diff --git a/prose/markdownParser.js b/prose/markdownParser.js index 7088995..f50b627 100644 --- a/prose/markdownParser.js +++ b/prose/markdownParser.js @@ -34,7 +34,7 @@ export const writeAsMarkdownParser = new MarkdownParser( alt: tok.children?.[0].content || null, }), }, - // hardbreak: { node: "hard_break" }, + hardbreak: { node: "hard_break" }, em: { mark: "em" }, strong: { mark: "strong" }, @@ -49,7 +49,6 @@ export const writeAsMarkdownParser = new MarkdownParser( html_block: { node: "readmore", getAttrs(token) { - console.log({ token }); // TODO: Give different attributes depending on the token content return {}; }, diff --git a/prose/markdownSerializer.js b/prose/markdownSerializer.js index f82dc1f..bffbc98 100644 --- a/prose/markdownSerializer.js +++ b/prose/markdownSerializer.js @@ -29,7 +29,7 @@ function isPlainURL(link, parent, index, side) { export const writeAsMarkdownSerializer = new MarkdownSerializer( { readmore(state, node) { - state.write(""); + state.write("\n"); state.closeBlock(node); }, // blockquote(state, node) { @@ -78,13 +78,13 @@ export const writeAsMarkdownSerializer = new MarkdownSerializer( })`, ); }, - // hard_break(state, node, parent, index) { - // for (let i = index + 1; i < parent.childCount; i += 1) - // if (parent.child(i).type !== node.type) { - // state.write("\\\n"); - // return; - // } - // }, + hard_break(state, node, parent, index) { + for (let i = index + 1; i < parent.childCount; i += 1) + if (parent.child(i).type !== node.type) { + state.write("\n"); + return; + } + }, text(state, node) { state.text(node.text || ""); }, diff --git a/prose/prose.js b/prose/prose.js index 0ef9f7c..bc7f319 100644 --- a/prose/prose.js +++ b/prose/prose.js @@ -58,8 +58,8 @@ class ProseMirrorView { dispatchTransaction(transaction) { // console.log('saving to '+window.draftKey) const newContent = writeAsMarkdownSerializer.serialize(transaction.doc) + console.log({newContent}) $content.value = newContent - console.log({ newContent }) localStorage.setItem(window.draftKey, function () { let draft = ""; if ($title.value != null && $title.value !== "") { diff --git a/prose/schema.js b/prose/schema.js index 5c36a77..2fa6e2d 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") - .remove("hard_break") .addToEnd("readmore", { inline: false, content: "", @@ -15,5 +14,3 @@ export const writeFreelySchema = new Schema({ }), marks: schema.spec.marks, }); - -console.log({ writeFreelySchema }) \ No newline at end of file diff --git a/static/js/prose.bundle.js b/static/js/prose.bundle.js index 3489289..9b5031e 100644 --- a/static/js/prose.bundle.js +++ b/static/js/prose.bundle.js @@ -94,7 +94,7 @@ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"writeAsMarkdownParser\", function() { return writeAsMarkdownParser; });\n/* harmony import */ var prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-markdown */ \"./node_modules/prosemirror-markdown/dist/index.es.js\");\n/* harmony import */ var markdown_it__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! markdown-it */ \"./node_modules/markdown-it/index.js\");\n/* harmony import */ var markdown_it__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(markdown_it__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _schema__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./schema */ \"./schema.js\");\n\n\n\nvar writeAsMarkdownParser = new prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__[\"MarkdownParser\"](_schema__WEBPACK_IMPORTED_MODULE_2__[\"writeFreelySchema\"], markdown_it__WEBPACK_IMPORTED_MODULE_1___default()(\"commonmark\", {\n html: true\n}), {\n // blockquote: { block: \"blockquote\" },\n paragraph: {\n block: \"paragraph\"\n },\n list_item: {\n block: \"list_item\"\n },\n bullet_list: {\n block: \"bullet_list\"\n },\n ordered_list: {\n block: \"ordered_list\",\n getAttrs: function getAttrs(tok) {\n return {\n order: +tok.attrGet(\"start\") || 1\n };\n }\n },\n heading: {\n block: \"heading\",\n getAttrs: function getAttrs(tok) {\n return {\n level: +tok.tag.slice(1)\n };\n }\n },\n code_block: {\n block: \"code_block\",\n noCloseToken: true\n },\n fence: {\n block: \"code_block\",\n getAttrs: function getAttrs(tok) {\n return {\n params: tok.info || \"\"\n };\n },\n noCloseToken: true\n },\n // hr: { node: \"horizontal_rule\" },\n image: {\n node: \"image\",\n getAttrs: function getAttrs(tok) {\n var _tok$children;\n\n return {\n src: tok.attrGet(\"src\"),\n title: tok.attrGet(\"title\") || null,\n alt: ((_tok$children = tok.children) === null || _tok$children === void 0 ? void 0 : _tok$children[0].content) || null\n };\n }\n },\n // hardbreak: { node: \"hard_break\" },\n em: {\n mark: \"em\"\n },\n strong: {\n mark: \"strong\"\n },\n link: {\n mark: \"link\",\n getAttrs: function getAttrs(tok) {\n return {\n href: tok.attrGet(\"href\"),\n title: tok.attrGet(\"title\") || null\n };\n }\n },\n code_inline: {\n mark: \"code\",\n noCloseToken: true\n },\n html_block: {\n node: \"readmore\",\n getAttrs: function getAttrs(token) {\n console.log({\n token: token\n }); // TODO: Give different attributes depending on the token content\n\n return {};\n }\n }\n});\n\n//# sourceURL=webpack:///./markdownParser.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"writeAsMarkdownParser\", function() { return writeAsMarkdownParser; });\n/* harmony import */ var prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-markdown */ \"./node_modules/prosemirror-markdown/dist/index.es.js\");\n/* harmony import */ var markdown_it__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! markdown-it */ \"./node_modules/markdown-it/index.js\");\n/* harmony import */ var markdown_it__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(markdown_it__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _schema__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./schema */ \"./schema.js\");\n\n\n\nvar writeAsMarkdownParser = new prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__[\"MarkdownParser\"](_schema__WEBPACK_IMPORTED_MODULE_2__[\"writeFreelySchema\"], markdown_it__WEBPACK_IMPORTED_MODULE_1___default()(\"commonmark\", {\n html: true\n}), {\n // blockquote: { block: \"blockquote\" },\n paragraph: {\n block: \"paragraph\"\n },\n list_item: {\n block: \"list_item\"\n },\n bullet_list: {\n block: \"bullet_list\"\n },\n ordered_list: {\n block: \"ordered_list\",\n getAttrs: function getAttrs(tok) {\n return {\n order: +tok.attrGet(\"start\") || 1\n };\n }\n },\n heading: {\n block: \"heading\",\n getAttrs: function getAttrs(tok) {\n return {\n level: +tok.tag.slice(1)\n };\n }\n },\n code_block: {\n block: \"code_block\",\n noCloseToken: true\n },\n fence: {\n block: \"code_block\",\n getAttrs: function getAttrs(tok) {\n return {\n params: tok.info || \"\"\n };\n },\n noCloseToken: true\n },\n // hr: { node: \"horizontal_rule\" },\n image: {\n node: \"image\",\n getAttrs: function getAttrs(tok) {\n var _tok$children;\n\n return {\n src: tok.attrGet(\"src\"),\n title: tok.attrGet(\"title\") || null,\n alt: ((_tok$children = tok.children) === null || _tok$children === void 0 ? void 0 : _tok$children[0].content) || null\n };\n }\n },\n hardbreak: {\n node: \"hard_break\"\n },\n em: {\n mark: \"em\"\n },\n strong: {\n mark: \"strong\"\n },\n link: {\n mark: \"link\",\n getAttrs: function getAttrs(tok) {\n return {\n href: tok.attrGet(\"href\"),\n title: tok.attrGet(\"title\") || null\n };\n }\n },\n code_inline: {\n mark: \"code\",\n noCloseToken: true\n },\n html_block: {\n node: \"readmore\",\n getAttrs: function getAttrs(token) {\n // TODO: Give different attributes depending on the token content\n return {};\n }\n }\n});\n\n//# sourceURL=webpack:///./markdownParser.js?"); /***/ }), @@ -106,7 +106,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"writeAsMarkdownSerializer\", function() { return writeAsMarkdownSerializer; });\n/* harmony import */ var prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-markdown */ \"./node_modules/prosemirror-markdown/dist/index.es.js\");\n\n\nfunction backticksFor(node, side) {\n var ticks = /`+/g;\n var m;\n var len = 0;\n if (node.isText) while (m = ticks.exec(node.text)) {\n len = Math.max(len, m[0].length);\n }\n var result = len > 0 && side > 0 ? \" `\" : \"`\";\n\n for (var i = 0; i < len; i++) {\n result += \"`\";\n }\n\n if (len > 0 && side < 0) result += \" \";\n return result;\n}\n\nfunction isPlainURL(link, parent, index, side) {\n if (link.attrs.title || !/^\\w+:/.test(link.attrs.href)) return false;\n var content = parent.child(index + (side < 0 ? -1 : 0));\n if (!content.isText || content.text != link.attrs.href || content.marks[content.marks.length - 1] != link) return false;\n if (index == (side < 0 ? 1 : parent.childCount - 1)) return true;\n var next = parent.child(index + (side < 0 ? -2 : 1));\n return !link.isInSet(next.marks);\n}\n\nvar writeAsMarkdownSerializer = new prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__[\"MarkdownSerializer\"]({\n readmore: function readmore(state, node) {\n state.write(\"\");\n state.closeBlock(node);\n },\n // blockquote(state, node) {\n // state.wrapBlock(\"> \", undefined, node, () => state.renderContent(node));\n // },\n code_block: function code_block(state, node) {\n state.write(\"```\".concat(node.attrs.params || \"\", \"\\n\"));\n state.text(node.textContent, false);\n state.ensureNewLine();\n state.write(\"```\");\n state.closeBlock(node);\n },\n heading: function heading(state, node) {\n state.write(\"\".concat(state.repeat(\"#\", node.attrs.level), \" \"));\n state.renderInline(node);\n state.closeBlock(node);\n },\n // horizontal_rule(state, node) {\n // state.write(node.attrs.markup || \"---\");\n // state.closeBlock(node);\n // },\n bullet_list: function bullet_list(state, node) {\n state.renderList(node, \" \", function () {\n return \"\".concat(node.attrs.bullet || \"*\", \" \");\n });\n },\n ordered_list: function ordered_list(state, node) {\n var start = node.attrs.order || 1;\n var maxW = String(start + node.childCount - 1).length;\n var space = state.repeat(\" \", maxW + 2);\n state.renderList(node, space, function (i) {\n var nStr = String(start + i);\n return \"\".concat(state.repeat(\" \", maxW - nStr.length) + nStr, \". \");\n });\n },\n list_item: function list_item(state, node) {\n state.renderContent(node);\n },\n paragraph: function paragraph(state, node) {\n state.renderInline(node);\n state.closeBlock(node);\n },\n image: function image(state, node) {\n state.write(\"![\".concat(state.esc(node.attrs.alt || \"\"), \"](\").concat(state.esc(node.attrs.src)).concat(node.attrs.title ? \" \".concat(state.quote(node.attrs.title)) : \"\", \")\"));\n },\n // hard_break(state, node, parent, index) {\n // for (let i = index + 1; i < parent.childCount; i += 1)\n // if (parent.child(i).type !== node.type) {\n // state.write(\"\\\\\\n\");\n // return;\n // }\n // },\n text: function text(state, node) {\n state.text(node.text || \"\");\n }\n}, {\n em: {\n open: \"*\",\n close: \"*\",\n mixable: true,\n expelEnclosingWhitespace: true\n },\n strong: {\n open: \"**\",\n close: \"**\",\n mixable: true,\n expelEnclosingWhitespace: true\n },\n link: {\n open: function open(_state, mark, parent, index) {\n return isPlainURL(mark, parent, index, 1) ? \"<\" : \"[\";\n },\n close: function close(state, mark, parent, index) {\n return isPlainURL(mark, parent, index, -1) ? \">\" : \"](\".concat(state.esc(mark.attrs.href)).concat(mark.attrs.title ? \" \".concat(state.quote(mark.attrs.title)) : \"\", \")\");\n }\n },\n code: {\n open: function open(_state, _mark, parent, index) {\n return backticksFor(parent.child(index), -1);\n },\n close: function close(_state, _mark, parent, index) {\n return backticksFor(parent.child(index - 1), 1);\n },\n escape: false\n }\n});\n\n//# sourceURL=webpack:///./markdownSerializer.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"writeAsMarkdownSerializer\", function() { return writeAsMarkdownSerializer; });\n/* harmony import */ var prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-markdown */ \"./node_modules/prosemirror-markdown/dist/index.es.js\");\n\n\nfunction backticksFor(node, side) {\n var ticks = /`+/g;\n var m;\n var len = 0;\n if (node.isText) while (m = ticks.exec(node.text)) {\n len = Math.max(len, m[0].length);\n }\n var result = len > 0 && side > 0 ? \" `\" : \"`\";\n\n for (var i = 0; i < len; i++) {\n result += \"`\";\n }\n\n if (len > 0 && side < 0) result += \" \";\n return result;\n}\n\nfunction isPlainURL(link, parent, index, side) {\n if (link.attrs.title || !/^\\w+:/.test(link.attrs.href)) return false;\n var content = parent.child(index + (side < 0 ? -1 : 0));\n if (!content.isText || content.text != link.attrs.href || content.marks[content.marks.length - 1] != link) return false;\n if (index == (side < 0 ? 1 : parent.childCount - 1)) return true;\n var next = parent.child(index + (side < 0 ? -2 : 1));\n return !link.isInSet(next.marks);\n}\n\nvar writeAsMarkdownSerializer = new prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__[\"MarkdownSerializer\"]({\n readmore: function readmore(state, node) {\n state.write(\"\\n\");\n state.closeBlock(node);\n },\n // blockquote(state, node) {\n // state.wrapBlock(\"> \", undefined, node, () => state.renderContent(node));\n // },\n code_block: function code_block(state, node) {\n state.write(\"```\".concat(node.attrs.params || \"\", \"\\n\"));\n state.text(node.textContent, false);\n state.ensureNewLine();\n state.write(\"```\");\n state.closeBlock(node);\n },\n heading: function heading(state, node) {\n state.write(\"\".concat(state.repeat(\"#\", node.attrs.level), \" \"));\n state.renderInline(node);\n state.closeBlock(node);\n },\n // horizontal_rule(state, node) {\n // state.write(node.attrs.markup || \"---\");\n // state.closeBlock(node);\n // },\n bullet_list: function bullet_list(state, node) {\n state.renderList(node, \" \", function () {\n return \"\".concat(node.attrs.bullet || \"*\", \" \");\n });\n },\n ordered_list: function ordered_list(state, node) {\n var start = node.attrs.order || 1;\n var maxW = String(start + node.childCount - 1).length;\n var space = state.repeat(\" \", maxW + 2);\n state.renderList(node, space, function (i) {\n var nStr = String(start + i);\n return \"\".concat(state.repeat(\" \", maxW - nStr.length) + nStr, \". \");\n });\n },\n list_item: function list_item(state, node) {\n state.renderContent(node);\n },\n paragraph: function paragraph(state, node) {\n state.renderInline(node);\n state.closeBlock(node);\n },\n image: function image(state, node) {\n state.write(\"![\".concat(state.esc(node.attrs.alt || \"\"), \"](\").concat(state.esc(node.attrs.src)).concat(node.attrs.title ? \" \".concat(state.quote(node.attrs.title)) : \"\", \")\"));\n },\n hard_break: function hard_break(state, node, parent, index) {\n for (var i = index + 1; i < parent.childCount; i += 1) {\n if (parent.child(i).type !== node.type) {\n state.write(\"\\n\");\n return;\n }\n }\n },\n text: function text(state, node) {\n state.text(node.text || \"\");\n }\n}, {\n em: {\n open: \"*\",\n close: \"*\",\n mixable: true,\n expelEnclosingWhitespace: true\n },\n strong: {\n open: \"**\",\n close: \"**\",\n mixable: true,\n expelEnclosingWhitespace: true\n },\n link: {\n open: function open(_state, mark, parent, index) {\n return isPlainURL(mark, parent, index, 1) ? \"<\" : \"[\";\n },\n close: function close(state, mark, parent, index) {\n return isPlainURL(mark, parent, index, -1) ? \">\" : \"](\".concat(state.esc(mark.attrs.href)).concat(mark.attrs.title ? \" \".concat(state.quote(mark.attrs.title)) : \"\", \")\");\n }\n },\n code: {\n open: function open(_state, _mark, parent, index) {\n return backticksFor(parent.child(index), -1);\n },\n close: function close(_state, _mark, parent, index) {\n return backticksFor(parent.child(index - 1), 1);\n },\n escape: false\n }\n});\n\n//# sourceURL=webpack:///./markdownSerializer.js?"); /***/ }), @@ -1176,7 +1176,7 @@ eval("module.exports = function (module) {\n if (!module.webpackPolyfill) {\n /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var prosemirror_view__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-view */ \"./node_modules/prosemirror-view/dist/index.es.js\");\n/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-state */ \"./node_modules/prosemirror-state/dist/index.es.js\");\n/* harmony import */ var prosemirror_example_setup__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! prosemirror-example-setup */ \"./node_modules/prosemirror-example-setup/dist/index.es.js\");\n/* harmony import */ var prosemirror_keymap__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! prosemirror-keymap */ \"./node_modules/prosemirror-keymap/dist/index.es.js\");\n/* harmony import */ var _markdownParser__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./markdownParser */ \"./markdownParser.js\");\n/* harmony import */ var _markdownSerializer__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./markdownSerializer */ \"./markdownSerializer.js\");\n/* harmony import */ var _schema__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./schema */ \"./schema.js\");\n/* harmony import */ var _menu__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./menu */ \"./menu.js\");\nfunction _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }\n\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance\"); }\n\nfunction _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter); }\n\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n// class MarkdownView {\n// constructor(target, content) {\n// this.textarea = target.appendChild(document.createElement(\"textarea\"))\n// this.textarea.value = content\n// }\n// get content() { return this.textarea.value }\n// focus() { this.textarea.focus() }\n// destroy() { this.textarea.remove() }\n// }\n\n\n\n\n\n\n\n\nvar $title = document.querySelector('#title');\nvar $content = document.querySelector('#content');\n\nvar ProseMirrorView = /*#__PURE__*/function () {\n function ProseMirrorView(target, content) {\n _classCallCheck(this, ProseMirrorView);\n\n this.view = new prosemirror_view__WEBPACK_IMPORTED_MODULE_0__[\"EditorView\"](target, {\n state: prosemirror_state__WEBPACK_IMPORTED_MODULE_1__[\"EditorState\"].create({\n doc: function (content) {\n // console.log('loading '+window.draftKey)\n var localDraft = localStorage.getItem(window.draftKey);\n\n if (localDraft != null) {\n content = localDraft;\n }\n\n if (content.indexOf(\"# \") === 0) {\n var eol = content.indexOf(\"\\n\");\n var title = content.substring(\"# \".length, eol);\n content = content.substring(eol + \"\\n\\n\".length);\n $title.value = title;\n }\n\n return _markdownParser__WEBPACK_IMPORTED_MODULE_4__[\"writeAsMarkdownParser\"].parse(content);\n }(content),\n plugins: [Object(prosemirror_keymap__WEBPACK_IMPORTED_MODULE_3__[\"keymap\"])({\n \"Mod-Enter\": function ModEnter() {\n document.getElementById(\"publish\").click();\n return true;\n },\n \"Mod-k\": function ModK() {\n console.log(\"TODO-link\");\n return true;\n }\n })].concat(_toConsumableArray(Object(prosemirror_example_setup__WEBPACK_IMPORTED_MODULE_2__[\"exampleSetup\"])({\n schema: _schema__WEBPACK_IMPORTED_MODULE_6__[\"writeFreelySchema\"],\n menuContent: Object(_menu__WEBPACK_IMPORTED_MODULE_7__[\"getMenu\"])()\n })))\n }),\n dispatchTransaction: function dispatchTransaction(transaction) {\n // console.log('saving to '+window.draftKey)\n var newContent = _markdownSerializer__WEBPACK_IMPORTED_MODULE_5__[\"writeAsMarkdownSerializer\"].serialize(transaction.doc);\n $content.value = newContent;\n console.log({\n newContent: newContent\n });\n localStorage.setItem(window.draftKey, function () {\n var draft = \"\";\n\n if ($title.value != null && $title.value !== \"\") {\n draft = \"# \" + $title.value + \"\\n\\n\";\n }\n\n draft += $content.value;\n return draft;\n }());\n var newState = this.state.apply(transaction);\n this.updateState(newState);\n }\n });\n }\n\n _createClass(ProseMirrorView, [{\n key: \"focus\",\n value: function focus() {\n this.view.focus();\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n this.view.destroy();\n }\n }, {\n key: \"content\",\n get: function get() {\n return defaultMarkdownSerializer.serialize(this.view.state.doc);\n }\n }]);\n\n return ProseMirrorView;\n}();\n\nvar place = document.querySelector(\"#editor\");\nvar view = new ProseMirrorView(place, $content.value); // document.querySelectorAll(\"input[type=radio]\").forEach(button => {\n// button.addEventListener(\"change\", () => {\n// if (!button.checked) return\n// let View = button.value == \"markdown\" ? MarkdownView : ProseMirrorView\n// if (view instanceof View) return\n// let content = view.content\n// view.destroy()\n// view = new View(place, content)\n// view.focus()\n// })\n// })\n\n//# sourceURL=webpack:///./prose.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var prosemirror_view__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-view */ \"./node_modules/prosemirror-view/dist/index.es.js\");\n/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-state */ \"./node_modules/prosemirror-state/dist/index.es.js\");\n/* harmony import */ var prosemirror_example_setup__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! prosemirror-example-setup */ \"./node_modules/prosemirror-example-setup/dist/index.es.js\");\n/* harmony import */ var prosemirror_keymap__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! prosemirror-keymap */ \"./node_modules/prosemirror-keymap/dist/index.es.js\");\n/* harmony import */ var _markdownParser__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./markdownParser */ \"./markdownParser.js\");\n/* harmony import */ var _markdownSerializer__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./markdownSerializer */ \"./markdownSerializer.js\");\n/* harmony import */ var _schema__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./schema */ \"./schema.js\");\n/* harmony import */ var _menu__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./menu */ \"./menu.js\");\nfunction _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }\n\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance\"); }\n\nfunction _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter); }\n\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n// class MarkdownView {\n// constructor(target, content) {\n// this.textarea = target.appendChild(document.createElement(\"textarea\"))\n// this.textarea.value = content\n// }\n// get content() { return this.textarea.value }\n// focus() { this.textarea.focus() }\n// destroy() { this.textarea.remove() }\n// }\n\n\n\n\n\n\n\n\nvar $title = document.querySelector('#title');\nvar $content = document.querySelector('#content');\n\nvar ProseMirrorView = /*#__PURE__*/function () {\n function ProseMirrorView(target, content) {\n _classCallCheck(this, ProseMirrorView);\n\n this.view = new prosemirror_view__WEBPACK_IMPORTED_MODULE_0__[\"EditorView\"](target, {\n state: prosemirror_state__WEBPACK_IMPORTED_MODULE_1__[\"EditorState\"].create({\n doc: function (content) {\n // console.log('loading '+window.draftKey)\n var localDraft = localStorage.getItem(window.draftKey);\n\n if (localDraft != null) {\n content = localDraft;\n }\n\n if (content.indexOf(\"# \") === 0) {\n var eol = content.indexOf(\"\\n\");\n var title = content.substring(\"# \".length, eol);\n content = content.substring(eol + \"\\n\\n\".length);\n $title.value = title;\n }\n\n return _markdownParser__WEBPACK_IMPORTED_MODULE_4__[\"writeAsMarkdownParser\"].parse(content);\n }(content),\n plugins: [Object(prosemirror_keymap__WEBPACK_IMPORTED_MODULE_3__[\"keymap\"])({\n \"Mod-Enter\": function ModEnter() {\n document.getElementById(\"publish\").click();\n return true;\n },\n \"Mod-k\": function ModK() {\n console.log(\"TODO-link\");\n return true;\n }\n })].concat(_toConsumableArray(Object(prosemirror_example_setup__WEBPACK_IMPORTED_MODULE_2__[\"exampleSetup\"])({\n schema: _schema__WEBPACK_IMPORTED_MODULE_6__[\"writeFreelySchema\"],\n menuContent: Object(_menu__WEBPACK_IMPORTED_MODULE_7__[\"getMenu\"])()\n })))\n }),\n dispatchTransaction: function dispatchTransaction(transaction) {\n // console.log('saving to '+window.draftKey)\n var newContent = _markdownSerializer__WEBPACK_IMPORTED_MODULE_5__[\"writeAsMarkdownSerializer\"].serialize(transaction.doc);\n console.log({\n newContent: newContent\n });\n $content.value = newContent;\n localStorage.setItem(window.draftKey, function () {\n var draft = \"\";\n\n if ($title.value != null && $title.value !== \"\") {\n draft = \"# \" + $title.value + \"\\n\\n\";\n }\n\n draft += $content.value;\n return draft;\n }());\n var newState = this.state.apply(transaction);\n this.updateState(newState);\n }\n });\n }\n\n _createClass(ProseMirrorView, [{\n key: \"focus\",\n value: function focus() {\n this.view.focus();\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n this.view.destroy();\n }\n }, {\n key: \"content\",\n get: function get() {\n return defaultMarkdownSerializer.serialize(this.view.state.doc);\n }\n }]);\n\n return ProseMirrorView;\n}();\n\nvar place = document.querySelector(\"#editor\");\nvar view = new ProseMirrorView(place, $content.value); // document.querySelectorAll(\"input[type=radio]\").forEach(button => {\n// button.addEventListener(\"change\", () => {\n// if (!button.checked) return\n// let View = button.value == \"markdown\" ? MarkdownView : ProseMirrorView\n// if (view instanceof View) return\n// let content = view.content\n// view.destroy()\n// view = new View(place, content)\n// view.focus()\n// })\n// })\n\n//# sourceURL=webpack:///./prose.js?"); /***/ }), @@ -1188,7 +1188,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var pros /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"writeFreelySchema\", function() { return writeFreelySchema; });\n/* harmony import */ var prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-markdown */ \"./node_modules/prosemirror-markdown/dist/index.es.js\");\n/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-model */ \"./node_modules/prosemirror-model/dist/index.es.js\");\n\n\nvar writeFreelySchema = new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__[\"Schema\"]({\n nodes: prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__[\"schema\"].spec.nodes.remove(\"blockquote\").remove(\"horizontal_rule\").remove(\"hard_break\").addToEnd(\"readmore\", {\n inline: false,\n content: \"\",\n group: \"block\",\n draggable: true,\n toDOM: function toDOM(node) {\n return [\"div\", {\n \"class\": \"editorreadmore\",\n style: \"width: 100%;text-align:center\"\n }, \"Read more...\"];\n },\n parseDOM: [{\n tag: \"div.editorreadmore\"\n }]\n }),\n marks: prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__[\"schema\"].spec.marks\n});\nconsole.log({\n writeFreelySchema: writeFreelySchema\n});\n\n//# sourceURL=webpack:///./schema.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"writeFreelySchema\", function() { return writeFreelySchema; });\n/* harmony import */ var prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-markdown */ \"./node_modules/prosemirror-markdown/dist/index.es.js\");\n/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-model */ \"./node_modules/prosemirror-model/dist/index.es.js\");\n\n\nvar writeFreelySchema = new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__[\"Schema\"]({\n nodes: prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__[\"schema\"].spec.nodes.remove(\"blockquote\").remove(\"horizontal_rule\").addToEnd(\"readmore\", {\n inline: false,\n content: \"\",\n group: \"block\",\n draggable: true,\n toDOM: function toDOM(node) {\n return [\"div\", {\n \"class\": \"editorreadmore\",\n style: \"width: 100%;text-align:center\"\n }, \"Read more...\"];\n },\n parseDOM: [{\n tag: \"div.editorreadmore\"\n }]\n }),\n marks: prosemirror_markdown__WEBPACK_IMPORTED_MODULE_0__[\"schema\"].spec.marks\n});\n\n//# sourceURL=webpack:///./schema.js?"); /***/ })