Skip to content

Fix roundtripping attention-like underscores #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/unsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ export const unsafe = [
// Caret is not used in markdown for constructs.
// An underscore can start emphasis, strong, or a thematic break.
{atBreak: true, character: '_'},
{before: '[^A-Za-z]', character: '_', inConstruct: 'phrasing'},
{character: '_', after: '[^A-Za-z]', inConstruct: 'phrasing'},
{character: '_', inConstruct: 'phrasing'},
// A grave accent can start code (fenced or text), or it can break out of
// a grave accent code fence.
{atBreak: true, character: '`'},
Expand Down
76 changes: 76 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3585,5 +3585,81 @@ test('roundtrip', (t) => {
'should roundtrip encoded spaces and tabs where needed'
)

doc = `Separate paragraphs:

a * is this emphasis? *

a ** is this emphasis? **

a *** is this emphasis? ***

a *\\* is this emphasis? *\\*

a \\** is this emphasis? \\**

a **\\* is this emphasis? **\\*

a *\\** is this emphasis? *\\**

One paragraph:

a * is this emphasis? *
a ** is this emphasis? **
a *** is this emphasis? ***
a *\\* is this emphasis? *\\*
a \\** is this emphasis? \\**
a **\\* is this emphasis? **\\*
a *\\** is this emphasis? *\\**`
tree = from(doc)

t.deepEqual(
removePosition(tree, true),
removePosition(from(to(tree)), true),
'should roundtrip asterisks (tree)'
)

doc = `Separate paragraphs:

a _ is this emphasis? _

a __ is this emphasis? __

a ___ is this emphasis? ___

a _\\_ is this emphasis? _\\_

a \\__ is this emphasis? \\__

a __\\_ is this emphasis? __\\_

a _\\__ is this emphasis? _\\__

One paragraph:

a _ is this emphasis? _
a __ is this emphasis? __
a ___ is this emphasis? ___
a _\\_ is this emphasis? _\\_
a \\__ is this emphasis? \\__
a __\\_ is this emphasis? __\\_
a _\\__ is this emphasis? _\\__`
tree = from(doc)

t.deepEqual(
removePosition(tree, true),
removePosition(from(to(tree)), true),
'should roundtrip underscores (tree)'
)

doc = to(from(`(____`))

t.equal(doc, to(from(doc)), 'should roundtrip attention-like plain text')

doc = to(
from('Once activated, a service worker ______, then transitions to idle…')
)

t.equal(doc, to(from(doc)), 'should roundtrip faux “fill in the blank” spans')

t.end()
})