moved from commonmark to inhouse MutableMarkdown for verification

This commit is contained in:
Mike Yaacoub 2022-12-19 13:24:40 -05:00
parent 7ba2a3de38
commit c149684d09
3 changed files with 31 additions and 5 deletions
nb-api/src/main/java/io/nosqlbench/api/markdown/aggregator
nbr
pom.xml
src/main/java/io/nosqlbench/api/docsapi/docexporter

View File

@ -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);
}
}
}

View File

@ -72,6 +72,12 @@
<artifactId>adapter-diag</artifactId>
<version>4.17.31-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.commonmark</groupId>
<artifactId>commonmark</artifactId>
<version>0.20.0</version>
</dependency>
</dependencies>
<build>

View File

@ -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();