in mdresourceprovider/src/main/java/org/apache/sling/mdresource/impl/MarkdownResource.java [112:160]
private ValueMap getValueMap0() {
if ( !backingFile.exists() || !backingFile.canRead() ) {
return null;
}
Parser parser = Parser.builder()
.extensions(singleton(YamlFrontMatterExtension.create()))
.build();
HtmlRenderer htmlRenderer = HtmlRenderer.builder().build();
Map<String, Object> props = new HashMap<>();
props.put("sling:resourceType", "sling/markdown/file");
try {
try ( BufferedReader r = Files.newBufferedReader(backingFile.toPath())) {
Node document = parser.parseReader(r);
Node currentNode = document.getFirstChild();
// consume special nodes at the beginning of the file
// while at least one special node (as defined by the list of handlers) finds
// something to handle, parsing continues
//
// this restriction is mostly for simplicity, as it's easy to skip the first
// special nodes and pass off the rest to the HTML renderer
// in the future, we can consider allowing these special nodes anywhere
while ( currentNode != null ) {
boolean handled = false;
for ( SpecialHandler handler : handlers ) {
handled = handler.consume(currentNode, props);
if ( handled ) {
currentNode = currentNode.getNext();
break;
}
}
if ( !handled )
break;
}
if ( currentNode != null)
props.put("jcr:description", htmlRenderer.render(currentNode));
}
} catch (IOException e) {
// TODO - handle errors someplace else?
throw new RuntimeException(e);
}
return new ValueMapDecorator(props);
}