Skip to content

Commit

Permalink
Remove hacky testing of commonmark parsing testing
Browse files Browse the repository at this point in the history
The commonmark parsing tests are already done by markdownit,
as suche we only need to test serializing. And of cause parsing of
markdown extensions we added.

The current "CommonMark" testing also had quite a lot of hacks
as even if we are commonmark compatible we do not yield the same html
representation (html is only a interim stage to tiptap).

Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
  • Loading branch information
susnux authored and juliushaertl committed Nov 30, 2023
1 parent 2e30ee5 commit c804604
Showing 1 changed file with 6 additions and 32 deletions.
38 changes: 6 additions & 32 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import createEditor from "../EditorFactory";
* Please add test belonging to some Node or Mark to the corresponding file in './nodes/` or `./marks/`
*/

// Goal: Input (commonmark) markdown should result in same output markdown
describe('Commonmark', () => {
const skippedMarkdownTests = [
// we interpret this as front matter
Expand All @@ -24,45 +25,18 @@ describe('Commonmark', () => {
// contain comments
309, 308,
// < > are escaped, because HTML is disabled for markdown-it
201, 490, 493, 523, 535
//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 data-syntax=".{1,2}" \/>/g, '<br />\n')
.replace(/<ul data-bullet="."/g, '<ul')
}

// 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)

// Ignore special markup for untouched markdown
expect(normalize(rendered)).toBe(expected)
})

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

Expand Down

0 comments on commit c804604

Please sign in to comment.