Skip to content

Commit

Permalink
fix: escape emphasis characters twice (fix #42) (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
seonim-ryu committed Feb 5, 2020
1 parent b8a1ac7 commit a94980b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libs/to-mark/src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var FIND_LEAD_SPACE_RX = /^\u0020/,
//find space more than one
FIND_SPACE_MORE_THAN_ONE_RX = /[\u0020]+/g,
//find characters that need escape
FIND_CHAR_TO_ESCAPE_RX = /[~>()*{}\[\]_`+-.!#|]/g,
FIND_CHAR_TO_ESCAPE_RX = /[>(){}\[\]+-.!#|]/g,
// find characters to be escaped in links or images
FIND_CHAR_TO_ESCAPE_IN_LINK_RX = /[\[\]]/g,
// find markdown image syntax
Expand Down
10 changes: 9 additions & 1 deletion libs/to-mark/test/renderer.basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('basicRenderer', function() {
expect(getMarkdownText('1. &lt;text&gt;')).toEqual('1\\. \\<text\\>');
});

it('should escape all markdown paired characters.', function() {
it('should escape all markdown paired characters', function() {
expect(getMarkdownText('foo*bar')).toBe('foo\\*bar');
expect(getMarkdownText('foo*bar*baz')).toBe('foo\\*bar\\*baz');
expect(getMarkdownText('foo**bar**baz')).toBe('foo\\*\\*bar\\*\\*baz');
Expand All @@ -65,8 +65,16 @@ describe('basicRenderer', function() {
expect(getMarkdownText('foo~bar')).toBe('foo\\~bar');
expect(getMarkdownText('foo~~bar~~baz')).toBe('foo\\~\\~bar\\~\\~baz');

expect(getMarkdownText('1. foo~bar*baz*_qux_')).toBe('1\\. foo\\~bar\\*baz\\*\\_qux\\_');
expect(getMarkdownText('> foo~bar*baz*_qux_')).toBe('\\> foo\\~bar\\*baz\\*\\_qux\\_');
});

it('should escape all backticks', function() {
expect(getMarkdownText('foo`bar')).toBe('foo\\`bar');
expect(getMarkdownText('foo`bar`')).toBe('foo\\`bar\\`');

expect(getMarkdownText('1. foo`bar`')).toBe('1\\. foo\\`bar\\`');
expect(getMarkdownText('> foo`bar`')).toBe('\\> foo\\`bar\\`');
});
});

Expand Down
4 changes: 0 additions & 4 deletions libs/to-mark/test/renderer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,14 @@ describe('renderer', function() {
it('escapeText() can process html text node for markdown text', function() {
var renderer = Renderer.factory();

expect(renderer.escapeText('im *text*')).toEqual('im \\*text\\*');
expect(renderer.escapeText('im (text)')).toEqual('im \\(text\\)');
expect(renderer.escapeText('im [text]')).toEqual('im \\[text\\]');
expect(renderer.escapeText('im {text}')).toEqual('im \\{text\\}');
expect(renderer.escapeText('im _text_')).toEqual('im \\_text\\_');
expect(renderer.escapeText('im ## text')).toEqual('im \\#\\# text');
expect(renderer.escapeText('im ` text')).toEqual('im \\` text');
expect(renderer.escapeText('im + text -')).toEqual('im \\+ text \\-');
expect(renderer.escapeText('im . text !')).toEqual('im \\. text \\!');
expect(renderer.escapeText('> im text')).toEqual('\\> im text');
expect(renderer.escapeText('im | text')).toEqual('im \\| text');
expect(renderer.escapeText('im ` text')).toEqual('im \\` text');
});

it('escapeTextHtml() can process html text node for markdown text', function() {
Expand Down

0 comments on commit a94980b

Please sign in to comment.