diff --git a/nb-api/src/main/java/io/nosqlbench/api/markdown/aggregator/MutableMarkdown.java b/nb-api/src/main/java/io/nosqlbench/api/markdown/aggregator/MutableMarkdown.java index b3a6e3dab..f8c4feed9 100644 --- a/nb-api/src/main/java/io/nosqlbench/api/markdown/aggregator/MutableMarkdown.java +++ b/nb-api/src/main/java/io/nosqlbench/api/markdown/aggregator/MutableMarkdown.java @@ -51,6 +51,11 @@ public class MutableMarkdown { throw new RuntimeException(e); } } + public MutableMarkdown(String rawMarkdown) { + this.path = null; + this.rawMarkdown = rawMarkdown; + parseStructure(rawMarkdown); + } private void parseStructure(String rawMarkdown) { AbstractYamlFrontMatterVisitor v = new AbstractYamlFrontMatterVisitor(); @@ -69,13 +74,19 @@ public class MutableMarkdown { } else if (node instanceof WhiteSpace) { } else if (node instanceof YamlFrontMatterBlock) { } else { - throw new RuntimeException("The markdown file at '" + this.path.toString() + "' must have an initial heading as a title, before any other element, but found:" + node.getClass().getSimpleName()); + if(this.path != null) + throw new RuntimeException("The markdown file at '" + this.path.toString() + "' must have an initial heading as a title, before any other element, but found:" + node.getClass().getSimpleName()); + else + throw new RuntimeException("The markdown string provided must have an initial heading as a title, before any other element, but found: "+ node.getClass().getSimpleName()); } node=node.getNext(); } } if (frontMatter.getTitle()==null || frontMatter.getTitle().isEmpty()) { - throw new RuntimeException("The markdown file at '" + this.path.toString() + "' has no heading to use as a title."); + if(this.path != null) + throw new RuntimeException("The markdown file at '" + this.path.toString() + "' has no heading to use as a title."); + else + throw new RuntimeException("The markdown string provided has no heading to use as a title."); } } @@ -90,7 +101,10 @@ public class MutableMarkdown { if (end>=0) { return rawMarkdown.substring(end+4); } else { - throw new RuntimeException("Unable to find matching boundaries in " + path.toString() + ": " + boundary); + if(path != null) + throw new RuntimeException("Unable to find matching boundaries in " + path.toString() + ": " + boundary); + else + throw new RuntimeException("Unable to find matching boundaries in provided markdown: " + boundary); } } } diff --git a/nbr/pom.xml b/nbr/pom.xml index 9dca9b6cf..f417ab914 100644 --- a/nbr/pom.xml +++ b/nbr/pom.xml @@ -72,6 +72,12 @@ adapter-diag 4.17.31-SNAPSHOT + + org.commonmark + commonmark + 0.20.0 + + diff --git a/nbr/src/main/java/io/nosqlbench/api/docsapi/docexporter/BundledMarkdownZipExporter.java b/nbr/src/main/java/io/nosqlbench/api/docsapi/docexporter/BundledMarkdownZipExporter.java index 75e77ef64..af6d5040b 100644 --- a/nbr/src/main/java/io/nosqlbench/api/docsapi/docexporter/BundledMarkdownZipExporter.java +++ b/nbr/src/main/java/io/nosqlbench/api/docsapi/docexporter/BundledMarkdownZipExporter.java @@ -39,6 +39,8 @@ import java.util.concurrent.Future; import java.util.function.Function; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import org.commonmark.parser.Parser; +import org.commonmark.node.Node; public class BundledMarkdownZipExporter { @@ -74,10 +76,14 @@ public class BundledMarkdownZipExporter { { String filename = entry.getKey(); StringBuilder fileStringBuilder = entry.getValue(); - ZipEntry zipEntry = new ZipEntry(bindingsPrefix +filename); + MutableMarkdown parsed = new MutableMarkdown(fileStringBuilder.toString()); + for (BundledMarkdownProcessor filter : this.filters) { + parsed = filter.apply(parsed); + } + ZipEntry zipEntry = new ZipEntry(bindingsPrefix + filename); zipEntry.setTime(new Date().getTime()); zipstream.putNextEntry(zipEntry); - zipstream.write(fileStringBuilder.toString().getBytes()); + zipstream.write(parsed.getComposedMarkdown().getBytes(StandardCharsets.UTF_8)); zipstream.closeEntry(); } zipstream.finish();