From 458ef7a014567bef226a340de803b44b4ec51f62 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Tue, 29 Jun 2021 08:13:10 +0200 Subject: [PATCH] Improve DocBook titles management. --- .../argeo/docbook/ui/AbstractDbkViewer.java | 21 ++++++++++++++++--- .../src/org/argeo/docbook/ui/TextSection.java | 19 ++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java index 656dd01..f2fa799 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java @@ -109,18 +109,27 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke if (style != null) CmsUiUtils.style(textSection, style); + // Title + Node titleNode = null; + // We give priority to ./title vs ./info/title, like the DocBook XSL if (node.hasNode(DbkType.title.get())) { + titleNode = node.getNode(DbkType.title.get()); + } else if (node.hasNode(DbkType.info.get() + '/' + DbkType.title.get())) { + titleNode = node.getNode(DbkType.info.get() + '/' + DbkType.title.get()); + } + + if (titleNode != null) { boolean showTitle = getMainSection() == section ? showMainTitle : true; if (showTitle) { if (section.getHeader() == null) section.createHeader(); - Node titleNode = node.getNode(DbkType.title.get()); DocBookSectionTitle title = newSectionTitle(textSection, titleNode); title.setLayoutData(CmsUiUtils.fillWidth()); updateContent(title); } } + // content for (NodeIterator ni = node.getNodes(); ni.hasNext();) { Node child = ni.nextNode(); SectionPart sectionPart = null; @@ -130,13 +139,19 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke // Node imageDataNode = child.getNode(DbkType.imageobject.get()).getNode(DbkType.imagedata.get()); // sectionPart = newImg(textSection, imageDataNode); // } + } else if (isDbk(child, DbkType.info)) { + // TODO enrich UI based on info + } else if (isDbk(child, DbkType.title)) { + // already managed } else if (isDbk(child, para)) { sectionPart = newParagraph(textSection, child); - } else { + } else if (isDbk(child, DbkType.section)) { sectionPart = newSectionPart(textSection, child); // if (sectionPart == null) // throw new IllegalArgumentException("Unsupported node " + child); // TODO list node types in exception + } else { + throw new IllegalArgumentException("Unsupported node type for "+child); } if (sectionPart != null && sectionPart instanceof Control) ((Control) sectionPart).setLayoutData(CmsUiUtils.fillWidth()); @@ -266,7 +281,7 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke if (title == getEdited()) title.setText(textInterpreter.read(title.getNode())); else - title.setText(textInterpreter.raw(title.getNode())); + title.setText(textInterpreter.readSimpleHtml(title.getNode())); } } diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextSection.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextSection.java index cb2e309..ba49f1a 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextSection.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextSection.java @@ -20,6 +20,8 @@ public class TextSection extends Section { private boolean titleReadOnly = false; + private final int level; + public TextSection(Composite parent, int style, Node node) { this(parent, findSection(parent), style, node); } @@ -31,6 +33,11 @@ public class TextSection extends Section { private TextSection(Composite parent, Section parentSection, int style, Node node) { super(parent, parentSection, style, node); flat = SWT.FLAT == (style & SWT.FLAT); + if (parentSection instanceof TextSection) { + level = ((TextSection) parentSection).getLevel() + 1; + } else { + level = 0; + } // CmsUiUtils.style(this, TextStyles.TEXT_SECTION); } @@ -42,12 +49,18 @@ public class TextSection extends Section { return flat; } + /** The level of this section, similar to h1, h2, etc. in HTML. */ + public int getLevel() { + return level; + } + public String getTitleStyle() { if (titleStyle != null) return titleStyle; // TODO make base H styles configurable - Integer relativeDepth = getRelativeDepth(); - return relativeDepth == 0 ? TextStyles.TEXT_TITLE : TextStyles.TEXT_H + relativeDepth; +// Integer relativeDepth = getRelativeDepth(); +// System.out.println("Level: "+getLevel()); + return getLevel() == 0 ? TextStyles.TEXT_TITLE : "h" + getLevel(); } public void setDefaultTextStyle(String defaultTextStyle) { @@ -64,5 +77,5 @@ public class TextSection extends Section { public void setTitleReadOnly(boolean titleReadOnly) { this.titleReadOnly = titleReadOnly; - } + } } -- 2.30.2