use of com.vladsch.flexmark.util.html.Attributes 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;
}
}
use of com.vladsch.flexmark.util.html.Attributes 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.util.html.Attributes 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.util.html.Attributes 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.util.html.Attributes 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