use of com.vladsch.flexmark.ast.util.TextCollectingVisitor in project flexmark-java by vsch.
the class CoreNodeRenderer method render.
private void render(Image node, NodeRendererContext context, HtmlWriter html) {
if (!context.isDoNotRenderLinks()) {
String altText = new TextCollectingVisitor().collectAndGetText(node);
ResolvedLink resolvedLink = context.resolveLink(LinkType.IMAGE, node.getUrl().unescape(), null, null);
String url = resolvedLink.getUrl();
if (!node.getUrlContent().isEmpty()) {
// reverse URL encoding of =, &
String content = Escaping.percentEncodeUrl(node.getUrlContent()).replace("+", "%2B").replace("%3D", "=").replace("%26", "&");
url += content;
}
html.attr("src", url);
html.attr("alt", altText);
// we have a title part, use that
if (node.getTitle().isNotNull()) {
resolvedLink.getNonNullAttributes().replaceValue(Attribute.TITLE_ATTR, node.getTitle().unescape());
} else {
resolvedLink.getNonNullAttributes().remove(Attribute.TITLE_ATTR);
}
html.attr(resolvedLink.getAttributes());
html.srcPos(node.getChars()).withAttr(resolvedLink).tagVoid("img");
}
}
use of com.vladsch.flexmark.ast.util.TextCollectingVisitor in project flexmark-java by vsch.
the class CoreNodeRenderer method render.
private void render(ImageRef node, NodeRendererContext context, HtmlWriter html) {
ResolvedLink resolvedLink = null;
if (!node.isDefined() && recheckUndefinedReferences) {
if (node.getReferenceNode(referenceRepository) != null) {
node.setDefined(true);
}
}
Reference reference = null;
if (node.isDefined()) {
reference = node.getReferenceNode(referenceRepository);
String url = reference.getUrl().unescape();
resolvedLink = context.resolveLink(LinkType.IMAGE, url, null, null);
if (reference.getTitle().isNotNull()) {
resolvedLink.getNonNullAttributes().replaceValue(Attribute.TITLE_ATTR, reference.getTitle().unescape());
} else {
resolvedLink.getNonNullAttributes().remove(Attribute.TITLE_ATTR);
}
} else {
// see if have reference resolver and this is resolved
String normalizeRef = referenceRepository.normalizeKey(node.getReference());
resolvedLink = context.resolveLink(LinkType.IMAGE_REF, normalizeRef, null, null);
if (resolvedLink.getStatus() == UNKNOWN) {
resolvedLink = null;
}
}
if (resolvedLink == null) {
// empty ref, we treat it as text
html.text(node.getChars().unescape());
} else {
if (!context.isDoNotRenderLinks()) {
String altText = new TextCollectingVisitor().collectAndGetText(node);
Attributes attributes = resolvedLink.getNonNullAttributes();
html.attr("src", resolvedLink.getUrl());
html.attr("alt", altText);
// need to take attributes for reference definition, then overlay them with ours
if (reference != null) {
attributes = context.extendRenderingNodeAttributes(reference, AttributablePart.NODE, attributes);
}
html.attr(attributes);
html.srcPos(node.getChars()).withAttr(resolvedLink).tagVoid("img");
}
}
}
use of com.vladsch.flexmark.ast.util.TextCollectingVisitor in project flexmark-java by vsch.
the class TocUtils method markdownHeaderTexts.
public static List<String> markdownHeaderTexts(List<Heading> headings, TocOptions tocOptions) {
ArrayList<String> headingTexts = new ArrayList<String>(headings.size());
for (Heading header : headings) {
String headerText;
// need to skip anchor links but render emphasis
if (tocOptions.isTextOnly) {
headerText = new TextCollectingVisitor().collectAndGetText(header);
} else {
headerText = header.getChars().toString();
}
String headerId = header.getAnchorRefId();
String headerLink;
if (headerId == null || headerText.isEmpty()) {
headerLink = headerText;
} else {
headerLink = "[" + headerText + "](#" + headerId + ")";
}
headingTexts.add(headerLink);
}
return headingTexts;
}
use of com.vladsch.flexmark.ast.util.TextCollectingVisitor in project flexmark-java by vsch.
the class WikiLinkLinkRefProcessor method updateNodeElements.
@Override
public void updateNodeElements(final Document document, final Node node) {
assert (node instanceof WikiNode);
final WikiNode wikiNode = (WikiNode) node;
if (node instanceof WikiLink && WikiLinkExtension.ALLOW_INLINES.getFrom(document)) {
// need to update link and pageRef with plain text versions
if (wikiNode.getText().isNull()) {
BasedSequence link = new TextCollectingVisitor().collectAndGetSequence(node);
wikiNode.setLink(link, WikiLinkExtension.ALLOW_ANCHORS.getFrom(document), WikiLinkExtension.ALLOW_ANCHOR_ESCAPE.getFrom(document));
}
}
}
use of com.vladsch.flexmark.ast.util.TextCollectingVisitor in project flexmark-java by vsch.
the class JiraConverterNodeRenderer method render.
private void render(ImageRef node, NodeRendererContext context, HtmlWriter html) {
if (!node.isDefined()) {
// empty ref, we treat it as text
assert !node.isDefined();
html.text(node.getChars().unescape());
} else {
if (!context.isDoNotRenderLinks()) {
Reference reference = node.getReferenceNode(referenceRepository);
assert reference != null;
String altText = new TextCollectingVisitor().collectAndGetText(node);
ResolvedLink resolvedLink = context.resolveLink(LinkType.IMAGE, reference.getUrl().unescape(), null);
html.raw("!").raw(resolvedLink.getUrl()).raw("!");
}
}
}
Aggregations