Skip to content

Commit

Permalink
Support example in MDITA
Browse files Browse the repository at this point in the history
Signed-off-by: Jarno Elovirta <[email protected]>
  • Loading branch information
jelovirt committed Dec 25, 2023
1 parent af5c144 commit 640e6cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicInteger;
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;
Expand Down Expand Up @@ -555,6 +557,8 @@ private static <E> E containsSome(final Collection<E> col, final Collection<E> 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);
Expand All @@ -575,8 +579,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) {
Expand Down
10 changes: 5 additions & 5 deletions src/test/resources/xdita/example.dita
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<title class="- topic/title ">Example</title>
<shortdesc class="- topic/shortdesc ">Shortdesc.</shortdesc>
<body class="- topic/body ">
<section class="- topic/section " id="example-section-example">
<example class="- topic/example " id="example-section-example">
<title class="- topic/title ">Example section {.example}</title>
<p class="- topic/p ">Example content.</p>
</section>
<section class="- topic/section " id="example-section-----example--">
</example>
<example class="- topic/example " id="example-section-----example--">
<title class="- topic/title ">Example section { .example }</title>
<p class="- topic/p ">Example content.</p>
</section>
</example>
</body>
</topic>
</topic>

0 comments on commit 640e6cd

Please sign in to comment.