Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/extensions/RichText.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Extension } from '@tiptap/core'
/* eslint-disable import/no-named-as-default */
import Blockquote from '@tiptap/extension-blockquote'
import Document from '@tiptap/extension-document'
import HorizontalRule from '@tiptap/extension-horizontal-rule'
import { ListItem } from '@tiptap/extension-list'
import Placeholder from '@tiptap/extension-placeholder'
import Text from '@tiptap/extension-text'
Expand All @@ -17,6 +16,7 @@ import { CharacterCount, Dropcursor, Gapcursor } from '@tiptap/extensions'
import { common, createLowlight } from 'lowlight'
import MentionSuggestion from '../components/Suggestion/Mention/suggestions.js'
import Heading from '../nodes/Heading.js'
import HorizontalRule from '../nodes/HorizontalRule.ts'
import EmojiSuggestion from './../components/Suggestion/Emoji/suggestions.js'
import LinkBubble from './../extensions/LinkBubble.js'
import LinkPicker from './../extensions/LinkPicker.js'
Expand Down
4 changes: 4 additions & 0 deletions src/markdownit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const markdownit = MarkdownIt('commonmark', { html: false, breaks: false })
markdownit.renderer.rules.front_matter = (tokens, idx, options) =>
`<pre id="frontmatter"><code>${escapeHtml(tokens[idx].meta)}</code></pre>`

// Render horizontal rules with markup attribute
markdownit.renderer.rules.hr = (tokens, idx) =>
`<hr data-markup="${escapeHtml(tokens[idx].markup || '---')}" />\n`

// Render lists with bullet attribute
markdownit.renderer.rules.bullet_list_open = (tokens, idx, options) => {
tokens[idx].attrs = [
Expand Down
39 changes: 39 additions & 0 deletions src/nodes/HorizontalRule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { nodeInputRule } from '@tiptap/core'
import TiptapHorizontalRule from '@tiptap/extension-horizontal-rule'

const HorizontalRule = TiptapHorizontalRule.extend({
addAttributes() {
return {
markup: {
default: '---',
parseHTML: (el) => el.getAttribute('data-markup') || '---',
renderHTML: (attrs) => {
if (!attrs.markup || attrs.markup === '---') {
return {}
}
return { 'data-markup': attrs.markup }
},
},
}
},

// Same triggers as upsream, but capture typed marker so it can be preserved
addInputRules() {
return [
nodeInputRule({
find: /^(?:(---|—-)|(___|\*\*\*)\s)$/,
type: this.type,
getAttributes: (match) => ({
markup: match[2] ?? '---',
}),
}),
]
},
})

export default HorizontalRule
6 changes: 6 additions & 0 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ describe('Markdown though editor', () => {
expect(markdownThroughEditor('foo\n\n---\n\nfoobar')).toBe(
'foo\n\n---\n\nfoobar',
)
expect(markdownThroughEditor('***\n\n- [ ] task\n\n***')).toBe(
'***\n\n- [ ] task\n\n***',
)
expect(markdownThroughEditor('___\n\n- [ ] task\n\n___')).toBe(
'___\n\n- [ ] task\n\n___',
)
})

test('table', () => {
Expand Down
1 change: 1 addition & 0 deletions src/tests/markdownit/commonmark.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('Commonmark', () => {
.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(/<hr data-markup="[*_-]+"/g, '<hr')
.replace(/<ul data-bullet="."/g, '<ul')
}

Expand Down
Loading