Skip to content

Commit

Permalink
fix(mention): No extra whitespace in markdown before/after mentions
Browse files Browse the repository at this point in the history
Fixes: #6314

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Sep 4, 2024
1 parent 496c37e commit d64187c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/extensions/Mention.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export default TipTapMention.extend({
},

toMarkdown(state, node) {
state.write(' ')
state.write(`@[${node.attrs.label}](mention://user/${encodeURIComponent(node.attrs.id)})`)
state.write(' ')
},
})
12 changes: 7 additions & 5 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ describe('Markdown though editor', () => {
expect(markdownThroughEditor('---\n---')).toBe('---\n---')
})

test('mentions', () => {
expect(markdownThroughEditor('@[username](mention://user/id)')).toBe(' @[username](mention://user/id) ')
test.only('mentions', () => {
expect(markdownThroughEditor('@[username](mention://user/id)')).toBe('@[username](mention://user/id)')
expect(markdownThroughEditor('pretext @[username](mention://user/id) posttext')).toBe('pretext @[username](mention://user/id) posttext')
})

test('details', () => {
Expand Down Expand Up @@ -196,9 +197,10 @@ describe('Markdown serializer from html', () => {
expect(markdownThroughEditorHtml('<pre id="frontmatter"><code>---</code></pre><h1>Heading</h1>')).toBe('----\n---\n----\n\n# Heading')
})

test('mentions', () => {
expect(markdownThroughEditorHtml('<span class="mention" data-label="username" data-type="user" data-id="id">username</span>')).toBe(' @[username](mention://user/id) ')
expect(markdownThroughEditorHtml('<span class="mention" data-label="whitespace user" data-type="user" data-id="whitespace user">whitespace user</span>')).toBe(' @[whitespace user](mention://user/whitespace%20user) ')
test.only('mentions', () => {
expect(markdownThroughEditorHtml('<span class="mention" data-label="username" data-type="user" data-id="id">username</span>')).toBe('@[username](mention://user/id)')
expect(markdownThroughEditorHtml('<span class="mention" data-label="whitespace user" data-type="user" data-id="whitespace user">whitespace user</span>')).toBe('@[whitespace user](mention://user/whitespace%20user)')
expect(markdownThroughEditorHtml('pretext <span class="mention" data-label="username" data-type="user" data-id="id">username</span> posttext')).toBe('pretext @[username](mention://user/id) posttext')
})

test('details', () => {
Expand Down

0 comments on commit d64187c

Please sign in to comment.