Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/nodes
diff options
context:
space:
mode:
authorFerdinand Thiessen <rpm@fthiessen.de>2022-07-21 09:55:14 +0300
committerFerdinand Thiessen <rpm@fthiessen.de>2022-07-29 17:07:53 +0300
commit1ee4b069ca17fa08121287fe9e6f2f3beb37df1a (patch)
tree1b60fbdc9d67816547be7b28fc075c1fb53931a4 /src/nodes
parente577eec1493e47178a795341c85a305a4597efb8 (diff)
Add support for editing (not creating) FrontMatter
This adds support for parsing files containing FrontMatter and editing it as like a code block. Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
Diffstat (limited to 'src/nodes')
-rw-r--r--src/nodes/FrontMatter.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/nodes/FrontMatter.js b/src/nodes/FrontMatter.js
new file mode 100644
index 000000000..d374228d1
--- /dev/null
+++ b/src/nodes/FrontMatter.js
@@ -0,0 +1,47 @@
+import TiptapCodeBlock from '@tiptap/extension-code-block'
+
+const FrontMatter = TiptapCodeBlock.extend({
+ name: 'frontMatter',
+ addAttributes() {
+ return {
+ ...this.parent?.(),
+ class: {
+ default: 'frontmatter',
+ rendered: true,
+ },
+ }
+ },
+ parseHTML: () => {
+ return [
+ {
+ tag: 'pre[id="frontmatter"]',
+ preserveWhitespace: 'full',
+ priority: 9001,
+ attrs: {
+ language: 'yaml',
+ },
+ },
+ ]
+ },
+ toMarkdown: (state, node) => {
+ if (!state.out.match(/^\s*/)) throw Error('FrontMatter must be the first node of the document!')
+ state.write('')
+ state.out = ''
+ state.write('---\n')
+ state.text(node.textContent, false)
+ state.ensureNewLine()
+ state.write('---')
+ state.closeBlock(node)
+ },
+ // FrontMatter are only valid at the begin of a document
+ draggable: false,
+ // Override rules from Codeblock
+ addCommands() {
+ return {}
+ },
+ addInputRules: () => [],
+ addPasteRules: () => [],
+ addProseMirrorPlugins: () => [],
+})
+
+export default FrontMatter