-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5361 from nextcloud/backport/5357/stable28
[stable28] test(markdownit): separate directory for markdowit tests
- Loading branch information
Showing
9 changed files
with
145 additions
and
122 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import markdownit from '../../markdownit' | ||
import stripIndent from './stripIndent' | ||
|
||
describe('markdownit', () => { | ||
|
||
it('exposes bullet list markup', () => { | ||
['*', '-'].forEach(bullet => { | ||
const rendered = markdownit.render(`${bullet} first\n${bullet} second`) | ||
expect(stripIndent(rendered)).toBe(stripIndent(` | ||
<ul data-bullet="${bullet}"> | ||
<li>first</li> | ||
<li>second</li> | ||
</ul>` | ||
)) | ||
}) | ||
}) | ||
|
||
it('renders bullet and task lists separately', () => { | ||
const rendered = markdownit.render('* not a task\n* [ ] task') | ||
expect(stripIndent(rendered)).toBe(stripIndent(` | ||
<ul data-bullet="*"> | ||
<li>not a task</li> | ||
</ul> | ||
<ul class="contains-task-list" data-bullet="*"> | ||
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-1" />task</li> | ||
</ul>` | ||
)) | ||
}) | ||
|
||
}) |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import markdownit from '../../markdownit' | ||
import { typesAvailable } from '../../markdownit/callouts' | ||
import stripIndent from './stripIndent.js' | ||
|
||
describe('callouts', () => { | ||
typesAvailable.forEach((type) => { | ||
it(`render ${type}`, () => { | ||
const rendered = markdownit.render(`::: ${type}\nHey there!\n:::`) | ||
expect(stripIndent(rendered)).toBe(stripIndent( | ||
`<div data-callout="${type}" class="callout callout-${type}"> | ||
<p>Hey there!</p> | ||
</div>` | ||
)) | ||
}) | ||
}) | ||
}) | ||
|
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import spec from "../fixtures/spec" | ||
import markdownit from '../../markdownit' | ||
|
||
describe('Commonmark', () => { | ||
const skippedMarkdownTests = [ | ||
// we interpret this as front matter | ||
96, 98, | ||
// contain HTML | ||
21, 31, 201, 344, 474, 475, 476, 490, 493, 523, 535, 642, 643, | ||
// contain comments | ||
309, 308, | ||
]; | ||
|
||
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) { | ||
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) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import markdownit from '../../markdownit' | ||
|
||
describe('image figures extension', () => { | ||
|
||
it('renders images as figures', () => { | ||
expect(markdownit.render('[![moon](moon.jpg)](/uri)\n')) | ||
.toBe('<figure><a href=\"/uri\"><img src=\"moon.jpg\" alt=\"moon\" /></a></figure>\n') | ||
}) | ||
|
||
}) |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import markdownit from '../../markdownit' | ||
import stripIndent from './stripIndent.js' | ||
|
||
describe('markdownit', () => { | ||
|
||
it('renders mentions of users with escaped whitespace', () => { | ||
const rendered = markdownit.render('@[whitespace user](mention://user/whitespace%20user)') | ||
expect(stripIndent(rendered)).toBe(stripIndent(` | ||
<p><span class="mention" data-type="user" data-id="whitespace%20user">whitespace user</span></p>` | ||
)) | ||
}) | ||
|
||
}) |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function stripIndent(content) { | ||
return content | ||
.replace(/\n/g, "") | ||
.replace(/[\t ]+\</g, "<") | ||
.replace(/\>[\t ]+\</g, "><") | ||
.replace(/\>[\t ]+$/g, ">") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import markdownit from '../../markdownit' | ||
import stripIndent from './stripIndent' | ||
|
||
describe('task list extension', () => { | ||
|
||
it('renders task lists', () => { | ||
const rendered = markdownit.render('* [ ] task\n* not a task') | ||
expect(stripIndent(rendered)).toBe(stripIndent(` | ||
<ul class="contains-task-list" data-bullet="*"> | ||
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-0" />task</li> | ||
</ul> | ||
<ul data-bullet="*"> | ||
<li>not a task</li> | ||
</ul>` | ||
)) | ||
}) | ||
|
||
}) | ||
|