Java源码示例:com.vladsch.flexmark.html.renderer.AttributablePart

示例1
@Override
public void setAttributes(final Node node, final AttributablePart part, final Attributes attributes) {
    if (node instanceof FencedCodeBlock) {
        if (part.getName().equals("NODE")) {
            String language = ((FencedCodeBlock) node).getInfo().toString();
            if (!TextUtils.isEmpty(language) &&
                    !language.equals("nohighlight")) {
                addJavascript(HIGHLIGHTJS);
                addJavascript(HIGHLIGHT_INIT);

                attributes.addValue("language", language);
                //attributes.addValue("onclick", String.format("javascript:android.onCodeTap('%s', this.textContent);",
                //        language));
            }
        }
    } else if (node instanceof MathJax) {
        addJavascript(MATHJAX);
        addJavascript(MATHJAX_CONFIG);
    } else if (node instanceof Abbreviation) {
        addJavascript(TOOLTIPSTER_JS);
        addStyleSheet(TOOLTIPSTER_CSS);
        addJavascript(TOOLTIPSTER_INIT);
        attributes.addValue("class", "tooltip");
    } else if (node instanceof Heading) {
        //attributes.addValue("onclick", String.format("javascript:android.onHeadingTap(%d, '%s');",
        //        ((Heading) node).getLevel(), ((Heading) node).getText()));
    } else if (node instanceof Image) {
        //attributes.addValue("onclick", String.format("javascript: android.onImageTap(this.src, this.clientWidth, this.clientHeight);"));
    } else if (node instanceof Mark) {
        //attributes.addValue("onclick", String.format("javascript: android.onMarkTap(this.textContent)"));
    } else if (node instanceof Keystroke) {
        //attributes.addValue("onclick", String.format("javascript: android.onKeystrokeTap(this.textContent)"));
    } else if (node instanceof Link ||
            node instanceof AutoLink) {
        //attributes.addValue("onclick", String.format("javascript: android.onLinkTap(this.href, this.textContent)"));
    }
}
 
示例2
@Override
public void setAttributes(Node node, AttributablePart part, Attributes attributes) {
    if (attributeMap != null) {
        Attributes attributes1 = attributeMap.get(node.getClass().getSimpleName());
        if (attributes1 != null) {
            attributes.replaceValues(attributes1);
        }
    }
}
 
示例3
@Override
public void setAttributes(final Node node, final AttributablePart part, final Attributes attributes) {}
 
示例4
@Override
public void extend(Builder rendererBuilder, String rendererType) {
	rendererBuilder.attributeProviderFactory(new IndependentAttributeProviderFactory() {
		
		@Override
		public AttributeProvider create(NodeRendererContext context) {
			return new AttributeProvider() {

				@Override
				public void setAttributes(Node node, AttributablePart part, Attributes attributes) {
					if (node instanceof Block) {
						int startOffset = node.getStartOffset();
						int endOffset = node.getEndOffset();
						Node document = node.getDocument();
						if (document != null) {
							int leadingWhitespaces = 0;
							for (int i=startOffset; i<endOffset; i++) {
								if (Character.isWhitespace(document.getChars().charAt(i))) {
									leadingWhitespaces++;
								} else {
									break;
								}
							}
							int trailingWhitespaces = 0;
							for (int i=endOffset-1; i>=startOffset; i--) {
								if (Character.isWhitespace(document.getChars().charAt(i))) {
									trailingWhitespaces++;
								} else {
									break;
								}
							}
							attributes.addValue("data-" + DATA_START_ATTRIBUTE, String.valueOf(startOffset+leadingWhitespaces));
							attributes.addValue("data-" + DATA_END_ATTRIBUTE, String.valueOf(endOffset-trailingWhitespaces));
						}
					}
				}
				
			};
		}
	});
}
 
示例5
@Override
public void setAttributes(Node node, AttributablePart part, Attributes attributes) {
	attributes.addValue("data-pos", node.getStartOffset() + ":" + node.getEndOffset());
}