]> BookStack Code Mirror - bookstack/blobdiff - resources/js/editor/markdown-serializer.js
Started work on details/summary blocks
[bookstack] / resources / js / editor / markdown-serializer.js
index 8e7da7d91855abefe6db3307fa62e5b58d9f65e7..57d8484dc21c39f1f65f0adae2949ff28b8e03fc 100644 (file)
@@ -9,6 +9,22 @@ nodes.callout = function (state, node) {
     writeNodeAsHtml(state, node);
 };
 
+nodes.table = function (state, node) {
+    writeNodeAsHtml(state, node);
+};
+
+nodes.iframe = function (state, node) {
+    writeNodeAsHtml(state, node);
+};
+
+nodes.details = function (state, node) {
+    wrapNodeWithHtml(state, node, '<details>', '</details>');
+};
+
+nodes.details_summary = function(state, node) {
+    writeNodeAsHtml(state, node);
+};
+
 function isPlainURL(link, parent, index, side) {
     if (link.attrs.title || !/^\w+:/.test(link.attrs.href)) {
         return false
@@ -77,7 +93,7 @@ marks.background_color = {
 
 /**
  * @param {MarkdownSerializerState} state
- * @param node
+ * @param {PmNode} node
  */
 function writeNodeAsHtml(state, node) {
     const html = docToHtml({content: [node]});
@@ -87,6 +103,22 @@ function writeNodeAsHtml(state, node) {
     state.closeBlock();
 }
 
+/**
+ * @param {MarkdownSerializerState} state
+ * @param {PmNode} node
+ * @param {String} openTag
+ * @param {String} closeTag
+ */
+function wrapNodeWithHtml(state, node, openTag, closeTag) {
+    state.write(openTag);
+    state.ensureNewLine();
+    state.renderContent(node);
+    state.write(closeTag);
+    state.closeBlock();
+    state.ensureNewLine();
+    state.write('\n');
+}
+
 // Update serializers to just write out as HTML if we have an attribute
 // or element that cannot be represented in commonmark without losing
 // formatting or content.