Skip to content

Commit fce3057

Browse files
authored
Fix roundtripping attention-like underscores
Closes to GH-25. Closes to GH-43.
1 parent 604c96c commit fce3057

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

lib/unsafe.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ export const unsafe = [
9696
// Caret is not used in markdown for constructs.
9797
// An underscore can start emphasis, strong, or a thematic break.
9898
{atBreak: true, character: '_'},
99-
{before: '[^A-Za-z]', character: '_', inConstruct: 'phrasing'},
100-
{character: '_', after: '[^A-Za-z]', inConstruct: 'phrasing'},
99+
{character: '_', inConstruct: 'phrasing'},
101100
// A grave accent can start code (fenced or text), or it can break out of
102101
// a grave accent code fence.
103102
{atBreak: true, character: '`'},

test/index.js

+76
Original file line numberDiff line numberDiff line change
@@ -3585,5 +3585,81 @@ test('roundtrip', (t) => {
35853585
'should roundtrip encoded spaces and tabs where needed'
35863586
)
35873587

3588+
doc = `Separate paragraphs:
3589+
3590+
a * is this emphasis? *
3591+
3592+
a ** is this emphasis? **
3593+
3594+
a *** is this emphasis? ***
3595+
3596+
a *\\* is this emphasis? *\\*
3597+
3598+
a \\** is this emphasis? \\**
3599+
3600+
a **\\* is this emphasis? **\\*
3601+
3602+
a *\\** is this emphasis? *\\**
3603+
3604+
One paragraph:
3605+
3606+
a * is this emphasis? *
3607+
a ** is this emphasis? **
3608+
a *** is this emphasis? ***
3609+
a *\\* is this emphasis? *\\*
3610+
a \\** is this emphasis? \\**
3611+
a **\\* is this emphasis? **\\*
3612+
a *\\** is this emphasis? *\\**`
3613+
tree = from(doc)
3614+
3615+
t.deepEqual(
3616+
removePosition(tree, true),
3617+
removePosition(from(to(tree)), true),
3618+
'should roundtrip asterisks (tree)'
3619+
)
3620+
3621+
doc = `Separate paragraphs:
3622+
3623+
a _ is this emphasis? _
3624+
3625+
a __ is this emphasis? __
3626+
3627+
a ___ is this emphasis? ___
3628+
3629+
a _\\_ is this emphasis? _\\_
3630+
3631+
a \\__ is this emphasis? \\__
3632+
3633+
a __\\_ is this emphasis? __\\_
3634+
3635+
a _\\__ is this emphasis? _\\__
3636+
3637+
One paragraph:
3638+
3639+
a _ is this emphasis? _
3640+
a __ is this emphasis? __
3641+
a ___ is this emphasis? ___
3642+
a _\\_ is this emphasis? _\\_
3643+
a \\__ is this emphasis? \\__
3644+
a __\\_ is this emphasis? __\\_
3645+
a _\\__ is this emphasis? _\\__`
3646+
tree = from(doc)
3647+
3648+
t.deepEqual(
3649+
removePosition(tree, true),
3650+
removePosition(from(to(tree)), true),
3651+
'should roundtrip underscores (tree)'
3652+
)
3653+
3654+
doc = to(from(`(____`))
3655+
3656+
t.equal(doc, to(from(doc)), 'should roundtrip attention-like plain text')
3657+
3658+
doc = to(
3659+
from('Once activated, a service worker ______, then transitions to idle…')
3660+
)
3661+
3662+
t.equal(doc, to(from(doc)), 'should roundtrip faux “fill in the blank” spans')
3663+
35883664
t.end()
35893665
})

0 commit comments

Comments
 (0)