зеркало из https://github.com/nextcloud/text.git
Implement toMarkdown for hard break instead of replacing after markdown transformation
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Родитель
4112068233
Коммит
efb27a52f5
|
@ -24,7 +24,6 @@
|
|||
import Document from '@tiptap/extension-document'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Text from '@tiptap/extension-text'
|
||||
import HardBreak from '@tiptap/extension-hard-break'
|
||||
import History from '@tiptap/extension-history'
|
||||
import Blockquote from '@tiptap/extension-blockquote'
|
||||
import Placeholder from '@tiptap/extension-placeholder'
|
||||
|
@ -53,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'
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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
|
|
@ -79,7 +79,6 @@ const createMarkdownSerializer = ({ nodes, marks }) => {
|
|||
),
|
||||
serialize(content, options) {
|
||||
return this.serializer.serialize(content, { ...options, tightLists: true })
|
||||
.split('\\\n').join(' \n')
|
||||
.split('\\[').join('[')
|
||||
.split('\\]').join(']')
|
||||
},
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
|
||||
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'
|
||||
|
@ -28,6 +29,7 @@ import Markdown from './Markdown.js'
|
|||
|
||||
export {
|
||||
Emoji,
|
||||
HardBreak,
|
||||
Keymap,
|
||||
UserColor,
|
||||
Collaboration,
|
||||
|
|
|
@ -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__')
|
||||
|
@ -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)')
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче