Skip to content

Commit

Permalink
Merge 8128f96 into 4095be6
Browse files Browse the repository at this point in the history
  • Loading branch information
juliushaertl authored Nov 13, 2022
2 parents 4095be6 + 8128f96 commit 41ed7bd
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 24 deletions.
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/markdownit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ const markdownit = MarkdownIt('commonmark', { html: false, breaks: false })
.use(keepSyntax)
.use(markdownitMentions)

// Issue #3370: To preserve softbreaks within md files we preserve all whitespaces, so we must not introduce additional new lines after a <br> element
markdownit.renderer.rules.hardbreak = (tokens, idx, options) => (options.xhtmlOut ? '<br />' : '<br>')

export default markdownit
8 changes: 7 additions & 1 deletion src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ describe('Commonmark', () => {
187, 209, 210
];

const normalize = (str) => {
return str.replace(/<span class="keep-md">([^<]+)<\/span>/g, '$1')
.replace(/<br \/>/, '<br />\n')
}

spec.forEach((entry) => {
if (skippedMarkdownTests.indexOf(entry.example) !== -1) {
return
Expand All @@ -45,8 +50,9 @@ describe('Commonmark', () => {
const expected = entry.markdown.includes('__')
? entry.html.replace(/<strong>/g, '<u>').replace(/<\/strong>/g, '</u>')
: entry.html
const rendered = markdownit.render(entry.markdown)
// Ignore special markup for untouched markdown
expect(markdownit.render(entry.markdown).replace(/<span class="keep-md">([^<]+)<\/span>/g, '$1')).toBe(expected)
expect(normalize(rendered)).toBe(expected)
})
})
})
Expand Down
16 changes: 8 additions & 8 deletions src/tests/tables.spec.js → src/tests/nodes/Table.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createEditor } from './../EditorFactory'
import { createMarkdownSerializer } from './../extensions/Markdown'
import markdownit from './../markdownit'
import input from './fixtures/table.md'
import output from './fixtures/tables/basic.out.html'
import otherStructure from './fixtures/tableWithOtherStructure.html'
import handbook from './fixtures/tables/handbook.html'
import handbookOut from './fixtures/tables/handbook.out.html'
import { createEditor } from '../../EditorFactory'
import { createMarkdownSerializer } from '../../extensions/Markdown'
import markdownit from '../../markdownit'
import input from '../fixtures/table.md'
import output from '../fixtures/tables/basic.out.html'
import otherStructure from '../fixtures/tableWithOtherStructure.html'
import handbook from '../fixtures/tables/handbook.html'
import handbookOut from '../fixtures/tables/handbook.out.html'

describe('Table', () => {

Expand Down
23 changes: 23 additions & 0 deletions src/tests/tiptap.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import createEditor from '../EditorFactory'
import markdownit from '../markdownit'

const renderedHTML = ( markdown ) => {
const editor = createEditor({
content: markdownit.render(markdown),
enableRichEditing: true
})
// Remove TrailingNode
return editor.getHTML().replace(/<p><\/p>$/, '')
}

describe('TipTap', () => {
it('render softbreaks', () => {
const markdown = 'This\nis\none\nparagraph'
expect(renderedHTML(markdown)).toEqual(`<p>${markdown}</p>`)
})

it('render hardbreak', () => {
const markdown = 'Hard line break \nNext Paragraph'
expect(renderedHTML(markdown)).toEqual('<p>Hard line break<br>Next Paragraph</p>')
})
})

0 comments on commit 41ed7bd

Please sign in to comment.