-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fixed an issue where ruby couldn't escape pipe with a backslash
- Loading branch information
1 parent
cf11305
commit ac111a2
Showing
3 changed files
with
50 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,36 @@ | ||
import { stripIndent } from 'common-tags'; | ||
import { buildProcessorTestingCode } from './utils'; | ||
import { stringify } from '../src/index'; | ||
|
||
it( | ||
'simple ruby', | ||
buildProcessorTestingCode( | ||
`{a|b}`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 ruby[1] | ||
│ data: {"hName":"ruby","rubyText":"b"} | ||
└─0 text "a" | ||
`, | ||
`<p><ruby>a<rt>b</rt></ruby></p>`, | ||
), | ||
); | ||
const options = { | ||
partial: true, | ||
disableFormatHtml: true, | ||
}; | ||
|
||
it( | ||
'enables escape in ruby body', | ||
buildProcessorTestingCode( | ||
`{a\\|b|c}`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 ruby[1] | ||
│ data: {"hName":"ruby","rubyText":"b|c"} | ||
└─0 text "a\\\\" | ||
`, | ||
`<p><ruby>a\\<rt>b|c</rt></ruby></p>`, | ||
), | ||
); | ||
it('Simple ruby', () => { | ||
const received = stringify(`{a|b}`, options); | ||
const expected = `<p><ruby>a<rt>b</rt></ruby></p>`; | ||
expect(received).toBe(expected); | ||
}); | ||
|
||
it( | ||
'disables any inline rule in <rt>', | ||
buildProcessorTestingCode( | ||
`{a|*b*}`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 ruby[1] | ||
│ data: {"hName":"ruby","rubyText":"*b*"} | ||
└─0 text "a" | ||
`, | ||
`<p><ruby>a<rt>*b*</rt></ruby></p>`, | ||
), | ||
); | ||
it('Enables escape in ruby body', () => { | ||
const received = stringify(`{a\\|b|c}`, options); | ||
const expected = `<p><ruby>a|b<rt>c</rt></ruby></p>`; | ||
expect(received).toBe(expected); | ||
}); | ||
|
||
it( | ||
'nested ruby', | ||
buildProcessorTestingCode( | ||
`{{a|b}|c}`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[2] | ||
├─0 ruby[1] | ||
│ │ data: {"hName":"ruby","rubyText":"b"} | ||
│ └─0 text "{a" | ||
└─1 text "|c}" | ||
`, | ||
`<p><ruby>{a<rt>b</rt></ruby>|c}</p>`, | ||
), | ||
); | ||
it('Disables any inline rule in <rt>', () => { | ||
const received = stringify(`{a|*b*}`, options); | ||
const expected = `<p><ruby>a<rt>*b*</rt></ruby></p>`; | ||
expect(received).toBe(expected); | ||
}); | ||
|
||
it( | ||
'ruby with newline', | ||
buildProcessorTestingCode( | ||
`{a\nb|c}`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[3] | ||
├─0 text "{a" | ||
├─1 break | ||
└─2 text "b|c}" | ||
`, | ||
`<p>{a<br>\nb|c}</p>`, | ||
{ hardLineBreaks: true }, | ||
), | ||
); | ||
it('Nested ruby', () => { | ||
const received = stringify(`{{a|b}|c}`, options); | ||
const expected = `<p><ruby>{a<rt>b</rt></ruby>|c}</p>`; | ||
expect(received).toBe(expected); | ||
}); | ||
|
||
it('Ruby with newline', () => { | ||
const received = stringify(`{a\nb|c}`, { ...options, hardLineBreaks: true }); | ||
const expected = `<p>{a<br>\nb|c}</p>`; | ||
expect(received).toBe(expected); | ||
}); |