Skip to content
Permalink
Browse files

Update flexmark-java to 0.50.18

Signed-off-by: Jarno Elovirta <jarno@elovirta.com>
  • Loading branch information...
jelovirt committed Jul 12, 2019
1 parent dd67d36 commit 82a28e5ee6eb777dbd144da18c24694e89273ce7
Showing with 316 additions and 189 deletions.
  1. +1 −1 README.md
  2. +2 −2 build.gradle
  3. +1 −1 src/main/java/com/elovirta/dita/markdown/AttributeProvider.java
  4. +4 −4 src/main/java/com/elovirta/dita/markdown/AttributeProviderFactory.java
  5. +4 −4 src/main/java/com/elovirta/dita/markdown/Builder.java
  6. +2 −2 src/main/java/com/elovirta/dita/markdown/CustomNodeRenderer.java
  7. +5 −5 src/main/java/com/elovirta/dita/markdown/DelegatingNodeRendererFactoryWrapper.java
  8. +91 −35 src/main/java/com/elovirta/dita/markdown/DitaRenderer.java
  9. +1 −1 src/main/java/com/elovirta/dita/markdown/DitaRendererOptions.java
  10. +1 −1 src/main/java/com/elovirta/dita/markdown/LinkResolver.java
  11. +5 −4 src/main/java/com/elovirta/dita/markdown/LinkResolverFactory.java
  12. +29 −29 src/main/java/com/elovirta/dita/markdown/MDitaReader.java
  13. +27 −28 src/main/java/com/elovirta/dita/markdown/MarkdownReader.java
  14. +1 −1 src/main/java/com/elovirta/dita/markdown/NodeRendererSubContext.java
  15. +22 −15 src/main/java/com/elovirta/dita/markdown/renderer/CoreNodeRenderer.java
  16. +2 −2 src/main/java/com/elovirta/dita/markdown/renderer/DitaIdGenerator.java
  17. +2 −2 src/main/java/com/elovirta/dita/markdown/renderer/HeaderIdGenerator.java
  18. +73 −0 src/main/java/com/elovirta/dita/markdown/renderer/LinkResolverContext.java
  19. +4 −4 src/main/java/com/elovirta/dita/markdown/renderer/NodeRendererContext.java
  20. +6 −3 src/main/java/com/elovirta/dita/markdown/renderer/NodeRendererFactory.java
  21. +2 −2 src/main/java/com/elovirta/dita/markdown/renderer/NodeRenderingHandler.java
  22. +1 −1 src/main/java/com/elovirta/dita/markdown/renderer/PhasedNodeRenderer.java
  23. +26 −26 src/main/plugin.xml
  24. +2 −8 src/test/resources/dita/jekyll.dita
  25. +2 −8 src/test/resources/lwdita/jekyll.dita
@@ -63,7 +63,7 @@ Install
On DITA-OT version 3.0 and older:

~~~~ {.sh}
$ dita --install https://github.com/jelovirt/org.lwdita/releases/download/2.2.1/org.lwdita-2.2.1.zip
$ dita --install https://github.com/jelovirt/org.lwdita/releases/download/2.3.0/org.lwdita-2.3.0.zip
~~~~

The `dita` command line tool requires no additional configuration;
@@ -5,7 +5,7 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8

group = 'com.elovirta.dita'
version = "2.2.2"
version = "2.3.0"

repositories {
mavenCentral()
@@ -14,7 +14,7 @@ repositories {

dependencies {
compile group: "org.dita-ot", name: "dost", version: "[2.1,)"
compile group: "com.vladsch.flexmark", name: "flexmark-all", version: "0.32.24"
compile group: "com.vladsch.flexmark", name: "flexmark-all", version: "0.50.18"
compile group: 'nu.validator.htmlparser', name: 'htmlparser', version: '1.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
@@ -1,7 +1,7 @@
package com.elovirta.dita.markdown;

import com.elovirta.dita.markdown.renderer.AttributablePart;
import com.vladsch.flexmark.ast.Node;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.html.Attributes;

/**
@@ -1,12 +1,12 @@
package com.elovirta.dita.markdown;

import com.elovirta.dita.markdown.renderer.NodeRendererContext;
import com.vladsch.flexmark.util.ComputableFactory;
import com.elovirta.dita.markdown.renderer.LinkResolverContext;
import com.vladsch.flexmark.util.dependency.Dependent;

import java.util.Set;
import java.util.function.Function;

public interface AttributeProviderFactory extends ComputableFactory<AttributeProvider, NodeRendererContext>, Dependent<AttributeProviderFactory> {
public interface AttributeProviderFactory extends Function<LinkResolverContext, AttributeProvider>, Dependent<AttributeProviderFactory> {
@Override
Set<Class<? extends AttributeProviderFactory>> getAfterDependents();

@@ -17,5 +17,5 @@
boolean affectsGlobalScope();

@Override
AttributeProvider create(NodeRendererContext context);
AttributeProvider apply(LinkResolverContext context);
}
@@ -1,12 +1,12 @@
package com.elovirta.dita.markdown;

import com.elovirta.dita.markdown.renderer.NodeRendererFactory;
import com.vladsch.flexmark.Extension;
import com.elovirta.dita.markdown.renderer.HeaderIdGeneratorFactory;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.options.DataHolder;
import com.vladsch.flexmark.util.options.DataKey;
import com.vladsch.flexmark.util.options.MutableDataSet;
import com.vladsch.flexmark.util.builder.Extension;
import com.vladsch.flexmark.util.data.DataHolder;
import com.vladsch.flexmark.util.data.DataKey;
import com.vladsch.flexmark.util.data.MutableDataSet;

import java.util.ArrayList;
import java.util.HashSet;
@@ -1,8 +1,8 @@
package com.elovirta.dita.markdown;

import com.elovirta.dita.markdown.renderer.NodeRendererContext;
import com.vladsch.flexmark.ast.Node;
import com.vladsch.flexmark.ast.NodeAdaptingVisitor;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.ast.NodeAdaptingVisitor;

public interface CustomNodeRenderer<N extends Node> extends NodeAdaptingVisitor<N> {
void render(N node, NodeRendererContext context, DitaWriter html);
@@ -3,18 +3,18 @@
import com.elovirta.dita.markdown.renderer.DelegatingNodeRendererFactory;
import com.elovirta.dita.markdown.renderer.NodeRenderer;
import com.elovirta.dita.markdown.renderer.NodeRendererFactory;
import com.vladsch.flexmark.util.ComputableFactory;
import com.vladsch.flexmark.util.data.DataHolder;
import com.vladsch.flexmark.util.dependency.Dependent;
import com.vladsch.flexmark.util.options.DataHolder;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

/**
* Factory for instantiating new node renderers with dependencies
*/
class DelegatingNodeRendererFactoryWrapper implements ComputableFactory<NodeRenderer, DataHolder>, Dependent<DelegatingNodeRendererFactoryWrapper>, DelegatingNodeRendererFactory {
class DelegatingNodeRendererFactoryWrapper implements Function<DataHolder, NodeRenderer>, Dependent<DelegatingNodeRendererFactoryWrapper>, DelegatingNodeRendererFactory {
private final NodeRendererFactory nodeRendererFactory;
private List<DelegatingNodeRendererFactoryWrapper> nodeRenderers;
private Set<Class> myDelegates = null;
@@ -25,8 +25,8 @@ public DelegatingNodeRendererFactoryWrapper(final List<DelegatingNodeRendererFac
}

@Override
public NodeRenderer create(final DataHolder options) {
return nodeRendererFactory.create(options);
public NodeRenderer apply(DataHolder options) {
return nodeRendererFactory.apply(options);
}

public NodeRendererFactory getFactory() {
@@ -4,26 +4,27 @@
package com.elovirta.dita.markdown;

import com.elovirta.dita.markdown.renderer.*;
import com.vladsch.flexmark.Extension;
import com.vladsch.flexmark.IRender;
import com.vladsch.flexmark.ast.Document;
import com.vladsch.flexmark.ast.Node;
import com.vladsch.flexmark.util.collection.DynamicDefaultKey;
import com.vladsch.flexmark.html.Disposable;
import com.vladsch.flexmark.util.ast.Document;
import com.vladsch.flexmark.util.ast.IRender;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.builder.Extension;
import com.vladsch.flexmark.util.data.*;
import com.vladsch.flexmark.util.dependency.DependencyHandler;
import com.vladsch.flexmark.util.dependency.FlatDependencyHandler;
import com.vladsch.flexmark.util.dependency.ResolvedDependencies;
import com.vladsch.flexmark.util.html.Attributes;
import com.vladsch.flexmark.util.html.Escaping;
import com.vladsch.flexmark.util.options.*;
import com.vladsch.flexmark.util.sequence.TagRange;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

import java.util.*;

//import static javax.xml.XMLConstants.NULL_NS_URI;
import static org.dita.dost.util.Constants.ATTRIBUTE_PREFIX_DITAARCHVERSION;
import static org.dita.dost.util.Constants.DITA_NAMESPACE;

//import static javax.xml.XMLConstants.NULL_NS_URI;
//import static org.dita.dost.util.Constants.ELEMENT_NAME_DITA;
//import static org.dita.dost.util.XMLSerializer.EMPTY_ATTS;

@@ -44,18 +45,18 @@
public static final DataKey<Boolean> PERCENT_ENCODE_URLS = new DataKey<Boolean>("ESCAPE_HTML", false);
public static final DataKey<Integer> INDENT_SIZE = new DataKey<Integer>("INDENT", 0);
public static final DataKey<Boolean> ESCAPE_HTML = new DataKey<Boolean>("ESCAPE_HTML", false);
public static final DataKey<Boolean> ESCAPE_HTML_BLOCKS = new DynamicDefaultKey<Boolean>("ESCAPE_HTML_BLOCKS", holder -> ESCAPE_HTML.getFrom(holder));
public static final DataKey<Boolean> ESCAPE_HTML_COMMENT_BLOCKS = new DynamicDefaultKey<Boolean>("ESCAPE_HTML_COMMENT_BLOCKS", holder -> ESCAPE_HTML_BLOCKS.getFrom(holder));
public static final DataKey<Boolean> ESCAPE_INLINE_HTML = new DynamicDefaultKey<Boolean>("ESCAPE_HTML_BLOCKS", holder -> ESCAPE_HTML.getFrom(holder));
public static final DataKey<Boolean> ESCAPE_INLINE_HTML_COMMENTS = new DynamicDefaultKey<Boolean>("ESCAPE_INLINE_HTML_COMMENTS", holder -> ESCAPE_INLINE_HTML.getFrom(holder));
public static final DataKey<Boolean> ESCAPE_HTML_BLOCKS = new DataKey<Boolean>("ESCAPE_HTML_BLOCKS", holder -> ESCAPE_HTML.getFrom(holder));
public static final DataKey<Boolean> ESCAPE_HTML_COMMENT_BLOCKS = new DataKey<Boolean>("ESCAPE_HTML_COMMENT_BLOCKS", holder -> ESCAPE_HTML_BLOCKS.getFrom(holder));
public static final DataKey<Boolean> ESCAPE_INLINE_HTML = new DataKey<Boolean>("ESCAPE_HTML_BLOCKS", holder -> ESCAPE_HTML.getFrom(holder));
public static final DataKey<Boolean> ESCAPE_INLINE_HTML_COMMENTS = new DataKey<Boolean>("ESCAPE_INLINE_HTML_COMMENTS", holder -> ESCAPE_INLINE_HTML.getFrom(holder));
public static final DataKey<Boolean> SUPPRESS_HTML = new DataKey<Boolean>("SUPPRESS_HTML", false);
public static final DataKey<Boolean> SUPPRESS_HTML_BLOCKS = new DynamicDefaultKey<Boolean>("SUPPRESS_HTML_BLOCKS", holder -> SUPPRESS_HTML.getFrom(holder));
public static final DataKey<Boolean> SUPPRESS_HTML_COMMENT_BLOCKS = new DynamicDefaultKey<Boolean>("SUPPRESS_HTML_COMMENT_BLOCKS", holder -> SUPPRESS_HTML_BLOCKS.getFrom(holder));
public static final DataKey<Boolean> SUPPRESS_INLINE_HTML = new DynamicDefaultKey<Boolean>("SUPPRESS_INLINE_HTML", holder -> SUPPRESS_HTML.getFrom(holder));
public static final DataKey<Boolean> SUPPRESS_INLINE_HTML_COMMENTS = new DynamicDefaultKey<Boolean>("SUPPRESS_INLINE_HTML_COMMENTS", holder -> SUPPRESS_INLINE_HTML.getFrom(holder));
public static final DataKey<Boolean> SUPPRESS_HTML_BLOCKS = new DataKey<Boolean>("SUPPRESS_HTML_BLOCKS", holder -> SUPPRESS_HTML.getFrom(holder));
public static final DataKey<Boolean> SUPPRESS_HTML_COMMENT_BLOCKS = new DataKey<Boolean>("SUPPRESS_HTML_COMMENT_BLOCKS", holder -> SUPPRESS_HTML_BLOCKS.getFrom(holder));
public static final DataKey<Boolean> SUPPRESS_INLINE_HTML = new DataKey<Boolean>("SUPPRESS_INLINE_HTML", holder -> SUPPRESS_HTML.getFrom(holder));
public static final DataKey<Boolean> SUPPRESS_INLINE_HTML_COMMENTS = new DataKey<Boolean>("SUPPRESS_INLINE_HTML_COMMENTS", holder -> SUPPRESS_INLINE_HTML.getFrom(holder));
public static final DataKey<Boolean> SOURCE_WRAP_HTML = new DataKey<Boolean>("SOURCE_WRAP_HTML", false);
public static final DataKey<Boolean> SOURCE_WRAP_HTML_BLOCKS = new DynamicDefaultKey<Boolean>("SOURCE_WRAP_HTML_BLOCKS", holder -> SOURCE_WRAP_HTML.getFrom(holder));
//public static final DataKey<Boolean> SOURCE_WRAP_INLINE_HTML = new DynamicDefaultKey<>("SOURCE_WRAP_INLINE_HTML", SOURCE_WRAP_HTML::getFrom);
public static final DataKey<Boolean> SOURCE_WRAP_HTML_BLOCKS = new DataKey<Boolean>("SOURCE_WRAP_HTML_BLOCKS", holder -> SOURCE_WRAP_HTML.getFrom(holder));
//public static final DataKey<Boolean> SOURCE_WRAP_INLINE_HTML = new DataKey<>("SOURCE_WRAP_INLINE_HTML", SOURCE_WRAP_HTML::getFrom);
public static final DataKey<Boolean> HEADER_ID_GENERATOR_RESOLVE_DUPES = new DataKey<Boolean>("HEADER_ID_GENERATOR_RESOLVE_DUPES", true);
public static final DataKey<String> HEADER_ID_GENERATOR_TO_DASH_CHARS = new DataKey<String>("HEADER_ID_GENERATOR_TO_DASH_CHARS", " -_");
public static final DataKey<Boolean> HEADER_ID_GENERATOR_NO_DUPED_DASHES = new DataKey<Boolean>("HEADER_ID_GENERATOR_NO_DUPED_DASHES", false);
@@ -108,7 +109,7 @@

for (int i = builder.nodeRendererFactories.size() - 1; i >= 0; i--) {
final NodeRendererFactory nodeRendererFactory = builder.nodeRendererFactories.get(i);
final Set<Class<? extends DelegatingNodeRendererFactoryWrapper>>[] myDelegates = new Set[] { null };
final Set<Class<? extends DelegatingNodeRendererFactoryWrapper>>[] myDelegates = new Set[]{null};

nodeRenderers.add(new DelegatingNodeRendererFactoryWrapper(nodeRenderers, nodeRendererFactory));
}
@@ -124,6 +125,11 @@
this.linkResolverFactories = FlatDependencyHandler.computeDependencies(builder.linkResolverFactories);
}

@Override
public DataHolder getOptions() {
return new DataSet(builder);
}

@Override
public void render(Node node, Appendable output) {
throw new UnsupportedOperationException();
@@ -224,7 +230,7 @@ protected Class getDependentClass(DelegatingNodeRendererFactoryWrapper dependent
}


private class MainNodeRenderer extends NodeRendererSubContext implements NodeRendererContext {
private class MainNodeRenderer extends NodeRendererSubContext implements NodeRendererContext, Disposable {
private final Document document;
private final Map<Class<?>, NodeRenderingHandlerWrapper> renderers;

@@ -237,6 +243,30 @@ protected Class getDependentClass(DelegatingNodeRendererFactoryWrapper dependent
private final HashMap<LinkType, HashMap<String, ResolvedLink>> resolvedLinkMap = new HashMap<LinkType, HashMap<String, ResolvedLink>>();
private final AttributeProvider[] attributeProviders;

@Override
public void dispose() {
// document = null;
// renderers = null;
// phasedRenderers = null;

for (LinkResolver linkResolver : myLinkResolvers) {
if (linkResolver instanceof Disposable) ((Disposable) linkResolver).dispose();
}
// myLinkResolvers = null;

// renderingPhases = null;
// options = null;

if (ditaIdGenerator instanceof Disposable) ((Disposable) ditaIdGenerator).dispose();
// ditaIdGenerator = null;
// resolvedLinkMap = null;

for (AttributeProvider attributeProvider : attributeProviders) {
if (attributeProvider instanceof Disposable) ((Disposable) attributeProvider).dispose();
}
// attributeProviders = null;
}

MainNodeRenderer(DataHolder options, DitaWriter ditaWriter, Document document) {
super(ditaWriter);
this.options = new ScopedDataSet(options, document);
@@ -253,7 +283,7 @@ protected Class getDependentClass(DelegatingNodeRendererFactoryWrapper dependent

for (int i = nodeRendererFactories.size() - 1; i >= 0; i--) {
NodeRendererFactory nodeRendererFactory = nodeRendererFactories.get(i);
NodeRenderer nodeRenderer = nodeRendererFactory.create(this.getOptions());
NodeRenderer nodeRenderer = nodeRendererFactory.apply(this.getOptions());
for (NodeRenderingHandler nodeType : nodeRenderer.getNodeRenderingHandlers()) {
// Overwrite existing renderer
NodeRenderingHandlerWrapper handlerWrapper = new NodeRenderingHandlerWrapper(nodeType, renderers.get(nodeType.getNodeType()));
@@ -267,12 +297,12 @@ protected Class getDependentClass(DelegatingNodeRendererFactoryWrapper dependent
}

for (int i = 0; i < linkResolverFactories.size(); i++) {
myLinkResolvers[i] = linkResolverFactories.get(i).create(this);
myLinkResolvers[i] = linkResolverFactories.get(i).apply(this);
}

this.attributeProviders = new AttributeProvider[attributeProviderFactories.size()];
for (int i = 0; i < attributeProviderFactories.size(); i++) {
attributeProviders[i] = attributeProviderFactories.get(i).create(this);
attributeProviders[i] = attributeProviderFactories.get(i).apply(this);
}
}

@@ -447,7 +477,9 @@ void renderNode(Node node, NodeRendererSubContext subContext) {
this.ditaIdGenerator.generateIds(document);

for (RenderingPhase phase : RenderingPhase.values()) {
if (phase != RenderingPhase.BODY && !renderingPhases.contains(phase)) { continue; }
if (phase != RenderingPhase.BODY && !renderingPhases.contains(phase)) {
continue;
}
this.phase = phase;
// here we render multiple phases

@@ -529,22 +561,34 @@ public SubNodeRenderer(DitaRenderer.MainNodeRenderer mainNodeRenderer, DitaWrite
}

@Override
public String getNodeId(Node node) {return myMainNodeRenderer.getNodeId(node);}
public String getNodeId(Node node) {
return myMainNodeRenderer.getNodeId(node);
}

@Override
public DataHolder getOptions() {return myMainNodeRenderer.getOptions();}
public DataHolder getOptions() {
return myMainNodeRenderer.getOptions();
}

@Override
public DitaRendererOptions getDitaOptions() {return myMainNodeRenderer.getDitaOptions();}
public DitaRendererOptions getDitaOptions() {
return myMainNodeRenderer.getDitaOptions();
}

@Override
public Document getDocument() {return myMainNodeRenderer.getDocument();}
public Document getDocument() {
return myMainNodeRenderer.getDocument();
}

@Override
public RenderingPhase getRenderingPhase() {return myMainNodeRenderer.getRenderingPhase();}
public RenderingPhase getRenderingPhase() {
return myMainNodeRenderer.getRenderingPhase();
}

@Override
public String encodeUrl(CharSequence url) {return myMainNodeRenderer.encodeUrl(url);}
public String encodeUrl(CharSequence url) {
return myMainNodeRenderer.encodeUrl(url);
}

@Override
public Attributes extendRenderingNodeAttributes(AttributablePart part, Attributes attributes) {
@@ -603,21 +647,33 @@ public void renderChildren(Node parent) {
}

@Override
public DitaWriter getDitaWriter() { return ditaWriter; }
public DitaWriter getDitaWriter() {
return ditaWriter;
}

protected int getDoNotRenderLinksNesting() {return super.getDoNotRenderLinksNesting();}
protected int getDoNotRenderLinksNesting() {
return super.getDoNotRenderLinksNesting();
}

@Override
public boolean isDoNotRenderLinks() {return super.isDoNotRenderLinks();}
public boolean isDoNotRenderLinks() {
return super.isDoNotRenderLinks();
}

@Override
public void doNotRenderLinks(boolean doNotRenderLinks) {super.doNotRenderLinks(doNotRenderLinks);}
public void doNotRenderLinks(boolean doNotRenderLinks) {
super.doNotRenderLinks(doNotRenderLinks);
}

@Override
public void doNotRenderLinks() {super.doNotRenderLinks();}
public void doNotRenderLinks() {
super.doNotRenderLinks();
}

@Override
public void doRenderLinks() {super.doRenderLinks();}
public void doRenderLinks() {
super.doRenderLinks();
}
}
}

@@ -1,7 +1,7 @@
package com.elovirta.dita.markdown;

import com.vladsch.flexmark.util.Utils;
import com.vladsch.flexmark.util.options.DataHolder;
import com.vladsch.flexmark.util.data.DataHolder;

public class DitaRendererOptions {
public final String softBreak;
@@ -2,7 +2,7 @@

import com.elovirta.dita.markdown.renderer.NodeRendererContext;
import com.elovirta.dita.markdown.renderer.ResolvedLink;
import com.vladsch.flexmark.ast.Node;
import com.vladsch.flexmark.util.ast.Node;

public interface LinkResolver {
ResolvedLink resolveLink(Node node, NodeRendererContext context, ResolvedLink link);

0 comments on commit 82a28e5

Please sign in to comment.
You can’t perform that action at this time.