use of com.vladsch.flexmark.html.renderer.ResolvedLink in project jspwiki by apache.
the class JSPWikiLinkRenderer method getNodeRenderingHandlers.
/**
* {@inheritDoc}
*
* @see com.vladsch.flexmark.html.renderer.NodeRenderer#getNodeRenderingHandlers()
*/
@Override
public Set<NodeRenderingHandler<?>> getNodeRenderingHandlers() {
HashSet<NodeRenderingHandler<?>> set = new HashSet<NodeRenderingHandler<?>>();
set.add(new NodeRenderingHandler<JSPWikiLink>(JSPWikiLink.class, new CustomNodeRenderer<JSPWikiLink>() {
/**
* {@inheritDoc}
*/
@Override
public void render(final JSPWikiLink node, final NodeRendererContext context, final HtmlWriter html) {
if (context.isDoNotRenderLinks()) {
context.renderChildren(node);
} else {
// standard Link Rendering
ResolvedLink resolvedLink = context.resolveLink(LinkType.LINK, node.getUrl().unescape(), null);
html.attr("href", resolvedLink.getUrl());
if (node.getTitle().isNotNull()) {
html.attr("title", node.getTitle().unescape());
}
html.srcPos(node.getChars()).withAttr(resolvedLink).tag("a");
context.renderChildren(node);
html.tag("/a");
}
}
}));
return set;
}
use of com.vladsch.flexmark.html.renderer.ResolvedLink in project flexmark-java by vsch.
the class CoreNodeDocxRenderer method render.
private void render(final LinkRef node, final DocxRendererContext docx) {
ResolvedLink resolvedLink = null;
if (!node.isDefined() && recheckUndefinedReferences) {
if (node.getReferenceNode(referenceRepository) != null) {
node.setDefined(true);
}
}
BasedSequence urlSrc = node.getReference();
Reference reference = null;
if (node.isDefined()) {
reference = node.getReferenceNode(referenceRepository);
urlSrc = reference.getUrl();
String url = urlSrc.unescape();
resolvedLink = docx.resolveLink(LinkType.LINK, 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 = node.getReference().unescape();
resolvedLink = docx.resolveLink(LinkType.LINK_REF, normalizeRef, null, null);
if (resolvedLink.getStatus() == UNKNOWN) {
resolvedLink = null;
}
}
if (resolvedLink == null) {
// empty ref, we treat it as text
assert !node.isDefined();
if (!node.hasChildren()) {
docx.text(node.getChars().unescape());
} else {
docx.text(node.getChars().prefixOf(node.getChildChars()).unescape());
docx.renderChildren(node);
docx.text(node.getChars().suffixOf(node.getChildChars()).unescape());
}
} else {
Attributes attributes = resolvedLink.getNonNullAttributes();
if (reference != null) {
attributes = docx.extendRenderingNodeAttributes(reference, AttributablePart.NODE, attributes);
}
attributes = docx.extendRenderingNodeAttributes(AttributablePart.NODE, attributes);
renderURL(urlSrc, docx, resolvedLink.getUrl(), attributes, new Runnable() {
@Override
public void run() {
docx.renderChildren(node);
}
});
}
}
use of com.vladsch.flexmark.html.renderer.ResolvedLink in project flexmark-java by vsch.
the class CoreNodeDocxRenderer method render.
private void render(final ImageRef node, final DocxRendererContext docx) {
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 = docx.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 = docx.resolveLink(LinkType.IMAGE_REF, normalizeRef, null, null);
if (resolvedLink.getStatus() == UNKNOWN) {
resolvedLink = null;
}
}
if (resolvedLink == null) {
// empty ref, we treat it as text
docx.text(node.getChars().unescape());
if (options.logImageProcessing) {
System.out.println("render image ref of " + referenceRepository.normalizeKey(node.getReference()) + " skipped because it was not defined");
}
} else {
String altText = new TextCollectingVisitor().collectAndGetText(node);
String url = resolvedLink.getUrl();
Attributes attributes = resolvedLink.getNonNullAttributes();
if (!altText.isEmpty()) {
attributes.replaceValue("alt", altText);
}
if (reference != null) {
attributes = docx.extendRenderingNodeAttributes(reference, AttributablePart.NODE, attributes);
}
attributes = docx.extendRenderingNodeAttributes(AttributablePart.NODE, attributes);
renderImage(docx, url, attributes);
}
}
use of com.vladsch.flexmark.html.renderer.ResolvedLink in project flexmark-java by vsch.
the class CoreNodeDocxRenderer method render.
private void render(final Link node, final DocxRendererContext docx) {
ResolvedLink resolvedLink = docx.resolveLink(LinkType.LINK, node.getUrl().unescape(), null, null);
// we have a title part, use that
Attributes attributes = resolvedLink.getNonNullAttributes();
if (node.getTitle().isNotNull()) {
attributes.replaceValue(Attribute.TITLE_ATTR, node.getTitle().unescape());
} else {
attributes.remove(Attribute.TITLE_ATTR);
}
attributes = docx.extendRenderingNodeAttributes(AttributablePart.NODE, attributes);
renderURL(node.getUrl(), docx, resolvedLink.getUrl(), attributes, new Runnable() {
@Override
public void run() {
docx.renderChildren(node);
}
});
}
use of com.vladsch.flexmark.html.renderer.ResolvedLink in project flexmark-java by vsch.
the class CoreNodeDocxRenderer method render.
private void render(final Image node, final DocxRendererContext docx) {
String altText = new TextCollectingVisitor().collectAndGetText(node);
ResolvedLink resolvedLink = docx.resolveLink(LinkType.IMAGE, node.getUrl().unescape(), null, null);
String url = resolvedLink.getUrl();
Attributes attributes = resolvedLink.getNonNullAttributes();
if (!node.getUrlContent().isEmpty()) {
// reverse URL encoding of =, &
String content = Escaping.percentEncodeUrl(node.getUrlContent()).replace("+", "%2B").replace("%3D", "=").replace("%26", "&");
url += content;
}
if (!altText.isEmpty()) {
attributes.replaceValue("alt", altText);
}
attributes = docx.extendRenderingNodeAttributes(AttributablePart.NODE, attributes);
// String alt = node.getText().unescape();
renderImage(docx, url, attributes);
}
Aggregations