Support horizontal rules in Classic editor

Ref T727
This commit is contained in:
Matt Baer 2021-04-29 17:05:18 -04:00
parent 02490c798c
commit c01fb585ba
5 changed files with 9 additions and 5 deletions

View File

@ -273,16 +273,17 @@ li.ProseMirror-selectednode:after {
/* Add space around the hr to make clicking it easier */ /* Add space around the hr to make clicking it easier */
.ProseMirror-example-setup-style hr { .ProseMirror-example-setup-style hr {
padding: 2px 10px; padding: 4px 10px;
border: none; border: none;
margin: 1em 0; margin: 1em 0;
background: initial;
} }
.ProseMirror-example-setup-style hr:after { .ProseMirror-example-setup-style hr:after {
content: ""; content: "";
display: block; display: block;
height: 1px; height: 1px;
background-color: silver; background-color: #ccc;
line-height: 2px; line-height: 2px;
} }

View File

@ -25,7 +25,7 @@ export const writeFreelyMarkdownParser = new MarkdownParser(
getAttrs: (tok) => ({ params: tok.info || "" }), getAttrs: (tok) => ({ params: tok.info || "" }),
noCloseToken: true, noCloseToken: true,
}, },
// hr: { node: "horizontal_rule" }, hr: { node: "horizontal_rule" },
image: { image: {
node: "image", node: "image",
getAttrs: (tok) => ({ getAttrs: (tok) => ({

View File

@ -47,6 +47,10 @@ export const writeFreelyMarkdownSerializer = new MarkdownSerializer(
state.renderInline(node); state.renderInline(node);
state.closeBlock(node); state.closeBlock(node);
}, },
horizontal_rule: function horizontal_rule(state, node) {
state.write(node.attrs.markup || "---");
state.closeBlock(node);
},
bullet_list(state, node) { bullet_list(state, node) {
node.attrs.tight = true; node.attrs.tight = true;
state.renderList(node, " ", () => `${node.attrs.bullet || "*"} `); state.renderList(node, " ", () => `${node.attrs.bullet || "*"} `);

View File

@ -104,7 +104,7 @@ class ProseMirrorView {
} }
get content() { get content() {
return defaultMarkdownSerializer.serialize(this.view.state.doc); return writeFreelyMarkdownSerializer.serialize(this.view.state.doc);
} }
focus() { focus() {
this.view.focus(); this.view.focus();

View File

@ -4,7 +4,6 @@ import { Schema } from "prosemirror-model";
export const writeFreelySchema = new Schema({ export const writeFreelySchema = new Schema({
nodes: schema.spec.nodes nodes: schema.spec.nodes
.remove("blockquote") .remove("blockquote")
.remove("horizontal_rule")
.addToEnd("readmore", { .addToEnd("readmore", {
inline: false, inline: false,
content: "", content: "",