mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: add html-block rich editor extension
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/** @type {RichEditorExtension} */
|
||||
const extension = {
|
||||
nodeSpec: {
|
||||
html_block: {
|
||||
attrs: { params: { default: "html" } },
|
||||
group: "block",
|
||||
content: "text*",
|
||||
code: true,
|
||||
defining: true,
|
||||
marks: "",
|
||||
isolating: true,
|
||||
selectable: true,
|
||||
draggable: true,
|
||||
parseDOM: [{ tag: "pre.html-block", preserveWhitespace: "full" }],
|
||||
toDOM() {
|
||||
return ["pre", { class: "html-block" }, ["code", 0]];
|
||||
},
|
||||
},
|
||||
},
|
||||
parse: {
|
||||
html_block: (state, token) => {
|
||||
state.openNode(state.schema.nodes.html_block);
|
||||
state.addText(token.content.trim());
|
||||
state.closeNode();
|
||||
},
|
||||
},
|
||||
serializeNode: {
|
||||
html_block: (state, node) => {
|
||||
state.renderContent(node);
|
||||
state.write("\n\n");
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default extension;
|
@@ -1,4 +1,5 @@
|
||||
import { registerRichEditorExtension } from "discourse/lib/composer/rich-editor-extensions";
|
||||
import htmlBlock from "./html-block";
|
||||
|
||||
/**
|
||||
* List of default extensions
|
||||
@@ -6,6 +7,6 @@ import { registerRichEditorExtension } from "discourse/lib/composer/rich-editor-
|
||||
*
|
||||
* @type {RichEditorExtension[]}
|
||||
*/
|
||||
const defaultExtensions = [];
|
||||
const defaultExtensions = [htmlBlock];
|
||||
|
||||
defaultExtensions.forEach(registerRichEditorExtension);
|
||||
|
Reference in New Issue
Block a user