Files
outline/shared/editor/marks/Underline.ts
Tom Moor 92b1c578f6 feat: Improve inline rule matching (#8085)
* stash

* fix: Allow inline mark matching to work with preceding brackets
Refactor markInputRule, add markInputRuleForPattern

* docs
2024-12-07 12:46:25 -08:00

57 lines
1.2 KiB
TypeScript

import { toggleMark } from "prosemirror-commands";
import { MarkSpec, MarkType } from "prosemirror-model";
import { markInputRuleForPattern } from "../lib/markInputRule";
import underlinesRule from "../rules/underlines";
import Mark from "./Mark";
export default class Underline extends Mark {
get name() {
return "underline";
}
get schema(): MarkSpec {
return {
parseDOM: [
{ tag: "u" },
{
consuming: false,
tag: ":not(a)",
getAttrs: (node: HTMLElement) =>
node.style.textDecoration.includes("underline") ||
node.style.textDecorationLine.includes("underline")
? null
: false,
},
],
toDOM: () => ["u", 0],
};
}
get rulePlugins() {
return [underlinesRule];
}
inputRules({ type }: { type: MarkType }) {
return [markInputRuleForPattern("__", type)];
}
keys({ type }: { type: MarkType }) {
return {
"Mod-u": toggleMark(type),
};
}
toMarkdown() {
return {
open: "__",
close: "__",
mixable: true,
expelEnclosingWhitespace: true,
};
}
parseMarkdown() {
return { mark: "underline" };
}
}