Skip to content

Commit

Permalink
fix(extension-mention): parse extraAttrs when parsing DOM (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
lightpohl committed Mar 7, 2020
1 parent 7c173a7 commit bd606ca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/big-pans-kneel.md
@@ -0,0 +1,5 @@
---
'@remirror/extension-mention': patch
---

parse extraAttrs when parsing mention DOM elements
27 changes: 27 additions & 0 deletions @remirror/extension-mention/src/__tests__/mention.spec.ts
Expand Up @@ -36,6 +36,33 @@ describe('schema', () => {
const expected = doc(p(mention(attrs.label)));
expect(node).toEqualProsemirrorNode(expected);
});

describe('extraAttrs', () => {
const custom = 'test';
const { schema } = createBaseTestManager([
{
extension: new MentionExtension({
matchers: [],
extraAttrs: ['data-custom'],
}),
priority: 1,
},
]);

const { doc, p, mention } = pmBuild(schema, {
mention: { markType: 'mention', ['data-custom']: custom, ...attrs },
});

it('parses the dom structure and finds itself with custom attributes', () => {
const node = fromHTML({
schema,
content: `<a class="mention mention-at" data-custom="${custom}" data-mention-id="${attrs.id}" data-mention-name="${attrs.name}">${attrs.label}</a>`,
});

const expected = doc(p(mention(attrs.label)));
expect(node).toEqualProsemirrorNode(expected);
});
});
});

describe('constructor', () => {
Expand Down
2 changes: 1 addition & 1 deletion @remirror/extension-mention/src/mention-extension.ts
Expand Up @@ -90,7 +90,7 @@ export class MentionExtension extends MarkExtension<MentionExtensionOptions> {
const id = node.getAttribute(dataAttributeId);
const name = node.getAttribute(dataAttributeName);
const label = node.innerText;
return { id, label, name };
return { ...this.getExtraAttrs(node), id, label, name };
},
},
],
Expand Down

1 comment on commit bd606ca

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.