Skip to content

Commit

Permalink
Merge 3f8f45e into 7461e48
Browse files Browse the repository at this point in the history
  • Loading branch information
susnux authored Nov 17, 2022
2 parents 7461e48 + 3f8f45e commit 1b6fb04
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,35 @@ const markdownThroughEditorHtml = (html) => {
return serializer.serialize(tiptap.state.doc)
}

// Goal: Input (commonmark) markdown should result in same output markdown
describe('Commonmark', () => {
const skippedMarkdownTests = [
// contain HTML
21, 31, 201, 344, 474, 475, 476, 490, 493, 523, 535, 642, 643,
21, 31, 344, 474, 475, 476, 642, 643,
// contain comments
309, 308,
// < > are escaped, because HTML is disabled for markdown-it
//201, 490, 493, 523, 535
];

const normalize = (str) => {
// https://github.com/markdown-it/markdown-it/blob/df4607f1d4d4be7fdc32e71c04109aea8cc373fa/test/commonmark.js#L10
return str.replace(/<blockquote><\/blockquote>/g, '<blockquote>\n</blockquote>')
.replace(/<span class="keep-md">([^<]+)<\/span>/g, '$1')
.replace(/<br \/>/, '<br />\n')
}

// special treatment because we use markdown-it-image-figures
const figureImageMarkdownTests = [
516, 519, 530, 571, 572, 573, 574, 575, 576, 577, 579, 580, 581, 582, 583, 584, 585, 587, 588, 590
]

spec.forEach((entry) => {
// We do not support HTML
if (entry.section === 'HTML blocks' || entry.section === 'Raw HTML') return;

if (skippedMarkdownTests.indexOf(entry.example) !== -1) {
if (entry.section === 'HTML blocks' ||
entry.section === 'Raw HTML' ||
skippedMarkdownTests.indexOf(entry.example) !== -1) {
return
}

test('commonmark parsing ' + entry.example, () => {
let expected = entry.markdown.includes('__')
? entry.html.replace(/<strong>/g, '<u>').replace(/<\/strong>/g, '</u>')
: entry.html
if (figureImageMarkdownTests.indexOf(entry.example) !== -1) {
expected = expected.replace(/<p>/g, '<figure>').replace(/<\/p>/g, '</figure>')
}

const rendered = markdownit.render(entry.markdown)
test('serializing ' + entry.example, () => {
const expected = markdownit.render(entry.markdown)
const serialized = markdownThroughEditorHtml(expected)

// Ignore special markup for untouched markdown
expect(normalize(rendered)).toBe(expected)
try {
expect(markdownit.render(serialized)).toBe(expected)
} catch(e) {
// This is just for debugging, so jest shows also the difference within the two markdown source codes
expect(markdownit.render(serialized) + '\n\n' + serialized).toBe(expected + '\n\n' + entry.markdown)
}
})
})
})
Expand Down

0 comments on commit 1b6fb04

Please sign in to comment.