Instatic icon indicating copy to clipboard operation
Instatic copied to clipboard

Markdown serializer: bold/italic/strike runs with leading or trailing whitespace produce invalid delimiters (`**word **`)

Open Amay66 opened this issue 1 month ago • 0 comments

Version: 0.0.21 (Docker image ghcr.io/corebunch/instatic)

What happens

When a bold (or italic / strikethrough) mark covers a run of text that starts or ends with a space, the body is saved with the delimiters directly around the whitespace:

a **word **b

CommonMark does not treat that as strong emphasis (a closing ** must not be preceded by whitespace, an opening ** must not be followed by it), so the asterisks are shown literally in the Live view, on the published page and when the body is opened again.

How it happens in practice

In the Content workspace (Write or Live), double-click a word and press Bold. On Windows a double-click selects the word plus its trailing space, so the marked run is word and the saved markdown is **word **.

Reproduction without the UI

proseMirrorDocToMarkdown from src/core/markdown/markdownDocument.ts, then marked.parse():

marked run markdown rendered
"word " bold a **word **b <p>a **word **b</p>
" word" bold a** word**b <p>a** word**b</p>
"word " italic a *word *b <p>a *word *b</p>
"word " strike a ~~word ~~b <p>a ~~word ~~b</p>
"word" bold (control) a **word** b <p>a <strong>word</strong> b</p>

Cause

runsToMarkdown (same file) emits MARK_OPEN[mark] before and after a run's text unchanged, so any whitespace inside the run ends up next to a delimiter.

Suggested fix

In runsToMarkdown, for runs carrying bold/italic/strike, move the leading and trailing whitespace of the run outside the delimiters (emit it as unmarked text), and skip delimiters for whitespace-only runs. Add unit tests for the cases in the table. I only ran bold, italic and strike; links and <u> were not checked.

Workaround

Select the word without its trailing space (drag or Shift+arrow).

Amay66 avatar Oct 16 '26 08:10 Amay66