Skip to content
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

fix: converting bullet list item with the ordered number contents(v2) #1669

Merged
merged 3 commits into from
Jul 13, 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
9 changes: 6 additions & 3 deletions apps/editor/src/js/convertor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const openingTag = `(\\\\<|<)([A-Za-z][A-Za-z0-9\\-]*${attribute})(\\/?>)`;
const HTML_TAG_RX = new RegExp(openingTag, 'g');
const FRONT_MATTER_RX = /^\s?\\-\\-\\-([\s\S]+?)\\-\\-\\-/;
const NBSP_RX = /&nbsp;/g;
const BULLET_LIST_WITH_ORDERED_NUM_RX = /^(\s*\*\s+\d+)\./g;

/**
* Class Convertor
Expand Down Expand Up @@ -77,9 +78,11 @@ class Convertor {
* @private
*/
_markdownToHtml(markdown) {
markdown = markdown.replace(HTML_TAG_RX, (match, $1, $2, $3) =>
match[0] !== '\\' ? `${$1}${$2} data-tomark-pass ${$3}` : match
);
markdown = markdown
.replace(HTML_TAG_RX, (match, $1, $2, $3) =>
match[0] !== '\\' ? `${$1}${$2} data-tomark-pass ${$3}` : match
)
.replace(BULLET_LIST_WITH_ORDERED_NUM_RX, '$1\\.');

return this.renderHTML(this.mdReader.parse(markdown));
}
Expand Down
17 changes: 17 additions & 0 deletions apps/editor/test/unit/convertor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ describe('Convertor', () => {

expect(convertor.toHTML(taskItemMd)).toBe(expectedHTML);
});

it('bullet list item having the ordered num contents should be converted as the bullet list item(not ordered list item)', () => {
const listItemMd = ['* 1. ordered num', ' * child1', ' * child2'].join('\n');
const expectedHTML = [
'<ul>',
'<li>1. ordered num',
'<ul>',
'<li>child1</li>',
'<li>child2</li>',
'</ul>',
'</li>',
'</ul>',
''
].join('\n');

expect(convertor.toHTML(listItemMd)).toBe(expectedHTML);
});
});

describe('html to markdown', () => {
Expand Down