diff --git a/app/community/routes.py b/app/community/routes.py index 99949cc3..cf70a91d 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -363,7 +363,7 @@ def add_post(actor): form.notify_author.data = True return render_template('community/add_post.html', title=_('Add post to community'), form=form, community=community, - images_disabled=images_disabled) + images_disabled=images_disabled, markdown_editor=True) @login_required diff --git a/app/post/routes.py b/app/post/routes.py index 9a9bf853..b35b3da3 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -124,7 +124,7 @@ def show_post(post_id: int): canonical=post.ap_id, form=form, replies=replies, THREAD_CUTOFF_DEPTH=constants.THREAD_CUTOFF_DEPTH, description=description, og_image=og_image, POST_TYPE_IMAGE=constants.POST_TYPE_IMAGE, POST_TYPE_LINK=constants.POST_TYPE_LINK, POST_TYPE_ARTICLE=constants.POST_TYPE_ARTICLE, - etag=f"{post.id}_{hash(post.last_active)}") + etag=f"{post.id}_{hash(post.last_active)}", markdown_editor=True) @bp.route('/post//', methods=['GET', 'POST']) @@ -276,7 +276,7 @@ def continue_discussion(post_id, comment_id): replies = get_comment_branch(post.id, comment.id, 'top') return render_template('post/continue_discussion.html', title=_('Discussing %(title)s', title=post.title), post=post, - is_moderator=is_moderator, comment=comment, replies=replies) + is_moderator=is_moderator, comment=comment, replies=replies, markdown_editor=True) @bp.route('/post//comment//reply', methods=['GET', 'POST']) @@ -384,7 +384,7 @@ def add_reply(post_id: int, comment_id: int): else: form.notify_author.data = True return render_template('post/add_reply.html', title=_('Discussing %(title)s', title=post.title), post=post, - is_moderator=is_moderator, form=form, comment=in_reply_to) + is_moderator=is_moderator, form=form, comment=in_reply_to, markdown_editor=True) @bp.route('/post//options', methods=['GET']) diff --git a/app/static/js/markdown/LICENSE b/app/static/js/markdown/LICENSE new file mode 100644 index 00000000..7d68de40 --- /dev/null +++ b/app/static/js/markdown/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Fatih EGE + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/app/static/js/markdown/demo.html b/app/static/js/markdown/demo.html deleted file mode 100644 index e09f3597..00000000 --- a/app/static/js/markdown/demo.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - -
-
- - - - - - -
-
- - diff --git a/app/static/js/markdown/downarea.css b/app/static/js/markdown/downarea.css new file mode 100644 index 00000000..c9b2e41e --- /dev/null +++ b/app/static/js/markdown/downarea.css @@ -0,0 +1,215 @@ +@import url('https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800&display=swap'); + +.downarea, .downarea * { + margin: 0; + padding: 0; + outline: none; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + font-family: 'Open Sans', -apple-system, 'Segoe UI', sans-serif; +} + +.downarea::-webkit-scrollbar , .downarea *::-webkit-scrollbar { + width: 10px; + height: 10px; +} + +.downarea::-webkit-scrollbar-thumb , .downarea *::-webkit-scrollbar-thumb { + border: 3px solid rgba(0, 0, 0, 0); + background-clip: padding-box; + background-color: #a1a1a1; +} + +.downarea::-webkit-scrollbar-thumb:hover , .downarea *::-webkit-scrollbar-thumb:hover { + background-color: #666666; +} + +.downarea { + background: #dbdbdb; + border: 1px solid #ccc; + border-radius: 3px; + width: auto; + height: 150px; + display: flex; + justify-content: center; + align-items: center; + min-width: max-content !important; + min-height: 120px !important; + position: relative; + overflow: hidden; +} + +.downarea.focused { + border-color: #bababa; +} + +.downarea .resizer { + width: 10px; + height: 10px; + border: 5px solid #909090; + border-top-color: transparent; + border-left-color: transparent; + border-bottom-right-radius: 3px; + position: absolute; + bottom: 3px; + right: 2px; + z-index: 1; +} + +.downarea .resizer.vertical { + cursor: ns-resize; +} + +.downarea .resizer.horizontal { + cursor: ew-resize; +} + +.downarea .resizer.both { + cursor: nw-resize; +} + +.downarea .downarea-wrapper { + width: 100%; + height: 100%; +} + +.downarea .downarea-toolbar { + background: #e8e8e8; + width: 100%; + display: flex; + justify-content: flex-start; + align-items: center; + padding: 5px; + border-bottom: 1px solid #cccccc; + min-width: max-content !important; +} + +.downarea.focused .downarea-toolbar { + border-bottom-color: #bababa; +} + +.downarea-toolbar .downarea-toolbar-tool { + display: flex; + justify-content: center; + align-items: center; + padding: 7px; + background: #fafafa; + border-radius: 3px; + border: 1px solid #c2c2c2; + cursor: pointer; + margin-right: 5px; + user-select: none; + position: relative; + font-size: 15px; + font-weight: 500; + color: #2f2f2f; +} + +.downarea-toolbar .downarea-toolbar-tool svg { + width: 13px; + opacity: 0.8; +} + +.downarea-toolbar .downarea-toolbar-tool:last-child { + margin-right: 0; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown { + position: absolute; + min-width: max-content; + max-height: 130px; + top: calc(100% + 2px); + left: 0; + z-index: 2; + border: 1px solid #cccccc; + border-radius: 3px; + overflow: auto; + visibility: hidden; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown.active { + visibility: visible; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown ul { + list-style-type: none; + display: block; + background: #fafafa; + cursor: default; + padding: 3px 0; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown ul li { + font-size: 15px; + padding: 5px 8px; + margin-bottom: 3px; + cursor: pointer; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown ul li:last-child { + margin-bottom: 0; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown ul li:hover { + background: #dcdcdc; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown#heading-dropdown ul li:nth-child(1) { + font-size: 22px; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown#heading-dropdown ul li:nth-child(2) { + font-size: 20px; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown#heading-dropdown ul li:nth-child(3) { + font-size: 18px; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown#heading-dropdown ul li:nth-child(4) { + font-size: 16px; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown#heading-dropdown ul li:nth-child(5) { + font-size: 14px; +} + +.downarea-toolbar .downarea-toolbar-tool .downarea-tool-dropdown#heading-dropdown ul li:nth-child(6) { + font-size: 12px; +} + +.downarea .downarea-textarea { + width: 100%; + height: max-content; + background: #fff; + position: relative; + margin-bottom: 20px; +} + +.downarea .downarea-textarea textarea { + position: relative; + width: 100%; + height: 100%; + border: none; + padding: 8px; + margin-bottom: 20px; + resize: none; + font-size: 14px; + font-weight: 500; +} + +.downarea .downarea-bottom { + width: 100%; + height: 19px; + background: #e8e8e8; + position: absolute; + bottom: 0; + left: 0; + border-top: 1px solid #cccccc; + border-bottom: 1px solid #cccccc; +} + +.downarea.focused .downarea-bottom { + border-top-color: #bababa; +} diff --git a/app/static/js/markdown/downarea.js b/app/static/js/markdown/downarea.js new file mode 100644 index 00000000..7420ecb0 --- /dev/null +++ b/app/static/js/markdown/downarea.js @@ -0,0 +1,701 @@ +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; +var repeat = function (string, count) { + var result = ''; + for (var i = 0; i < count; i++) { + result += string; + } + return result; +}; +var DownArea = (function () { + function DownArea(args) { + var _a; + var _b, _c, _d, _e, _f; + this.minWidth = 464; + this.minHeight = 120; + this.tools = []; + this.actions = (_a = {}, + _a['heading-1'] = { fn: this.addHeading }, + _a['heading-2'] = { fn: this.addHeading, args: [2] }, + _a['heading-3'] = { fn: this.addHeading, args: [3] }, + _a['heading-4'] = { fn: this.addHeading, args: [4] }, + _a['heading-5'] = { fn: this.addHeading, args: [5] }, + _a['heading-6'] = { fn: this.addHeading, args: [6] }, + _a['bold'] = { fn: this.addBold }, + _a['italic'] = { fn: this.addItalic }, + _a['bold-italic'] = { fn: this.addBoldItalic }, + _a['normal-link'] = { fn: this.addLink }, + _a['quick-link'] = { fn: this.addLink, args: [1] }, + _a['email'] = { fn: this.addEmail }, + _a['image'] = { fn: this.addImage }, + _a['blockquote'] = { fn: this.addBlockquote }, + _a['u-list'] = { fn: this.addUnorderedList }, + _a['o-list'] = { fn: this.addOrderedList }, + _a['sl-code'] = { fn: this.addSingleLineCode }, + _a['code-block'] = { fn: this.addCodeBlock }, + _a); + this.element = args.elem; + this.attr = (_b = args.attr) !== null && _b !== void 0 ? _b : {}; + this.textareaName = (_c = args.name) !== null && _c !== void 0 ? _c : null; + this.textareaValue = (_d = args.value) !== null && _d !== void 0 ? _d : ''; + this.resize = (_e = args.resize) !== null && _e !== void 0 ? _e : DownArea.RESIZE_VERTICAL; + this.hiddenTools = (_f = args.hide) !== null && _f !== void 0 ? _f : []; + this.init(); + } + DownArea.prototype.init = function () { + var _a; + if (this.element instanceof HTMLTextAreaElement) { + var containerElement = document.createElement('div'); + if (this.attr.id) { + containerElement.id = this.attr.id.join(' '); + } + if (this.attr.class) { + (_a = containerElement.classList).add.apply(_a, this.attr.class); + } + this.textarea = this.element; + this.element.parentNode.replaceChild(containerElement, this.element); + this.element = containerElement; + this.createElements(); + } + else { + this.createElements(); + } + this.registerElements(); + this.initResizer(); + this.listenTools(); + this.initDropdowns(); + this.listenTextareaEvents(); + this.setTextareaSize(); + }; + DownArea.prototype.createElements = function () { + var _a; + var downareaElement = document.createElement('div'); + downareaElement.classList.add('downarea'); + this.element.appendChild(downareaElement); + var resizer = document.createElement('div'); + resizer.classList.add('resizer'); + downareaElement.appendChild(resizer); + var wrapper = document.createElement('div'); + wrapper.classList.add('downarea-wrapper'); + downareaElement.appendChild(wrapper); + var toolbar = document.createElement('div'); + toolbar.classList.add('downarea-toolbar'); + wrapper.appendChild(toolbar); + if (this.hiddenTools.indexOf('heading') < 0) { + var headingTool = document.createElement('div'); + headingTool.classList.add('downarea-toolbar-tool'); + headingTool.dataset.dropdown = 'heading-dropdown'; + headingTool.title = 'Heading'; + headingTool.innerText = 'Heading'; + toolbar.appendChild(headingTool); + var headingDropdown = document.createElement('div'); + headingDropdown.classList.add('downarea-tool-dropdown'); + headingDropdown.id = 'heading-dropdown'; + headingDropdown.innerHTML = "
    \n
  • Heading 1
  • \n
  • Heading 2
  • \n
  • Heading 3
  • \n
  • Heading 4
  • \n
  • Heading 5
  • \n
  • Heading 6
  • \n
"; + headingTool.appendChild(headingDropdown); + } + if (this.hiddenTools.indexOf('bold') < 0) { + var boldTool = document.createElement('div'); + boldTool.classList.add('downarea-toolbar-tool'); + boldTool.dataset.action = 'bold'; + boldTool.title = 'Bold'; + boldTool.innerHTML = "\n \n \n \n "; + toolbar.appendChild(boldTool); + } + if (this.hiddenTools.indexOf('italic') < 0) { + var italicTool = document.createElement('div'); + italicTool.classList.add('downarea-toolbar-tool'); + italicTool.dataset.action = 'italic'; + italicTool.title = 'Italic'; + italicTool.innerHTML = "\n \n \n \n "; + toolbar.appendChild(italicTool); + } + if (this.hiddenTools.indexOf('bold-italic') < 0) { + var boldItalicTool = document.createElement('div'); + boldItalicTool.classList.add('downarea-toolbar-tool'); + boldItalicTool.dataset.action = 'bold-italic'; + boldItalicTool.title = 'Bold Italic'; + boldItalicTool.innerHTML = "\n \n \n \n \n \n \n \n \n "; + toolbar.appendChild(boldItalicTool); + } + if (this.hiddenTools.indexOf('link') < 0) { + var linkTool = document.createElement('div'); + linkTool.classList.add('downarea-toolbar-tool'); + linkTool.dataset.dropdown = 'link-dropdown'; + linkTool.title = 'Link'; + linkTool.innerHTML = "\n \n \n \n "; + toolbar.appendChild(linkTool); + var linkDropdown = document.createElement('div'); + linkDropdown.classList.add('downarea-tool-dropdown'); + linkDropdown.id = 'link-dropdown'; + linkDropdown.innerHTML = "
    \n
  • Normal
  • \n
  • Quick
  • \n
  • Email
  • \n
"; + linkTool.appendChild(linkDropdown); + } + if (this.hiddenTools.indexOf('image') < 0) { + var imageTool = document.createElement('div'); + imageTool.classList.add('downarea-toolbar-tool'); + imageTool.dataset.action = 'image'; + imageTool.title = 'Image'; + imageTool.innerHTML = "\n \n \n \n "; + toolbar.appendChild(imageTool); + } + if (this.hiddenTools.indexOf('blockquote') < 0) { + var blockquoteTool = document.createElement('div'); + blockquoteTool.classList.add('downarea-toolbar-tool'); + blockquoteTool.dataset.action = 'blockquote'; + blockquoteTool.title = 'Blockquote'; + blockquoteTool.innerHTML = "\n \n \n \n \n \n \n \n \n "; + toolbar.appendChild(blockquoteTool); + } + if (this.hiddenTools.indexOf('u-list') < 0) { + var unorderedListTool = document.createElement('div'); + unorderedListTool.classList.add('downarea-toolbar-tool'); + unorderedListTool.dataset.action = 'u-list'; + unorderedListTool.title = 'Unordered List'; + unorderedListTool.innerHTML = "\n \n \n \n "; + toolbar.appendChild(unorderedListTool); + } + if (this.hiddenTools.indexOf('o-list') < 0) { + var orderedListTool = document.createElement('div'); + orderedListTool.classList.add('downarea-toolbar-tool'); + orderedListTool.dataset.action = 'o-list'; + orderedListTool.title = 'Ordered List'; + orderedListTool.innerHTML = "\n \n \n \n "; + toolbar.appendChild(orderedListTool); + } + if (this.hiddenTools.indexOf('sl-code') < 0) { + var singleLineCodeTool = document.createElement('div'); + singleLineCodeTool.classList.add('downarea-toolbar-tool'); + singleLineCodeTool.dataset.action = 'sl-code'; + singleLineCodeTool.title = 'Single Line Code'; + singleLineCodeTool.innerHTML = "\n \n "; + toolbar.appendChild(singleLineCodeTool); + } + if (this.hiddenTools.indexOf('code-block') < 0) { + var codeBlockTool = document.createElement('div'); + codeBlockTool.classList.add('downarea-toolbar-tool'); + codeBlockTool.dataset.action = 'code-block'; + codeBlockTool.title = 'Code Block'; + codeBlockTool.innerHTML = "\n \n \n \n "; + toolbar.appendChild(codeBlockTool); + } + var textareaContainer = document.createElement('div'); + textareaContainer.classList.add('downarea-textarea'); + wrapper.appendChild(textareaContainer); + var textarea = (_a = this.textarea) !== null && _a !== void 0 ? _a : document.createElement('textarea'); + if (this.textareaName) { + textarea.name = this.textareaName; + } + textarea.value = this.textareaValue.toString(); + textareaContainer.appendChild(textarea); + var bottom = document.createElement('div'); + bottom.classList.add('downarea-bottom'); + wrapper.appendChild(bottom); + }; + DownArea.prototype.registerElements = function () { + this.downareaElement = this.element.querySelector('.downarea'); + this.resizer = this.downareaElement.querySelector('.resizer'); + this.toolbar = this.downareaElement.querySelector('.downarea-toolbar'); + this.textarea = this.downareaElement.querySelector('.downarea-textarea textarea'); + }; + DownArea.prototype.listenTextareaEvents = function () { + var self = this; + this.textarea.addEventListener('focusin', function () { + self.downareaElement.classList.add('focused'); + }); + this.textarea.addEventListener('focusout', function () { + self.downareaElement.classList.remove('focused'); + }); + this.textarea.addEventListener('keydown', function (e) { + if (e.key.toLowerCase() === 'enter' && DownArea.onListing !== null) { + e.preventDefault(); + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var splittedStart = start.split(/\n/g); + var list = ''; + var pattern = DownArea.onListing.type === 'unordered' ? /-\s?/ : /\d+\.\s?/; + if (splittedStart.length) { + var match = splittedStart[splittedStart.length - 1].trim().match(pattern); + if (match && match[0] === match.input) { + splittedStart.pop(); + self.textarea.value = "".concat(splittedStart.join('\n'), "\n").concat(end); + self.textarea.selectionStart = splittedStart.join('\n').length + '\n'.length; + self.textarea.selectionEnd = self.textarea.selectionStart; + return DownArea.onListing = null; + } + } + if (DownArea.onListing.type === 'unordered') { + list = "\n- "; + } + if (DownArea.onListing.type === 'ordered') { + list = "\n".concat(DownArea.onListing.number, ". "); + DownArea.onListing.number++; + } + self.textarea.value = "".concat(start).concat(list).concat(end); + self.textarea.selectionStart = start.length + list.length; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + } + if (e.key.toLowerCase() === 'tab') { + e.preventDefault(); + if (e.shiftKey) { + self.shiftTab(self); + } + else { + self.addTab(self); + } + } + }); + }; + DownArea.prototype.setTextareaSize = function () { + var downareaRect = this.downareaElement.getBoundingClientRect(); + var toolbarRect = this.toolbar.getBoundingClientRect(); + var bottomRect = this.downareaElement.querySelector('.downarea-bottom').getBoundingClientRect(); + this.textarea.style.height = downareaRect.height - toolbarRect.height - bottomRect.height + 'px'; + }; + DownArea.prototype.initResizer = function () { + var _this = this; + if (this.resize == DownArea.RESIZE_OFF) { + this.resizer.remove(); + } + else if (this.resize == DownArea.RESIZE_VERTICAL) { + this.resizer.classList.add('vertical'); + } + else if (this.resize == DownArea.RESIZE_HORIZONTAL) { + this.resizer.classList.add('horizontal'); + } + else if (this.resize == DownArea.RESIZE_BOTH) { + this.resizer.classList.add('both'); + } + var isResizing = false; + var self = this; + var mousedown = function (e) { + e.preventDefault(); + var rect = self.downareaElement.getBoundingClientRect(); + if (rect.width <= self.minWidth) { + self.downareaElement.style.width = self.minWidth + 0.1 + 'px'; + } + if (rect.height <= self.minHeight) { + self.downareaElement.style.height = self.minHeight + 0.1 + 'px'; + } + isResizing = true; + var prevX = e.clientX; + var prevY = e.clientY; + var mousemove = function (e) { + var rect = self.downareaElement.getBoundingClientRect(); + if (rect.width <= self.minWidth) { + self.downareaElement.style.width = self.minWidth + 0.1 + 'px'; + } + if (rect.height <= self.minHeight) { + self.downareaElement.style.height = self.minHeight + 0.1 + 'px'; + } + if (self.resizer.classList.contains('vertical')) { + if (rect.height > self.minHeight) { + self.downareaElement.style.height = rect.height - (prevY - e.clientY) + 'px'; + } + } + else if (self.resizer.classList.contains('horizontal')) { + if (rect.width > self.minWidth) { + self.downareaElement.style.width = rect.width - (prevX - e.clientX) + 'px'; + } + } + else if (self.resizer.classList.contains('both')) { + if (rect.width > self.minWidth) { + self.downareaElement.style.width = rect.width - (prevX - e.clientX) + 'px'; + } + if (rect.height > self.minHeight) { + self.downareaElement.style.height = rect.height - (prevY - e.clientY) + 'px'; + } + } + prevX = e.clientX; + prevY = e.clientY; + _this.setTextareaSize(); + }; + var mouseup = function () { + removeEventListener('mousemove', mousemove); + removeEventListener('mouseup', mouseup); + isResizing = false; + }; + addEventListener('mousemove', mousemove); + addEventListener('mouseup', mouseup); + }; + this.resizer.addEventListener('mousedown', mousedown); + }; + DownArea.prototype.listenTools = function () { + this.addTools(); + var self = this; + this.tools.map(function (tool) { + tool.addEventListener('click', function () { + var _a; + var action = (_a = self.actions[tool.dataset.action]) !== null && _a !== void 0 ? _a : null; + if (action) { + if (action.args) { + action.fn.apply(action, __spreadArray([self], action.args, false)); + } + else { + action.fn(self); + } + } + }); + }); + }; + DownArea.prototype.addTools = function () { + var _this = this; + var tools = this.downareaElement.querySelectorAll('div.downarea-toolbar *'); + tools.forEach(function (tool) { + if (tool.dataset.action) { + _this.tools.push(tool); + } + }); + }; + DownArea.prototype.initDropdowns = function () { + var tools = this.downareaElement.querySelectorAll('.downarea-toolbar .downarea-toolbar-tool'); + tools.forEach(function (tool) { + if (tool.dataset.dropdown) { + var dropdown_1 = tool.querySelector('#' + tool.dataset.dropdown); + tool.addEventListener('click', function () { + if (dropdown_1.classList.contains('active')) { + dropdown_1.classList.remove('active'); + } + else { + dropdown_1.classList.add('active'); + } + }); + } + }); + }; + DownArea.prototype.addTab = function (self) { + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var tab = "\t"; + self.textarea.value = "".concat(start).concat(tab).concat(end); + self.textarea.selectionStart = start.length + tab.length; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.prototype.shiftTab = function (self) { + var _a; + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + if (start[start.length - 1] == '\t') { + start = (_a = start.substr(0, start.length - 1)) !== null && _a !== void 0 ? _a : ''; + } + else if (end[0] == '\t') { + end = end.substr(1); + } + self.textarea.value = "".concat(start).concat(end); + self.textarea.selectionStart = start.length; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.prototype.addHeading = function (self, level) { + if (level === void 0) { level = 1; } + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var heading = "".concat(repeat('#', level), " "); + var offset = 0; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + heading = "".concat(heading).concat(range.trim()); + offset = 0; + } + if (start.length && start[start.length - 1] != '\n') { + heading = "\n".concat(heading); + } + if (end.length && end[0] != '\n') { + heading = "".concat(heading, "\n"); + offset = 1; + } + self.textarea.value = "".concat(start).concat(heading).concat(end); + self.textarea.selectionStart = start.length + heading.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.prototype.addBold = function (self) { + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var bold = "****"; + var offset = bold.length - 2; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + bold = "**".concat(range, "**"); + offset = 2; + } + if (start.length && start[start.length - 1] != '\n' && start[start.length - 1] != ' ') { + bold = " ".concat(bold); + } + if (end.length && end[0] != '\n' && end[0] != ' ') { + bold = "".concat(bold, " "); + offset += 1; + } + self.textarea.value = "".concat(start).concat(bold).concat(end); + self.textarea.selectionStart = start.length + bold.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.prototype.addItalic = function (self) { + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var italic = "__"; + var offset = italic.length - 1; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + italic = "_".concat(range, "_"); + offset = 1; + } + if (start.length && start[start.length - 1] != '\n' && start[start.length - 1] != ' ') { + italic = " ".concat(italic); + } + if (end.length && end[0] != '\n' && end[0] != ' ') { + italic = "".concat(italic, " "); + offset += 1; + } + self.textarea.value = "".concat(start).concat(italic).concat(end); + self.textarea.selectionStart = start.length + italic.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.prototype.addBoldItalic = function (self) { + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var bold = "******"; + var offset = bold.length - 3; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + bold = "***".concat(range, "***"); + offset = 3; + } + if (start.length && start[start.length - 1] != '\n' && start[start.length - 1] != ' ') { + bold = " ".concat(bold); + } + if (end.length && end[0] != '\n' && end[0] != ' ') { + bold = "".concat(bold, " "); + offset += 1; + } + self.textarea.value = "".concat(start).concat(bold).concat(end); + self.textarea.selectionStart = start.length + bold.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.prototype.addLink = function (self, type) { + if (type === void 0) { type = 0; } + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var link = ''; + var offset = 0; + if (type === 0) { + link = '[](https://)'; + offset = link.length - 1; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + var rangeIsURL = range.match(/https?:\/\/(.+)/); + link = rangeIsURL ? "[](".concat(range.trim(), ")") : "[".concat(range.trim(), "](https://)"); + offset = rangeIsURL ? range.trim().length + 3 : 1; + } + } + else { + link = '<>'; + offset = link.length - 1; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + link = "<".concat(range, ">"); + offset = 1; + } + } + if (start.length && start[start.length - 1] != '\n' && start[start.length - 1] != ' ') { + link = " ".concat(link); + } + if (end.length && end[0] != '\n' && end[0] != ' ') { + link = "".concat(link, " "); + offset += 1; + } + self.textarea.value = "".concat(start).concat(link).concat(end); + self.textarea.selectionStart = start.length + link.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.prototype.addEmail = function (self) { + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var emailLink = '<@>'; + var offset = emailLink.length - 1; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + emailLink = "<".concat(range, ">"); + offset = 1; + } + if (start.length && start[start.length - 1] != '\n' && start[start.length - 1] != ' ') { + emailLink = " ".concat(emailLink); + } + if (end.length && end[0] != '\n' && end[0] != ' ') { + emailLink = "".concat(emailLink, " "); + offset += 1; + } + self.textarea.value = "".concat(start).concat(emailLink).concat(end); + self.textarea.selectionStart = start.length + emailLink.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.prototype.addImage = function (self) { + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var link = "![](https://)"; + var offset = link.length - 2; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + var rangeIsURL = range.match(/https?:\/\/(.+)/); + link = rangeIsURL ? "![](".concat(range.trim(), ")") : "![".concat(range.trim(), "](https://)"); + offset = rangeIsURL ? range.trim().length + 3 : 1; + } + if (start.length && start[start.length - 1] != '\n' && start[start.length - 1] != ' ') { + link = " ".concat(link); + } + if (end.length && end[0] != '\n' && end[0] != ' ') { + link = "".concat(link, " "); + offset += 1; + } + self.textarea.value = "".concat(start).concat(link).concat(end); + self.textarea.selectionStart = start.length + link.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.prototype.addBlockquote = function (self) { + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var blockquote = "> "; + var offset = 0; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + blockquote = "".concat(blockquote).concat(range.trim()); + } + if (start.length && start[start.length - 1] != '\n') { + blockquote = "\n".concat(blockquote); + } + if (end.length && end[0] != '\n') { + blockquote = "".concat(blockquote, "\n"); + offset = 1; + } + self.textarea.value = "".concat(start).concat(blockquote).concat(end); + self.textarea.selectionStart = start.length + blockquote.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.prototype.addUnorderedList = function (self) { + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var list = "- "; + var offset = 0; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + list = "".concat(list).concat(range.trim()); + } + if (start.length && start[start.length - 1] != '\n') { + list = "\n".concat(list); + } + if (end.length && end[0] != '\n') { + list = "".concat(list, "\n"); + offset = 1; + } + self.textarea.value = "".concat(start).concat(list).concat(end); + self.textarea.selectionStart = start.length + list.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + DownArea.onListing = { + type: 'unordered' + }; + }; + DownArea.prototype.addOrderedList = function (self) { + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var list = "1. "; + var offset = 0; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + list = "".concat(list).concat(range.trim()); + } + if (start.length && start[start.length - 1] != '\n') { + list = "\n".concat(list); + } + if (end.length && end[0] != '\n') { + list = "".concat(list, "\n"); + offset = 1; + } + self.textarea.value = "".concat(start).concat(list).concat(end); + self.textarea.selectionStart = start.length + list.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + DownArea.onListing = { + type: 'ordered', + number: 2, + }; + }; + DownArea.prototype.addSingleLineCode = function (self) { + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var code = '``'; + var offset = 1; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + code = "`".concat(range, "`"); + } + if (start.length && start[start.length - 1] != '\n') { + code = " ".concat(code); + } + if (end.length && end[0] != '\n') { + code = "".concat(code, " "); + offset += 1; + } + self.textarea.value = "".concat(start).concat(code).concat(end); + self.textarea.selectionStart = start.length + code.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.prototype.addCodeBlock = function (self) { + var start = self.textarea.value.substr(0, self.textarea.selectionStart); + var end = self.textarea.value.substr(self.textarea.selectionStart); + var code = '```\n```'; + var offset = 4; + if (self.textarea.selectionStart != self.textarea.selectionEnd) { + end = self.textarea.value.substr(self.textarea.selectionEnd); + var range = self.textarea.value.slice(self.textarea.selectionStart, self.textarea.selectionEnd); + code = "```\n".concat(range, "\n```"); + offset = range.length + 5; + } + if (start.length && start[start.length - 1] != '\n') { + code = "\n".concat(code); + } + if (end.length && end[0] != '\n') { + code = "".concat(code, " "); + offset += 1; + } + self.textarea.value = "".concat(start).concat(code).concat(end); + self.textarea.selectionStart = start.length + code.length - offset; + self.textarea.selectionEnd = self.textarea.selectionStart; + self.textarea.focus(); + }; + DownArea.RESIZE_OFF = 0; + DownArea.RESIZE_VERTICAL = 1; + DownArea.RESIZE_HORIZONTAL = 2; + DownArea.RESIZE_BOTH = 3; + DownArea.onListing = null; + return DownArea; +}()); diff --git a/app/static/js/markdown/editor.css b/app/static/js/markdown/editor.css deleted file mode 100644 index 780eff4c..00000000 --- a/app/static/js/markdown/editor.css +++ /dev/null @@ -1,31 +0,0 @@ -.easy-markdown{ - position: absolute; - display: block; - left:0; - top:0; - width: 100%; - webkit-transition: left 0.7s ease-in-out 0.1s; - -moz-transition : left 0.7s ease-in-out 0.1s; - -ms-transition : left 0.7s ease-in-out 0.1s; - -o-transition : left 0.7s ease-in-out 0.1s; - transition : left 0.7s ease-in-out 0.1s; -} -.easy-preview{ - position: absolute; - display: block; - top:0; - left: 100%; - width: 100%; - - webkit-transition: left 0.7s ease-in-out 0.1s; - -moz-transition : left 0.7s ease-in-out 0.1s; - -ms-transition : left 0.7s ease-in-out 0.1s; - -o-transition : left 0.7s ease-in-out 0.1s; - transition : left 0.7s ease-in-out 0.1s; -} -.easy-markdown.is-hidden{ - left:-105%; -} -.easy-preview.is-visible{ - left:0; -} \ No newline at end of file diff --git a/app/static/js/markdown/editor.js b/app/static/js/markdown/editor.js deleted file mode 100644 index 48b8f908..00000000 --- a/app/static/js/markdown/editor.js +++ /dev/null @@ -1,725 +0,0 @@ -// MIT license - -var easyMarkdown = (function() { - 'use strict'; - var regexplink = new RegExp( - '^' + - // protocol identifier - '(?:(?:https?|ftp)://)' + - // user:pass authentication - '(?:\\S+(?::\\S*)?@)?' + - '(?:' + - // IP address exclusion - // private & local networks - '(?!(?:10|127)(?:\\.\\d{1,3}){3})' + - '(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})' + - '(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})' + - // IP address dotted notation octets - // excludes loopback network 0.0.0.0 - // excludes reserved space >= 224.0.0.0 - // excludes network & broacast addresses - // (first & last IP address of each class) - '(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' + - '(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' + - '(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' + - '|' + - // host name - '(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)' + - // domain name - '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*' + - // TLD identifier - '(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))' + - ')' + - // port number - '(?::\\d{2,5})?' + - // resource path - '(?:/\\S*)?' + - '$', 'i' - ); - var regexppic = new RegExp( - '^' + - // protocol identifier - '(?:(?:https?|ftp)://)' + - // user:pass authentication - '(?:\\S+(?::\\S*)?@)?' + - '(?:' + - // IP address exclusion - // private & local networks - '(?!(?:10|127)(?:\\.\\d{1,3}){3})' + - '(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})' + - '(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})' + - // IP address dotted notation octets - // excludes loopback network 0.0.0.0 - // excludes reserved space >= 224.0.0.0 - // excludes network & broacast addresses - // (first & last IP address of each class) - '(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' + - '(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' + - '(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' + - '|' + - // host name - '(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)' + - // domain name - '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*' + - // TLD identifier - '(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))' + - ')' + - // port number - '(?::\\d{2,5})?' + - // resource path - '(?:/\\S*)?' + - // image - '(?:jpg|gif|png)'+ - '$', 'i' - ); - function createDom(obj){ - var nodeArray = []; - for ( var i in obj){ - var node = document.createElement(obj[i].type); - for ( var j in obj[i].attrs) - node.setAttribute( j, obj[i].attrs[j]); - if (obj[i].text) - node.appendChild(document.createTextNode(obj[i].text)); - nodeArray[i] = node; - if (typeof(obj[i].childrenOf) !== 'undefined') - nodeArray[obj[i].childrenOf].appendChild(node); - } - return nodeArray[0]; - } - function createNode(el,attrs,text){ - var node = document.createElement(el); - for(var key in attrs) - node.setAttribute(key, attrs[key]); - if (text) - node.appendChild(document.createTextNode(text)); - return node; - } - function applyStyle(el,attrs){ - for(var key in attrs) - el.style[key] = attrs[key]; - } - function merge(obj) { - var i = 1,target, key; - for (; i < arguments.length; i += 1) { - target = arguments[i]; - for (key in target) - if (Object.prototype.hasOwnProperty.call(target, key)) - obj[key] = target[key]; - } - return obj; - } - function getStyle (el,styleProp){ - var y; - if (el.currentStyle) - y = el.currentStyle[styleProp]; - else if (window.getComputedStyle) - y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp); - return y; - } - function easyMarkdown(node, options) { - return new Editor(node, options); - } - /*========== BUTTONS ==========*/ - function Buttons(element,options,buttons) { - this.element = element; - this.options = options; - this.locale = merge({}, easyMarkdown.locale, easyMarkdown.locale[options.locale] || {}); - this.buttons = { - header: { - title : this.locale.header.title, - text : 'header', - group : 0, - callback : function(e) { - // Append/remove ### surround the selection - var chunk, cursor, selected = e.getSelection(), - content = e.getContent(); - if (selected.length === 0) { - // Give extra word - chunk = e.locale.header.description + '\n'; - } else { - chunk = selected.text + '\n'; - } - var key = 0, - hash='', - start = selected.start-1, - end = selected.start, - prevChr = content.substring(start,end); - while (/^\s+$|^#+$/.test(prevChr)){ - if (/^#+$/.test(prevChr)) - hash = hash+'#'; - key +=1; - prevChr = content.substring(start-key,end-key); - } - - if (hash.length > 0){ - // already a title - var startLinePos, - endLinePos = content.indexOf('\n', selected.start); - - // more than ### -> # - if (hash.length > 2){ - hash = '#'; - startLinePos = content.indexOf('\n', selected.start - 5); - e.setSelection(startLinePos, endLinePos+1); - e.replaceSelection('\n'+hash+' '+chunk); - cursor = startLinePos+3; - }else{ - hash = hash +'#'; - startLinePos = content.indexOf('\n', selected.start - (hash.length + 1)); - e.setSelection(startLinePos, endLinePos+1); - e.replaceSelection('\n'+hash+' '+chunk); - cursor = selected.start + 1; - } - }else{ - - // new title - hash= '#'; - e.replaceSelection('\n'+hash+' '+ chunk); - cursor = selected.start + 3; - } - e.setSelection(cursor, cursor + chunk.length-1); - return false; - } - }, - bold: { - title : this.locale.bold.title, - text : 'bold', - group : 0, - callback : function(e) { - // Give/remove ** surround the selection - var chunk, cursor, selected = e.getSelection(), - content = e.getContent(); - if (selected.length === 0) { - // Give extra word - chunk = e.locale.bold.description; - } else { - chunk = selected.text; - } - // transform selection and set the cursor into chunked text - if (content.substr(selected.start - 2, 2) === '**' && content.substr(selected.end, 2) === '**') { - e.setSelection(selected.start - 2, selected.end + 2); - e.replaceSelection(chunk); - cursor = selected.start - 2; - } else { - e.replaceSelection('**' + chunk + '**'); - cursor = selected.start + 2; - } - // Set the cursor - e.setSelection(cursor, cursor + chunk.length); - } - }, - italic: { - title : this.locale.italic.title, - text : 'italic', - group : 0, - callback : function(e) { - // Give/remove * surround the selection - var chunk, cursor, selected = e.getSelection(), - content = e.getContent(); - if (selected.length === 0) { - // Give extra word - chunk = e.locale.italic.description; - } else { - chunk = selected.text; - } - // transform selection and set the cursor into chunked text - if (content.substr(selected.start - 1, 1) === '_' && content.substr(selected.end, 1) === '_') { - e.setSelection(selected.start - 1, selected.end + 1); - e.replaceSelection(chunk); - cursor = selected.start - 1; - } else { - e.replaceSelection('_' + chunk + '_'); - cursor = selected.start + 1; - } - // Set the cursor - e.setSelection(cursor, cursor + chunk.length); - } - }, - image: { - title : this.locale.image.title, - text : 'image', - group : 1, - callback : function(e) { - // Give ![] surround the selection and prepend the image link - var chunk, cursor, selected = e.getSelection(), - link; - if (selected.length === 0) { - // Give extra word - chunk = e.locale.image.description; - } else { - chunk = selected.text; - } - link = prompt(e.locale.image.title, 'http://'); - if (regexppic.test(link)) { - e.replaceSelection('![' + chunk + '](' + link + ' "' + e.locale.image.description + '")'); - cursor = selected.start + 2; - e.setSelection(cursor, cursor + chunk.length); - } - return false; - } - }, - link: { - title : this.locale.link.title, - text : 'link', - group : 1, - callback : function(e) { - // Give [] surround the selection and prepend the link - var chunk, cursor, selected = e.getSelection(), - link; - if (selected.length === 0) { - // Give extra word - chunk = e.locale.link.description; - } else { - chunk = selected.text; - } - link = prompt(e.locale.link.title, 'http://'); - if (regexplink.test(link)) { - e.replaceSelection('[' + chunk + '](' + link + ')'); - cursor = selected.start + 1; - // Set the cursor - e.setSelection(cursor, cursor + chunk.length); - } - return false; - } - }, - ol: { - title : this.locale.ol.title, - text : 'ol', - group : 2, - callback : function(e) { - // Prepend/Give - surround the selection - var chunk, cursor, selected = e.getSelection(); - // transform selection and set the cursor into chunked text - if (selected.length === 0) { - // Give extra word - chunk = e.locale.ol.description; - e.replaceSelection('1. ' + chunk); - // Set the cursor - cursor = selected.start + 3; - } else { - if (selected.text.indexOf('\n') < 0) { - chunk = selected.text; - e.replaceSelection('1. ' + chunk); - // Set the cursor - cursor = selected.start + 3; - } else { - var list = []; - list = selected.text.split('\n'); - chunk = list[0]; - for (var key in list) { - var index = parseInt(key) + parseInt(1); - list[key] = index + '. ' + list[key]; - } - e.replaceSelection('\n\n' + list.join('\n')); - // Set the cursor - cursor = selected.start + 5; - } - } - // Set the cursor - e.setSelection(cursor, cursor + chunk.length); - } - }, - ul: { - title : this.locale.ul.title, - text : 'ul', - group : 2, - callback : function(e) { - // Prepend/Give - surround the selection - var chunk, cursor, selected = e.getSelection(); - // transform selection and set the cursor into chunked text - if (selected.length === 0) { - // Give extra word - chunk = e.locale.ul.description; - e.replaceSelection('- ' + chunk); - // Set the cursor - cursor = selected.start + 2; - } else { - if (selected.text.indexOf('\n') < 0) { - chunk = selected.text; - e.replaceSelection('- ' + chunk); - // Set the cursor - cursor = selected.start + 2; - } else { - var list = []; - list = selected.text.split('\n'); - chunk = list[0]; - for (var key in list) { - list[key] = '- ' + list[key]; - } - e.replaceSelection('\n\n' + list.join('\n')); - // Set the cursor - cursor = selected.start + 4; - } - } - // Set the cursor - e.setSelection(cursor, cursor + chunk.length); - } - }, - comment: { - title : this.locale.comment.title, - text : 'comment', - group : 3, - callback : function(e) { - // Prepend/Give - surround the selection - var chunk, cursor, selected = e.getSelection(), - content = e.getContent(); - // transform selection and set the cursor into chunked text - if (selected.length === 0) { - // Give extra word - chunk = e.locale.comment.description; - e.replaceSelection('> ' + chunk); - // Set the cursor - cursor = selected.start + 2; - } else { - if (selected.text.indexOf('\n') < 0) { - chunk = selected.text; - e.replaceSelection('> ' + chunk); - // Set the cursor - cursor = selected.start + 2; - } else { - var list = []; - list = selected.text.split('\n'); - chunk = list[0]; - for (var key in list) - list[key] = '> ' + list[key]; - e.replaceSelection('\n\n' + list.join('\n')); - // Set the cursor - cursor = selected.start + 4; - } - } - // Set the cursor - e.setSelection(cursor, cursor + chunk.length); - } - }, - code: { - title : this.locale.code.title, - text : 'code', - group : 3, - callback : function(e) { - // Give/remove ** surround the selection - var chunk, cursor, selected = e.getSelection(), - content = e.getContent(); - if (selected.length === 0) { - // Give extra word - chunk = e.locale.code.description; - } else { - chunk = selected.text; - } - // transform selection and set the cursor into chunked text - if (content.substr(selected.start - 4, 4) === '```\n' && content.substr(selected.end, 4) === '\n```') { - e.setSelection(selected.start - 4, selected.end + 4); - e.replaceSelection(chunk); - cursor = selected.start - 4; - } else if (content.substr(selected.start - 1, 1) === '`' && content.substr(selected.end, 1) === '`') { - e.setSelection(selected.start - 1, selected.end + 1); - e.replaceSelection(chunk); - cursor = selected.start - 1; - } else if (content.indexOf('\n') > -1) { - e.replaceSelection('```\n' + chunk + '\n```'); - cursor = selected.start + 4; - } else { - e.replaceSelection('`' + chunk + '`'); - cursor = selected.start + 1; - } - // Set the cursor - e.setSelection(cursor, cursor + chunk.length); - } - }, - preview: { - title : this.locale.preview.title, - text : 'preview', - group : 4, - callback : function(e) { - var txteditor = document.getElementById('easy-markdown'); - var preview = document.getElementById('easy-preview'); - var button = document.getElementById('easy-preview-close'); - button.removeAttribute('disabled'); - //preview.childNodes[1].childNodes[0].innerHTML = markdown.toHTML(e.element.value); - var md = window.markdownit(); - - preview.childNodes[1].innerHTML = md.render(e.element.value); - txteditor.classList.add('is-hidden'); - preview.classList.add('is-visible'); - } - } - }; - if (this.options.framework === 'bootstrap' || this.options.framework === 'foundation'){ - return this[this.options.framework](); - }else{ - return this.none(); - } - } - Buttons.prototype = { - getContent: function() { - return this.element.value; - }, - findSelection: function(chunk) { - var content = this.getContent(), - startChunkPosition; - if (startChunkPosition = content.indexOf(chunk), startChunkPosition >= 0 && chunk.length > 0) { - var oldSelection = this.getSelection(), - selection; - this.setSelection(startChunkPosition, startChunkPosition + chunk.length); - selection = this.getSelection(); - this.setSelection(oldSelection.start, oldSelection.end); - return selection; - } else { - return null; - } - }, - getSelection: function() { - var e = this.element; - return ( - ('selectionStart' in e && function() { - var l = e.selectionEnd - e.selectionStart; - return { - start: e.selectionStart, - end: e.selectionEnd, - length: l, - text: e.value.substr(e.selectionStart, l) - }; - }) || - /* browser not supported */ - function() { - return null; - } - )(); - }, - setIcons: function(element,button){ - if (typeof(this.options.icons) === 'string'){ - var t = document.createTextNode(element.title); - button.appendChild(t); - - }else{ - var i = document.createElement('I'); - i.setAttribute('class', this.options.icons[element.text]); - button.appendChild(i); - } - }, - setListener: function(node) { - var that = this; - node.addEventListener('click', function(e) { - var element = e.target, - target = (element.nodeName === 'I') ? element.parentNode : element; - that.buttons[target.getAttribute('data-md')].callback(that); - e.preventDefault(); - }, false); - return node; - }, - setSelection: function(start, end) { - var e = this.element; - return ( - ('selectionStart' in e && function() { - e.selectionStart = start; - e.selectionEnd = end; - return; - }) || - /* browser not supported */ - function() { - return null; - } - )(); - }, - replaceSelection: function(text) { - var e = this.element; - return ( - ('selectionStart' in e && function() { - e.value = e.value.substr(0, e.selectionStart) + text + e.value.substr(e.selectionEnd, e.value.length); - // Set cursor to the last replacement end - e.selectionStart = e.value.length; - return this; - }) - )(); - } - }; - Buttons.prototype.bootstrap = function(){ - var button_groups = createDom ({ - 0 : {'type':'div'}, - 1 : {'type':'div','attrs': {'class':'btn-group','role':'group','style':'margin:5px;'},'childrenOf': 0}, - 2 : {'type':'div','attrs': {'class':'btn-group','role':'group','style':'margin:5px;'},'childrenOf': 0}, - 3 : {'type':'div','attrs': {'class':'btn-group','role':'group','style':'margin:5px;'},'childrenOf': 0}, - 4 : {'type':'div','attrs': {'class':'btn-group','role':'group','style':'margin:5px;'},'childrenOf': 0}, - 5 : {'type':'div','attrs': {'class':'btn-group','role':'group','style':'margin:5px;'},'childrenOf': 0} - }); - for (var i in this.buttons) { - var obj = this.buttons[i]; - if (this.options.disabled[obj.text] !== true) { - var button = createNode('BUTTON',{'class':this.options.btnClass,'data-md':obj.text,'title':obj.title }); - this.setIcons(obj,button); - button_groups.childNodes[obj.group].appendChild(button); - } - } - this.setListener(button_groups); - return button_groups; - }; - Buttons.prototype.foundation = function(){ - var container = createNode('UL',{'class': 'button-group','style':'margin: 0 0 10px 0;'}); - for (var i in this.buttons) { - var obj = this.buttons[i]; - if (this.options.disabled[obj.text] !== true) { - var li = createNode('LI'); - var a = createNode('A',{'class':this.options.btnClass,'data-md':obj.text,'title':obj.title }); - this.setIcons(obj,a); - container.appendChild(li).appendChild(a); - } - } - this.setListener(container); - return container; - }; - Buttons.prototype.none = function(){ - var container = document.createElement('DIV'); - for (var key in this.buttons) { - var obj = this.buttons[key]; - if (this.options.disabled[obj.text] !== true) { - var button = createNode('BUTTON',{'class':this.options.btnClass,'data-md':obj.text,'title':obj.title }); - this.setIcons(obj,button); - container.appendChild(button); - } - } - this.setListener(container); - return container; - }; - /*========== SKELETON ==========*/ - - function Skeleton(options,textarea,buttons) { - this.element = textarea; - this.options = options; - this.buttons = buttons; - return this.build(); - } - Skeleton.prototype = { - build : function(){ - var buttons = new Buttons(this.element,this.options,this.buttons); - var dom = createDom ({ - 0 : {'type':'div','attrs': {'class':'easy-markdown','id':'easy-markdown'}}, - 1 : {'type':'div','attrs': {'id':'easy-markdown-buttons'},'childrenOf': 0}, - 2 : {'type':'div','attrs': {'id':'easy-markdown-textarea'},'childrenOf': 0} - }); - dom.childNodes[0].appendChild(buttons); - dom.childNodes[1].appendChild(this.element); - return dom; - } - }; - /*========== PREVIEW ==========*/ - function Preview(options,parent) { - this.parent = parent; - this.options = options; - this.locale = merge({}, easyMarkdown.locale, easyMarkdown.locale[options.locale] || {}); - return this.build(); - } - Preview.prototype = { - build: function() { - - var dom = createDom ({ - 0 : {'type':'div','attrs': {'class':'easy-preview','id':'easy-preview','style':'height:'+this.parent.clientHeight +'px;'}}, - 1 : {'type':'div','attrs': {'id':'easy-preview-buttons'},'childrenOf': 0}, - 2 : {'type':'div','attrs': {'id':'easy-preview-html','style':'overflow:auto;'},'childrenOf': 0}, - 3 : {'type':'button','attrs':{'class':this.options.btnClass,'disabled':'disabled','id':'easy-preview-close'},'text':this.locale.getback.title,'childrenOf': 1}, - 4 : {'type':'HR','childrenOf':1} - }); - this.setListener(dom.childNodes[0].childNodes[0]); - this.parent.appendChild(dom); - dom.childNodes[1].style.height = this.parent.clientHeight - dom.childNodes[0].clientHeight - 20 +'px'; - - }, - setListener : function(node){ - node.addEventListener('click', function(e) { - var txteditor = document.getElementById('easy-markdown'); - var preview = document.getElementById('easy-preview'); - var button = document.getElementById('easy-preview-close'); - button.setAttribute('disabled','disabled'); - txteditor.classList.remove('is-hidden'); - preview.classList.remove('is-visible'); - e.preventDefault(); - }, false); - return node; - } - }; - /*========== EDITOR ==========*/ - function Editor(node, options) { - this.element = node; - this.parent = node.parentNode; - this.parent.innerHTML = ''; - this.options = merge({}, Editor.defaults, options || {}); - // test if markdown.js is missing - if (typeof(markdownit) === 'undefined') - this.options.disabled.preview = true; - this.preview = 'off'; - var skeleton = new Skeleton(this.options,this.element); - node.style.width = this.options.width; - this.parent.appendChild(skeleton); - - applyStyle(this.parent,{position:'relative',height:skeleton.clientHeight+'px',overflow:'hidden'}); - new Preview(this.options,this.parent); - } - easyMarkdown.Preview = Preview; - easyMarkdown.Buttons = Buttons; - easyMarkdown.Skeleton = Skeleton; - easyMarkdown.Editor = Editor; - easyMarkdown.locale = { - bold: { - title:'Bold', - description:'Strong Text' - }, - italic: { - title:'Italic' , - description: 'Emphasized text' - }, - header: { - title:'Header', - description: 'Heading text' - }, - image: { - title:'Image', - description:'Image description' - }, - link: { - title:'Link', - description:'Link description' - }, - ol: { - title:'Numbered', - description:'Numbered list' - }, - ul: { - title:'Bullet', - description:'Bulleted list' - }, - comment: { - title:'Comment', - description: 'Comment' - }, - code: { - title:'Code', - description: 'code text' - }, - preview: { - title:'Preview' - }, - getback: { - title: 'Get back' - } - }; - Editor.defaults = { - width: '100%', - btnClass: '', - framework: 'none', - locale:'', - icons: '', - disabled: { - bold: false, - italic: false, - header: false, - image: false, - link: false, - ol: false, - ul: false, - comment: false, - code: false, - preview: false - } - }; - - return easyMarkdown; - -})(); diff --git a/app/static/js/markdown/index.min.js b/app/static/js/markdown/index.min.js deleted file mode 100644 index d4a7b8ef..00000000 --- a/app/static/js/markdown/index.min.js +++ /dev/null @@ -1 +0,0 @@ -var easyMarkdown=function(){"use strict";var t=new RegExp("^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:/\\S*)?$","i"),e=new RegExp("^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:/\\S*)?(?:jpg|gif|png)$","i");function i(t){var e=[];for(var i in t){var n=document.createElement(t[i].type);for(var l in t[i].attrs)n.setAttribute(l,t[i].attrs[l]);t[i].text&&n.appendChild(document.createTextNode(t[i].text)),e[i]=n,void 0!==t[i].childrenOf&&e[t[i].childrenOf].appendChild(n)}return e[0]}function n(t,e,i){var n=document.createElement(t);for(var l in e)n.setAttribute(l,e[l]);return i&&n.appendChild(document.createTextNode(i)),n}function l(t){for(var e,i,n=1;n0){var d,p=l.indexOf("\n",n.start);r.length>2?(r="#",d=l.indexOf("\n",n.start-5),t.setSelection(d,p+1),t.replaceSelection("\n"+r+" "+e),i=d+3):(r+="#",d=l.indexOf("\n",n.start-(r.length+1)),t.setSelection(d,p+1),t.replaceSelection("\n"+r+" "+e),i=n.start+1)}else r="#",t.replaceSelection("\n"+r+" "+e),i=n.start+3;return t.setSelection(i,i+e.length-1),!1}},bold:{title:this.locale.bold.title,text:"bold",group:0,callback:function(t){var e,i,n=t.getSelection(),l=t.getContent();e=0===n.length?t.locale.bold.description:n.text,"**"===l.substr(n.start-2,2)&&"**"===l.substr(n.end,2)?(t.setSelection(n.start-2,n.end+2),t.replaceSelection(e),i=n.start-2):(t.replaceSelection("**"+e+"**"),i=n.start+2),t.setSelection(i,i+e.length)}},italic:{title:this.locale.italic.title,text:"italic",group:0,callback:function(t){var e,i,n=t.getSelection(),l=t.getContent();e=0===n.length?t.locale.italic.description:n.text,"_"===l.substr(n.start-1,1)&&"_"===l.substr(n.end,1)?(t.setSelection(n.start-1,n.end+1),t.replaceSelection(e),i=n.start-1):(t.replaceSelection("_"+e+"_"),i=n.start+1),t.setSelection(i,i+e.length)}},image:{title:this.locale.image.title,text:"image",group:1,callback:function(t){var i,n,l,s=t.getSelection();return i=0===s.length?t.locale.image.description:s.text,l=prompt(t.locale.image.title,"http://"),e.test(l)&&(t.replaceSelection("!["+i+"]("+l+' "'+t.locale.image.description+'")'),n=s.start+2,t.setSelection(n,n+i.length)),!1}},link:{title:this.locale.link.title,text:"link",group:1,callback:function(e){var i,n,l,s=e.getSelection();return i=0===s.length?e.locale.link.description:s.text,l=prompt(e.locale.link.title,"http://"),t.test(l)&&(e.replaceSelection("["+i+"]("+l+")"),n=s.start+1,e.setSelection(n,n+i.length)),!1}},ol:{title:this.locale.ol.title,text:"ol",group:2,callback:function(t){var e,i,n=t.getSelection();if(0===n.length)e=t.locale.ol.description,t.replaceSelection("1. "+e),i=n.start+3;else if(n.text.indexOf("\n")<0)e=n.text,t.replaceSelection("1. "+e),i=n.start+3;else{var l=[];for(var s in e=(l=n.text.split("\n"))[0],l){var r=parseInt(s)+parseInt(1);l[s]=r+". "+l[s]}t.replaceSelection("\n\n"+l.join("\n")),i=n.start+5}t.setSelection(i,i+e.length)}},ul:{title:this.locale.ul.title,text:"ul",group:2,callback:function(t){var e,i,n=t.getSelection();if(0===n.length)e=t.locale.ul.description,t.replaceSelection("- "+e),i=n.start+2;else if(n.text.indexOf("\n")<0)e=n.text,t.replaceSelection("- "+e),i=n.start+2;else{var l=[];for(var s in e=(l=n.text.split("\n"))[0],l)l[s]="- "+l[s];t.replaceSelection("\n\n"+l.join("\n")),i=n.start+4}t.setSelection(i,i+e.length)}},comment:{title:this.locale.comment.title,text:"comment",group:3,callback:function(t){var e,i,n=t.getSelection();t.getContent();if(0===n.length)e=t.locale.comment.description,t.replaceSelection("> "+e),i=n.start+2;else if(n.text.indexOf("\n")<0)e=n.text,t.replaceSelection("> "+e),i=n.start+2;else{var l=[];for(var s in e=(l=n.text.split("\n"))[0],l)l[s]="> "+l[s];t.replaceSelection("\n\n"+l.join("\n")),i=n.start+4}t.setSelection(i,i+e.length)}},code:{title:this.locale.code.title,text:"code",group:3,callback:function(t){var e,i,n=t.getSelection(),l=t.getContent();e=0===n.length?t.locale.code.description:n.text,"```\n"===l.substr(n.start-4,4)&&"\n```"===l.substr(n.end,4)?(t.setSelection(n.start-4,n.end+4),t.replaceSelection(e),i=n.start-4):"`"===l.substr(n.start-1,1)&&"`"===l.substr(n.end,1)?(t.setSelection(n.start-1,n.end+1),t.replaceSelection(e),i=n.start-1):l.indexOf("\n")>-1?(t.replaceSelection("```\n"+e+"\n```"),i=n.start+4):(t.replaceSelection("`"+e+"`"),i=n.start+1),t.setSelection(i,i+e.length)}},preview:{title:this.locale.preview.title,text:"preview",group:4,callback:function(t){var e=document.getElementById("easy-markdown"),i=document.getElementById("easy-preview");document.getElementById("easy-preview-close").removeAttribute("disabled");var n=window.markdownit();i.childNodes[1].innerHTML=n.render(t.element.value),e.classList.add("is-hidden"),i.classList.add("is-visible")}}},"bootstrap"===this.options.framework||"foundation"===this.options.framework?this[this.options.framework]():this.none()}function o(t,e,i){return this.element=e,this.options=t,this.buttons=i,this.build()}function a(t,e){return this.parent=e,this.options=t,this.locale=l({},s.locale,s.locale[t.locale]||{}),this.build()}function c(t,e){this.element=t,this.parent=t.parentNode,this.parent.innerHTML="",this.options=l({},c.defaults,e||{}),"undefined"==typeof markdownit&&(this.options.disabled.preview=!0),this.preview="off";var i=new o(this.options,this.element);t.style.width=this.options.width,this.parent.appendChild(i),function(t,e){for(var i in e)t.style[i]=e[i]}(this.parent,{position:"relative",height:i.clientHeight+"px",overflow:"hidden"}),new a(this.options,this.parent)}return r.prototype={getContent:function(){return this.element.value},findSelection:function(t){var e;if((e=this.getContent().indexOf(t))>=0&&t.length>0){var i,n=this.getSelection();return this.setSelection(e,e+t.length),i=this.getSelection(),this.setSelection(n.start,n.end),i}return null},getSelection:function(){var t=this.element;return("selectionStart"in t&&function(){var e=t.selectionEnd-t.selectionStart;return{start:t.selectionStart,end:t.selectionEnd,length:e,text:t.value.substr(t.selectionStart,e)}}||function(){return null})()},setIcons:function(t,e){if("string"==typeof this.options.icons){var i=document.createTextNode(t.title);e.appendChild(i)}else{var n=document.createElement("I");n.setAttribute("class",this.options.icons[t.text]),e.appendChild(n)}},setListener:function(t){var e=this;return t.addEventListener("click",(function(t){var i=t.target,n="I"===i.nodeName?i.parentNode:i;e.buttons[n.getAttribute("data-md")].callback(e),t.preventDefault()}),!1),t},setSelection:function(t,e){var i=this.element;return("selectionStart"in i&&function(){i.selectionStart=t,i.selectionEnd=e}||function(){return null})()},replaceSelection:function(t){var e=this.element;return("selectionStart"in e&&function(){return e.value=e.value.substr(0,e.selectionStart)+t+e.value.substr(e.selectionEnd,e.value.length),e.selectionStart=e.value.length,this})()}},r.prototype.bootstrap=function(){var t=i({0:{type:"div"},1:{type:"div",attrs:{class:"btn-group",role:"group",style:"margin:5px;"},childrenOf:0},2:{type:"div",attrs:{class:"btn-group",role:"group",style:"margin:5px;"},childrenOf:0},3:{type:"div",attrs:{class:"btn-group",role:"group",style:"margin:5px;"},childrenOf:0},4:{type:"div",attrs:{class:"btn-group",role:"group",style:"margin:5px;"},childrenOf:0},5:{type:"div",attrs:{class:"btn-group",role:"group",style:"margin:5px;"},childrenOf:0}});for(var e in this.buttons){var l=this.buttons[e];if(!0!==this.options.disabled[l.text]){var s=n("BUTTON",{class:this.options.btnClass,"data-md":l.text,title:l.title});this.setIcons(l,s),t.childNodes[l.group].appendChild(s)}}return this.setListener(t),t},r.prototype.foundation=function(){var t=n("UL",{class:"button-group",style:"margin: 0 0 10px 0;"});for(var e in this.buttons){var i=this.buttons[e];if(!0!==this.options.disabled[i.text]){var l=n("LI"),s=n("A",{class:this.options.btnClass,"data-md":i.text,title:i.title});this.setIcons(i,s),t.appendChild(l).appendChild(s)}}return this.setListener(t),t},r.prototype.none=function(){var t=document.createElement("DIV");for(var e in this.buttons){var i=this.buttons[e];if(!0!==this.options.disabled[i.text]){var l=n("BUTTON",{class:this.options.btnClass,"data-md":i.text,title:i.title});this.setIcons(i,l),t.appendChild(l)}}return this.setListener(t),t},o.prototype={build:function(){var t=new r(this.element,this.options,this.buttons),e=i({0:{type:"div",attrs:{class:"easy-markdown",id:"easy-markdown"}},1:{type:"div",attrs:{id:"easy-markdown-buttons"},childrenOf:0},2:{type:"div",attrs:{id:"easy-markdown-textarea"},childrenOf:0}});return e.childNodes[0].appendChild(t),e.childNodes[1].appendChild(this.element),e}},a.prototype={build:function(){var t=i({0:{type:"div",attrs:{class:"easy-preview",id:"easy-preview",style:"height:"+this.parent.clientHeight+"px;"}},1:{type:"div",attrs:{id:"easy-preview-buttons"},childrenOf:0},2:{type:"div",attrs:{id:"easy-preview-html",style:"overflow:auto;"},childrenOf:0},3:{type:"button",attrs:{class:this.options.btnClass,disabled:"disabled",id:"easy-preview-close"},text:this.locale.getback.title,childrenOf:1},4:{type:"HR",childrenOf:1}});this.setListener(t.childNodes[0].childNodes[0]),this.parent.appendChild(t),t.childNodes[1].style.height=this.parent.clientHeight-t.childNodes[0].clientHeight-20+"px"},setListener:function(t){return t.addEventListener("click",(function(t){var e=document.getElementById("easy-markdown"),i=document.getElementById("easy-preview");document.getElementById("easy-preview-close").setAttribute("disabled","disabled"),e.classList.remove("is-hidden"),i.classList.remove("is-visible"),t.preventDefault()}),!1),t}},s.Preview=a,s.Buttons=r,s.Skeleton=o,s.Editor=c,s.locale={bold:{title:"Bold",description:"Strong Text"},italic:{title:"Italic",description:"Emphasized text"},header:{title:"Header",description:"Heading text"},image:{title:"Image",description:"Image description"},link:{title:"Link",description:"Link description"},ol:{title:"Numbered",description:"Numbered list"},ul:{title:"Bullet",description:"Bulleted list"},comment:{title:"Comment",description:"Comment"},code:{title:"Code",description:"code text"},preview:{title:"Preview"},getback:{title:"Get back"}},c.defaults={width:"100%",btnClass:"",framework:"none",locale:"",icons:"",disabled:{bold:!1,italic:!1,header:!1,image:!1,link:!1,ol:!1,ul:!1,comment:!1,code:!1,preview:!1}},s}(); diff --git a/app/templates/base.html b/app/templates/base.html index 71c44468..096e6898 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -34,6 +34,9 @@ {{ bootstrap.load_css() }} + {% if markdown_editor %} + + {% endif %} {% endblock %} {% if title %}{{ title }} - {{ _('PieFed') }}{% else %}{{ _('PieFed') }}{% endif %} @@ -120,7 +123,9 @@ {{ bootstrap.load_js() }} - + {% if markdown_editor %} + + {% endif %} {% block end_scripts %} {% endblock %} diff --git a/app/templates/community/add_post.html b/app/templates/community/add_post.html index 1095be7d..850a2ea0 100644 --- a/app/templates/community/add_post.html +++ b/app/templates/community/add_post.html @@ -24,6 +24,17 @@
{{ render_field(form.discussion_title) }} {{ render_field(form.discussion_body) }} + {% if markdown_editor %} + + {% endif %}
diff --git a/app/templates/post/post.html b/app/templates/post/post.html index 24720d88..2c903296 100644 --- a/app/templates/post/post.html +++ b/app/templates/post/post.html @@ -16,6 +16,17 @@
{{ render_form(form) }} + {% if markdown_editor %} + + {% endif %}
{% if replies %}