Skip to content

A link title is rewritten to double quotes on save #261

Description

@Azganoth

Summary

A link title is rewritten to the double-quoted form on save, whichever of CommonMark's three forms the author used. The title text is preserved, so this is an authored-form rewrite rather than a loss, and it is one of the differences keeping corpus/commonmark/links-and-images.md from byte identity.

Steps to reproduce

  1. Open a document containing [Single quote](garden.md 'Garden').
  2. Save it.
  3. Read the file.

Expected behavior

[Single quote](garden.md 'Garden'). CommonMark accepts a title in double quotes, single quotes, or parentheses, and the corpus covers all three.

Actual behavior

Measured against 9626471d by driving the editor mount used by the plugin tests. Stable across a second save:

Document Saved
[Single quote](garden.md 'Garden') [Single quote](garden.md "Garden")
[Parentheses](garden.md (Garden)) [Parentheses](garden.md "Garden")

[Double quote](garden.md "Garden") is unchanged.

Related context

Done when

  • A title saves in the form it was authored in, for links, images, and definitions.
  • A title whose text would break the authored form is written in a form that holds it, rather than being escaped into the authored one.
  • Regression coverage asserts the saved form for each of the three title forms.

Notes, logs, screenshots

Diagnosis

mdast records only the title's text, not its delimiters, and mdast-util-to-markdown writes it with the single quote option, which is one setting for the whole document. Nothing in the pipeline carries the authored form as far as the serializer.

Implementation direction

#243 solved the same shape of problem for a bare URL by recovering the authored form from the source rather than by adding document state, and #245 concluded against storing an authored form where it can be derived. Neither applies cleanly here: a title's delimiters are not recoverable from the title text, so this one probably does need the authored delimiter carried on the node, which makes it a smaller version of the decision #245 answered for escapes. Worth confirming the direction in this issue before implementation.

The quote option is per document, so a per-node choice needs a link, image, and definition handler override in createMilkdownEditor.ts, alongside the text one #252 added.

Out of scope

  • The destination, which is a separate normalization filed on its own.
  • Reference definitions disappearing on save, filed on its own.

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Projects

Status
Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions