diff --git a/src/main/java/com/elovirta/dita/markdown/renderer/TopicRenderer.java b/src/main/java/com/elovirta/dita/markdown/renderer/TopicRenderer.java index f0e8cbd..d482742 100644 --- a/src/main/java/com/elovirta/dita/markdown/renderer/TopicRenderer.java +++ b/src/main/java/com/elovirta/dita/markdown/renderer/TopicRenderer.java @@ -41,6 +41,8 @@ import java.util.*; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.xml.transform.TransformerConfigurationException; @@ -521,6 +523,8 @@ private static E containsSome(final Collection col, final Collection f return null; } + private static final Pattern EXAMPLE_PATTERN = Pattern.compile("\\{ *\\.example *}"); + private void render(final Heading node, final NodeRendererContext context, final SaxWriter html) { final StringBuilder buf = new StringBuilder(); node.getAstExtra(buf); @@ -541,8 +545,13 @@ private void render(final Heading node, final NodeRendererContext context, final final DitaClass cls; final boolean isSection; if ((mditaCoreProfile || mditaExtendedProfile) && node.getLevel() == 2) { - isSection = true; - cls = TOPIC_SECTION; + isSection = true; + final Matcher matcher = EXAMPLE_PATTERN.matcher(node.getText()); + if (matcher.find()) { + cls = TOPIC_EXAMPLE; + } else { + cls = TOPIC_SECTION; + } } else if (!mditaCoreProfile) { final String sectionClassName = containsSome(header.classes, sections.keySet()); if (sectionClassName != null) { diff --git a/src/test/resources/xdita/example.dita b/src/test/resources/xdita/example.dita index 60218a3..34593cc 100644 --- a/src/test/resources/xdita/example.dita +++ b/src/test/resources/xdita/example.dita @@ -4,13 +4,13 @@ Example Shortdesc. -
+ Example section {.example}

Example content.

-
-
+ + Example section { .example }

Example content.

-
+ - + \ No newline at end of file