fix: Allow strikethrough of inline code (#5207

* fix: Allow strikethrough of inline code

* Remove unneccessary change
This commit is contained in:
Tom Moor
2023-04-17 22:26:36 -04:00
committed by GitHub
parent f2b3524d87
commit 746f4e4150
2 changed files with 35 additions and 15 deletions

View File

@@ -52,6 +52,31 @@ export default class ExtensionManager {
);
}
get marks() {
const marks = this.extensions
.filter((extension) => extension.type === "mark")
.reduce(
(marks, mark: Mark) => ({
...marks,
[mark.name]: mark.schema,
}),
{}
);
for (const i in marks) {
if (marks[i].excludes) {
// We must filter marks from the excludes list that are not defined
// in the schema for the current editor.
marks[i].excludes = marks[i].excludes
.split(" ")
.filter((m: string) => Object.keys(marks).includes(m))
.join(" ");
}
}
return marks;
}
serializer() {
const nodes = this.extensions
.filter((extension) => extension.type === "node")
@@ -104,18 +129,6 @@ export default class ExtensionManager {
return new MarkdownParser(schema, makeRules({ rules, plugins }), tokens);
}
get marks() {
return this.extensions
.filter((extension) => extension.type === "mark")
.reduce(
(marks, { name, schema }: Mark) => ({
...marks,
[name]: schema,
}),
{}
);
}
get plugins() {
return this.extensions
.filter((extension) => "plugins" in extension)

View File

@@ -4,8 +4,10 @@ import {
MarkType,
Node as ProsemirrorNode,
Mark as ProsemirrorMark,
Slice,
} from "prosemirror-model";
import { Plugin } from "prosemirror-state";
import { EditorView } from "prosemirror-view";
import moveLeft from "../commands/moveLeft";
import moveRight from "../commands/moveRight";
import markInputRule from "../lib/markInputRule";
@@ -40,7 +42,7 @@ export default class Code extends Mark {
get schema(): MarkSpec {
return {
excludes: "_",
excludes: "comment mention link placeholder highlight em strong",
parseDOM: [{ tag: "code.inline", preserveWhitespace: true }],
toDOM: () => ["code", { class: "inline", spellCheck: "false" }],
};
@@ -66,7 +68,12 @@ export default class Code extends Mark {
props: {
// Typing a character inside of two backticks will wrap the character
// in an inline code mark.
handleTextInput: (view, from: number, to: number, text: string) => {
handleTextInput: (
view: EditorView,
from: number,
to: number,
text: string
) => {
const { state } = view;
// Prevent access out of document bounds
@@ -99,7 +106,7 @@ export default class Code extends Mark {
// Pasting a character inside of two backticks will wrap the character
// in an inline code mark.
handlePaste: (view, _event, slice) => {
handlePaste: (view: EditorView, _event: Event, slice: Slice) => {
const { state } = view;
const { from, to } = state.selection;