Skip to content

preserve Markdown reference links#8717

Open
mejo- wants to merge 1 commit into
mainfrom
feat/reference_links
Open

preserve Markdown reference links#8717
mejo- wants to merge 1 commit into
mainfrom
feat/reference_links

Conversation

@mejo-

@mejo- mejo- commented Jun 8, 2026

Copy link
Copy Markdown
Member

Fixes: #5820

Adds new arguments to the ProseMirror link mark to persist information that the link was in reference syntax in Markdown.

Augments the prosemirror-markdown Markdown serializer to carry references that get rendered in the serialized Markdown after the document content.

🏁 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits
  • Tests (unit, integration and/or end-to-end) passing and the changes are covered with tests

🤖 AI (if applicable)

  • The content of this PR was partly generated using AI tools
  • The AI-generated content was reviewed, comprehended and tested by a human

@mejo- mejo- self-assigned this Jun 8, 2026
@mejo- mejo- added bug Something isn't working 3. to review format: markdown labels Jun 8, 2026
@github-project-automation github-project-automation Bot moved this to 🧭 Planning evaluation (don't pick) in 📝 Productivity team Jun 8, 2026
@mejo- mejo- moved this from 🧭 Planning evaluation (don't pick) to 👀 In review in 📝 Productivity team Jun 8, 2026
Fixes: #5820

Adds new arguments to the ProseMirror link mark to persist information
that the link was in reference syntax in Markdown.

Augments the prosemirror-markdown Markdown serializer to carry
references that get rendered in the serialized Markdown after the
document content.

Signed-off-by: Jonas <jonas@freesources.org>
@mejo- mejo- force-pushed the feat/reference_links branch from 6cb1728 to 101090a Compare June 8, 2026 10:20
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.05263% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/markdownit/referenceLinks.ts 94.59% 2 Missing ⚠️
src/marks/Link.ts 96.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@max-nextcloud max-nextcloud left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments. Other than that looks good.

expect(markdownThroughEditor('[bar\\\\]: /uri\n\n[bar\\\\]')).toBe(
'[bar\\\\](/uri)',
)
const test2703 = '[bar\\\\]\n\n[bar\\\\]: /uri\n'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has a different order than the original issue. Does it also pass with the original order:

[bar\\]: /uri

[bar\\]
Suggested change
const test2703 = '[bar\\\\]\n\n[bar\\\\]: /uri\n'
const test2703 = '[bar\\\\]: /uri\n\n[bar\\\\]\n'

},
)
return (
body.replace(/\s*$/, '') + '\n\n' + referenceLines.join('\n') + '\n'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect the replace is meant to remove dangling newlines so we always have one empty line.

It also removes other dangling whitespace:

"hello  \nworld  \n\n".replace(/\s*$/, '')
"hello  
world"

Not sure if that is an issue. Two spaces at the end of a line is valid markdown for a hard break. However I think we serialize that to a <br> tag anyways.
Does the meaning of quotes or lists change if they have no content?
For example * -> * - is the latter still a list?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

Reference-style Markdown links are auto-replaced by inline links and thus text legibility is reduced

2 participants