-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to prevent the addition of marks on a Mention ? #1387
Comments
It’s probably just a styling issue on your side. What’s the rendered markup? |
Since this is how HTML/CSS works you have to reset styling for your mentions. .mention {
font-weight: normal;
} |
@philippkuehn but isn't it possible that the JSON output does not include the marks on the Mention ? I have specified on the Mention extension that I do not allow marks with |
marks are controlled by the parent node. in your case the paragraph. related: https://discuss.prosemirror.net/t/nodespec-marks-not-work-at-inline-node/2414 |
Thank you for this clarification. I understand better why it didn't work. Is there a clean and efficient way to control this? Because more problematic, so it is possible to add a link on a content that has text and a Mention. While in my case the mention implements a click behavior to redirect to a page ? Thanks @philippkuehn ! |
@GitHubish You can use appendTransaction to achieve this. Here's the code I'm using to automatically clean up marks of mention elements: import { Transaction, Plugin } from 'prosemirror-state';
function clearMentionMarks(
tr: Transaction, // An old transaction
newTr: Transaction, // The latest transaction
): boolean {
let cleared = false;
tr.doc.descendants((node, pos) => {
if (node.type.name === 'mention' && node.marks.length > 0) {
const mappedPos = newTr.mapping.map(pos);
newTr.setNodeMarkup(mappedPos, node.type, node.attrs, []);
cleared = true;
}
});
return cleared;
}
/**
* Remove marks from mention element.
* */
export class ClearMentionMarksPlugin extends Plugin {
constructor() {
super({
appendTransaction(transactions, oldState, newState) {
// Create a new transaction.
const newTr = newState.tr;
let cleared = false;
for (const transaction of transactions) {
const anotherClear = clearMentionMarks(transaction, newTr);
cleared = anotherClear || cleared;
}
if (cleared) {
return newTr;
}
},
});
}
} |
I am trying to prevent the addition of marks (such as bold) on my mention type. I have extended the type that Tiptap offers by trying to specify :
But it doesn't work. What am I missing?
Thanks
The text was updated successfully, but these errors were encountered: