Skip to content

Commit

Permalink
Merge pull request #6315 from nextcloud/fix/mention_whitespace
Browse files Browse the repository at this point in the history
fix(mention): No extra whitespace in markdown before/after mentions
  • Loading branch information
mejo- authored Sep 5, 2024
2 parents 49e6aa9 + aeeaad9 commit 19951d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 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(' ')
},
})
8 changes: 5 additions & 3 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ describe('Markdown though editor', () => {
})

test('mentions', () => {
expect(markdownThroughEditor('@[username](mention://user/id)')).toBe(' @[username](mention://user/id) ')
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 @@ -197,8 +198,9 @@ describe('Markdown serializer from html', () => {
})

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) ')
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 19951d5

Please sign in to comment.