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

4 changes: 2 additions & 2 deletions js/vendors.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@tiptap/extension-code-block-lowlight": "^2.0.0-beta.68",
"@tiptap/extension-document": "^2.0.0-beta.15",
"@tiptap/extension-dropcursor": "^2.0.0-beta.25",
"@tiptap/extension-hard-break": "^2.0.0-beta.30",
"@tiptap/extension-heading": "^2.0.0-beta.26",
"@tiptap/extension-history": "^2.0.0-beta.21",
"@tiptap/extension-horizontal-rule": "^2.0.0-beta.31",
Expand Down
3 changes: 2 additions & 1 deletion src/EditorFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
TaskItem,
Callout,
} from './nodes/index.js'
import { Markdown, Emoji } from './extensions/index.js'
import { HardBreak, Markdown, Emoji } from './extensions/index.js'
import { translate as t } from '@nextcloud/l10n'
import { listLanguages, registerLanguage } from 'lowlight/lib/core'
import { emojiSearch } from '@nextcloud/vue/dist/Functions/emoji'
Expand Down Expand Up @@ -83,6 +83,7 @@ const createEditor = ({ content, onCreate, onUpdate, extensions, enableRichEditi
Markdown,
Document,
Paragraph,
HardBreak,
Heading,
Strong,
Italic,
Expand Down
37 changes: 37 additions & 0 deletions src/extensions/HardBreak.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* @copyright Copyright (c) 2022 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import TipTapHardBreak from '@tiptap/extension-hard-break'

const HardBreak = TipTapHardBreak.extend({

toMarkdown(state, node, parent, index) {
for (let i = index + 1; i < parent.childCount; i++) {
if (parent.child(i).type !== node.type) {
state.write(' \n')
return
}
}
},
})

export default HardBreak
2 changes: 2 additions & 0 deletions src/extensions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
*/

import Emoji from './Emoji.js'
import HardBreak from './HardBreak.js'
import Keymap from './Keymap.js'
import UserColor from './UserColor.js'
import Collaboration from './Collaboration.js'
import Markdown from './Markdown.js'

export {
Emoji,
HardBreak,
Keymap,
UserColor,
Collaboration,
Expand Down
10 changes: 10 additions & 0 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ describe('Markdown though editor', () => {
expect(markdownThroughEditor('#### Test')).toBe('#### Test')
expect(markdownThroughEditor('##### Test')).toBe('##### Test')
})
test('hard breaks', () => {
expect(markdownThroughEditor('hard \nbreak')).toBe('hard \nbreak')
expect(markdownThroughEditor('hard\\\nbreak')).toBe('hard \nbreak')
expect(markdownThroughEditor('no\nbreak')).toBe('no break')
})
test('inline format', () => {
expect(markdownThroughEditor('**Test**')).toBe('**Test**')
expect(markdownThroughEditor('__Test__')).toBe('__Test__')
Expand Down Expand Up @@ -131,6 +136,11 @@ describe('Markdown serializer from html', () => {
test('paragraph', () => {
expect(markdownThroughEditorHtml('<p>hello</p><p>world</p>')).toBe('hello\n\nworld')
})
test('hard line breaks', () => {
expect(markdownThroughEditorHtml('<p>hard<br />break</p>')).toBe('hard \nbreak')
expect(markdownThroughEditorHtml('<p>hard<br>break</p>')).toBe('hard \nbreak')
expect(markdownThroughEditorHtml('<p>no\nbreak</p>')).toBe('no break')
})
test('links', () => {
expect(markdownThroughEditorHtml('<a href="foo">test</a>')).toBe('[test](foo)')
})
Expand Down