Reading view: emphasis ignores CommonMark's rules for * and _ (spaces inside, _ inside words, nesting)

Steps to reproduce

Paste this into a note and open Reading view:

a * foo bar*

a ** b ** c

foo_bar_

__foo, __bar__, baz__

Did you follow the troubleshooting guide?

Yes (reproduced in the sandbox vault, no community plugins).

Expected result

As the CommonMark spec (0.31.2) renders them:

Markdown CommonMark HTML Spec example
a * foo bar* a * foo bar* (a * followed by a space cannot open emphasis) 351
a ** b ** c a ** b ** c same rule
foo_bar_ foo_bar_ (a _ inside a word neither opens nor closes) 360
__foo, __bar__, baz__ <strong>foo, <strong>bar</strong>, baz</strong> 389

Actual result

Markdown Reading view HTML
a * foo bar* a <em> foo bar</em>
a ** b ** c a <strong> b </strong> c
foo_bar_ foo<em>bar</em>
__foo, __bar__, baz__ <strong>foo, </strong>bar<strong>, baz</strong>

Reading view pairs * and _ runs first come first served, without CommonMark’s left- and right-flanking checks, its rule for _ inside words, or its nesting rules. Words in other scripts are affected the same way (пристаням_стремятся_ gives пристаням<em>стремятся</em>, example 362).

Environment

SYSTEM INFO:
	Obsidian version: 1.14.5
	Installer version: 1.14.4
	Operating system: Windows 11 Pro 10.0.26300
	Login status: not logged in
	Language: en
	Insider build toggle: off
	Live preview: on
	Base theme: adapt to system
	Community theme: none
	Snippets enabled: 0
	Restricted mode: on

RECOMMENDATIONS:
	none

Sandbox vault, no community plugins, default theme and settings.

Additional information

Measured on the CommonMark 0.31.2 spec examples in Reading view (default settings). Other examples with the same cause: 352-354, 358-359, 366, 368-369, 371, 373, 375, 379-380, 383-388, 391-392, 397-398, 400-402, 407-409, 413-418, 425-427, 432, 437, 439, 443-447, 449, 451, 455-459, 464-468, 470-472.

Related: Commonmark-compliance: Reader should NOT parse intra word underscore (CJK and Cyrillic) covers the _-inside-a-word part for CJK and Cyrillic text. This report adds the Latin cases, the spaces-inside-delimiters cases and nesting.

foo_bar_baz (an _ pair fully inside a word) is left alone, which is right, but __a__b still gives <strong>a</strong>b.

More shapes of the same thing, measured on 1.14.5 and on the current Catalyst build, with CommonMark’s result beside each:

Markdown Reading view CommonMark
***a** <strong>*a</strong> *<strong>a</strong>
**a*** <strong>a*</strong> <strong>a</strong>*
***a* <em>**a</em> **<em>a</em>
*a*** *a***, no emphasis <em>a</em>**
****a**** *<strong>*a**</strong> <strong><strong>a</strong></strong>
*****a***** <strong>*</strong>a<strong>*</strong> <em><strong><strong>a</strong></strong></em>
***a*** (and ___a___) <strong><em>a</em></strong> <em><strong>a</strong></em>
*a **b* c** <em>a **b</em> c** <em>a <em><em>b</em> c</em></em>
**a **b** c** <strong>a </strong>b<strong> c</strong> <strong>a <strong>b</strong> c</strong>
**a\** **a**, no emphasis *<em>a*</em>
\**text\** **text**, no emphasis *<em>text*</em>

Two of these change what a reader sees, not only the tree: in **a **b** c** the b is not bold, and in the first rows a literal * ends up inside the bold or italic span. The escaped rows drop the backslash in both, as CommonMark does; they differ in what pairs.

Every row, and the samples of the first post, come out exactly as remark-parse 8.0.3’s emphasis and strong tokenizers give them with pedantic off, so they share one cause.


Credit: found by @saberzero1 with the remark-obsidian parity harness; I re-checked it on 1.14.5 and the current Catalyst build.