This commit is contained in:
parent
3adddf4938
commit
56d8aca9b0
1 changed files with 11 additions and 31 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { Schema, type Attrs } from "prosemirror-model";
|
import { Schema } from "prosemirror-model";
|
||||||
import { parse } from "regexparam";
|
import { parse } from "regexparam";
|
||||||
import { routes } from "../lib/routes";
|
import { routes } from "../lib/routes";
|
||||||
|
|
||||||
|
@ -11,20 +11,8 @@ function rgbToHex(rgb: string): string {
|
||||||
return "#" + hex(matches[1]) + hex(matches[2]) + hex(matches[3]);
|
return "#" + hex(matches[1]) + hex(matches[2]) + hex(matches[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Align = null | "center" | "right";
|
|
||||||
|
|
||||||
export type MultimediaKind = "img" | "video" | "audio" | "iframe";
|
export type MultimediaKind = "img" | "video" | "audio" | "iframe";
|
||||||
|
|
||||||
function getAlign(node: HTMLElement): Align | null {
|
|
||||||
let align = node.style.textAlign || node.getAttribute("data-align");
|
|
||||||
if (align !== "center" && align !== "right") return null;
|
|
||||||
return align;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getHeadingAttrs(level: number): (n: string | Element) => Attrs {
|
|
||||||
return (n) => ({ level, align: getAlign(n as HTMLElement) });
|
|
||||||
}
|
|
||||||
|
|
||||||
export const schema = new Schema({
|
export const schema = new Schema({
|
||||||
nodes: {
|
nodes: {
|
||||||
doc: {
|
doc: {
|
||||||
|
@ -34,17 +22,13 @@ export const schema = new Schema({
|
||||||
paragraph: {
|
paragraph: {
|
||||||
content: "inline*",
|
content: "inline*",
|
||||||
group: "block",
|
group: "block",
|
||||||
attrs: { align: { default: null } },
|
|
||||||
parseDOM: [
|
parseDOM: [
|
||||||
{
|
{
|
||||||
tag: "p",
|
tag: "p",
|
||||||
getAttrs(n) {
|
|
||||||
return { align: getAlign(n as HTMLElement) };
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
toDOM(node) {
|
toDOM() {
|
||||||
return ["p", { style: `text-align: ${node.attrs.align}` }, 0];
|
return ["p", 0];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -66,24 +50,20 @@ export const schema = new Schema({
|
||||||
},
|
},
|
||||||
|
|
||||||
heading: {
|
heading: {
|
||||||
attrs: { level: { default: 1 }, align: { default: null } },
|
attrs: { level: { default: 1 } },
|
||||||
content: "text*",
|
content: "text*",
|
||||||
group: "block",
|
group: "block",
|
||||||
defining: true,
|
defining: true,
|
||||||
parseDOM: [
|
parseDOM: [
|
||||||
{ tag: "h1", getAttrs: getHeadingAttrs(1) },
|
{ tag: "h1" },
|
||||||
{ tag: "h2", getAttrs: getHeadingAttrs(2) },
|
{ tag: "h2" },
|
||||||
{ tag: "h3", getAttrs: getHeadingAttrs(3) },
|
{ tag: "h3" },
|
||||||
{ tag: "h4", getAttrs: getHeadingAttrs(4) },
|
{ tag: "h4" },
|
||||||
{ tag: "h5", getAttrs: getHeadingAttrs(5) },
|
{ tag: "h5" },
|
||||||
{ tag: "h6", getAttrs: getHeadingAttrs(6) },
|
{ tag: "h6" },
|
||||||
],
|
],
|
||||||
toDOM(node) {
|
toDOM(node) {
|
||||||
return [
|
return ["h" + node.attrs.level, 0];
|
||||||
"h" + node.attrs.level,
|
|
||||||
{ style: `text-align: ${node.attrs.align}` },
|
|
||||||
0,
|
|
||||||
];
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue