Skip to content

Commit

Permalink
Merge pull request #6321 from nextcloud/backport/6315/stable30
Browse files Browse the repository at this point in the history
[stable30] fix(mention): No extra whitespace in markdown before/after mentions
  • Loading branch information
mejo- authored Sep 5, 2024
2 parents 46ddf56 + 6f1490e commit 9e2bd5c
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')
})
})

Expand Down Expand Up @@ -187,8 +188,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')
})
})

Expand Down

0 comments on commit 9e2bd5c

Please sign in to comment.