Search in sources :

Example 1 with EnumRefTextCollectingVisitor

use of com.vladsch.flexmark.ext.enumerated.reference.internal.EnumRefTextCollectingVisitor in project flexmark-java by vsch.

the class CoreNodeDocxRenderer method render.

private void render(EnumeratedReferenceLink node, final DocxRendererContext docx) {
    final String text = node.getText().toString();
    if (text.isEmpty()) {
        // placeholder for ordinal
        docx.text(String.valueOf(ordinal));
    } else {
        final Node referenceFormat = enumeratedOrdinals.getFormatNode(text);
        int wasOrdinal = ordinal;
        ordinal = enumeratedOrdinals.getOrdinal(text);
        final String defaultText = String.format("%s %d", EnumeratedReferences.getType(text), ordinal);
        String title = referenceFormat != null ? new EnumRefTextCollectingVisitor(ordinal).collectAndGetText(referenceFormat) : defaultText;
        Attributes attributes = new Attributes();
        if (title != null) {
            attributes.replaceValue(Attribute.TITLE_ATTR, title);
        }
        attributes = docx.extendRenderingNodeAttributes(AttributablePart.NODE, attributes);
        renderURL(node.getText(), docx, "#" + text, attributes, new Runnable() {

            @Override
            public void run() {
                if (referenceFormat != null) {
                    docx.renderChildren(referenceFormat);
                } else {
                    // no format, just output ordinal
                    docx.text(defaultText);
                }
            }
        });
        ordinal = wasOrdinal;
    }
}
Also used : EnumRefTextCollectingVisitor(com.vladsch.flexmark.ext.enumerated.reference.internal.EnumRefTextCollectingVisitor) AttributesNode(com.vladsch.flexmark.ext.attributes.AttributesNode) Attributes(com.vladsch.flexmark.util.html.Attributes)

Aggregations

AttributesNode (com.vladsch.flexmark.ext.attributes.AttributesNode)1 EnumRefTextCollectingVisitor (com.vladsch.flexmark.ext.enumerated.reference.internal.EnumRefTextCollectingVisitor)1 Attributes (com.vladsch.flexmark.util.html.Attributes)1