diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-05-30 12:43:59 +0300 |
---|---|---|
committer | Max <max@nextcloud.com> | 2022-06-07 14:55:44 +0300 |
commit | efb27a52f5aed9771cb5e4a019e8a3125dfb7d59 (patch) | |
tree | bd0f4e4f629ee484113a0a8b52045ddaee26ea59 /src/extensions | |
parent | 4112068233fb16770ce211d036971668b86338a7 (diff) |
Implement toMarkdown for hard break instead of replacing after markdown transformation
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'src/extensions')
-rw-r--r-- | src/extensions/HardBreak.js | 37 | ||||
-rw-r--r-- | src/extensions/Markdown.js | 1 | ||||
-rw-r--r-- | src/extensions/index.js | 2 |
3 files changed, 39 insertions, 1 deletions
diff --git a/src/extensions/HardBreak.js b/src/extensions/HardBreak.js new file mode 100644 index 000000000..60c7518ee --- /dev/null +++ b/src/extensions/HardBreak.js @@ -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 diff --git a/src/extensions/Markdown.js b/src/extensions/Markdown.js index 7eae9c83a..c7faa5caf 100644 --- a/src/extensions/Markdown.js +++ b/src/extensions/Markdown.js @@ -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(']') }, diff --git a/src/extensions/index.js b/src/extensions/index.js index 998fff30c..d6ce69a8c 100644 --- a/src/extensions/index.js +++ b/src/extensions/index.js @@ -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, |