Skip to content

Commit 5890080

Browse files
travkin79Copilot
andcommitted
fix: Stop carriage returns leaking out of unresolved reference links
Reference links and reference images that cannot be resolved render their raw source as text. Every other renderer that emits raw source normalizes its line endings first, but these four call sites did not, so a reference label spanning a CRLF line ending leaked its carriage return into the rendered output. Normalize the line endings there as well, matching what the surrounding renderers already do. Output for sources using plain newlines is unchanged, since normalizing them is a no-op. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 62f6d15 commit 5890080

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎flexmark/src/main/java/com/vladsch/flexmark/html/renderer/CoreNodeRenderer.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,8 @@ void render(ImageRef node, NodeRendererContext context, HtmlWriter html) {
766766
}
767767

768768
if (resolvedLink == null) {
769-
// empty ref, we treat it as text
770-
html.text(node.getChars().unescape());
769+
// empty ref, we treat it as text, the reference label is raw source and may still hold a CR
770+
html.text(Escaping.normalizeEOL(node.getChars().unescape()));
771771
} else {
772772
if (!(context.isDoNotRenderLinks() || isSuppressed)) {
773773
String altText = new TextCollectingVisitor().collectAndGetText(node);
@@ -819,12 +819,13 @@ void render(LinkRef node, NodeRendererContext context, HtmlWriter html) {
819819
if (resolvedLink == null) {
820820
// empty ref, we treat it as text
821821
assert !node.isDefined();
822+
// the reference label is raw source and is never parsed into inlines, so it may still hold a CR
822823
if (!node.hasChildren()) {
823-
html.text(node.getChars().unescape());
824+
html.text(Escaping.normalizeEOL(node.getChars().unescape()));
824825
} else {
825-
html.text(node.getChars().prefixOf(node.getChildChars()).unescape());
826+
html.text(Escaping.normalizeEOL(node.getChars().prefixOf(node.getChildChars()).unescape()));
826827
renderChildrenSourceLineWrapped(node, node.getText(), context, html);
827-
html.text(node.getChars().suffixOf(node.getChildChars()).unescape());
828+
html.text(Escaping.normalizeEOL(node.getChars().suffixOf(node.getChildChars()).unescape()));
828829
}
829830
} else {
830831
if (context.isDoNotRenderLinks() || isSuppressed) {

0 commit comments

Comments
 (0)