From c01fb585baa5b5d10ed2a18db2177643c1d4cf44 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Thu, 29 Apr 2021 17:05:18 -0400 Subject: [PATCH] Support horizontal rules in Classic editor Ref T727 --- less/prose-editor.less | 5 +++-- prose/markdownParser.js | 2 +- prose/markdownSerializer.js | 4 ++++ prose/prose.js | 2 +- prose/schema.js | 1 - 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/less/prose-editor.less b/less/prose-editor.less index 6a43c29..fc8e8ba 100644 --- a/less/prose-editor.less +++ b/less/prose-editor.less @@ -273,16 +273,17 @@ li.ProseMirror-selectednode:after { /* Add space around the hr to make clicking it easier */ .ProseMirror-example-setup-style hr { - padding: 2px 10px; + padding: 4px 10px; border: none; margin: 1em 0; + background: initial; } .ProseMirror-example-setup-style hr:after { content: ""; display: block; height: 1px; - background-color: silver; + background-color: #ccc; line-height: 2px; } diff --git a/prose/markdownParser.js b/prose/markdownParser.js index bd81590..1ee5a07 100644 --- a/prose/markdownParser.js +++ b/prose/markdownParser.js @@ -25,7 +25,7 @@ export const writeFreelyMarkdownParser = new MarkdownParser( getAttrs: (tok) => ({ params: tok.info || "" }), noCloseToken: true, }, - // hr: { node: "horizontal_rule" }, + hr: { node: "horizontal_rule" }, image: { node: "image", getAttrs: (tok) => ({ diff --git a/prose/markdownSerializer.js b/prose/markdownSerializer.js index d14deab..9615633 100644 --- a/prose/markdownSerializer.js +++ b/prose/markdownSerializer.js @@ -47,6 +47,10 @@ export const writeFreelyMarkdownSerializer = new MarkdownSerializer( state.renderInline(node); state.closeBlock(node); }, + horizontal_rule: function horizontal_rule(state, node) { + state.write(node.attrs.markup || "---"); + state.closeBlock(node); + }, bullet_list(state, node) { node.attrs.tight = true; state.renderList(node, " ", () => `${node.attrs.bullet || "*"} `); diff --git a/prose/prose.js b/prose/prose.js index 7c361a0..3096c9e 100644 --- a/prose/prose.js +++ b/prose/prose.js @@ -104,7 +104,7 @@ class ProseMirrorView { } get content() { - return defaultMarkdownSerializer.serialize(this.view.state.doc); + return writeFreelyMarkdownSerializer.serialize(this.view.state.doc); } focus() { this.view.focus(); diff --git a/prose/schema.js b/prose/schema.js index 67302df..0a87662 100644 --- a/prose/schema.js +++ b/prose/schema.js @@ -4,7 +4,6 @@ import { Schema } from "prosemirror-model"; export const writeFreelySchema = new Schema({ nodes: schema.spec.nodes .remove("blockquote") - .remove("horizontal_rule") .addToEnd("readmore", { inline: false, content: "",