Search in sources :

Example 1 with TagRange

use of com.vladsch.flexmark.util.sequence.TagRange in project flexmark-java by vsch.

the class HtmlWriter method tag.

@Override
public HtmlWriter tag(CharSequence tagName, boolean voidElement) {
    if (useAttributes != null) {
        final Attributes attributes = context.extendRenderingNodeAttributes(useAttributes, getAttributes());
        String sourcePositionAttribute = context.getHtmlOptions().sourcePositionAttribute;
        String attributeValue = attributes.getValue(sourcePositionAttribute);
        if (!attributeValue.isEmpty()) {
            // add to tag ranges
            int pos = attributeValue.indexOf('-');
            int startOffset = -1;
            int endOffset = -1;
            if (pos != -1) {
                try {
                    startOffset = Integer.valueOf(attributeValue.substring(0, pos));
                } catch (Throwable ignored) {
                }
                try {
                    endOffset = Integer.valueOf(attributeValue.substring(pos + 1));
                } catch (Throwable ignored) {
                }
            }
            if (startOffset >= 0 && startOffset < endOffset) {
                ArrayList<TagRange> tagRanges = context.getDocument().get(HtmlRenderer.TAG_RANGES);
                tagRanges.add(new TagRange(tagName, startOffset, endOffset));
            }
        }
        setAttributes(attributes);
        useAttributes = null;
    }
    super.tag(tagName, voidElement);
    return this;
}
Also used : TagRange(com.vladsch.flexmark.util.sequence.TagRange) Attributes(com.vladsch.flexmark.util.html.Attributes)

Aggregations

Attributes (com.vladsch.flexmark.util.html.Attributes)1 TagRange (com.vladsch.flexmark.util.sequence.TagRange)1