2018-09-16 15:59:22 +00:00
|
|
|
<template lang='pug'>
|
2019-01-26 01:00:30 +00:00
|
|
|
.editor-markdown
|
2019-05-18 06:27:30 +00:00
|
|
|
v-toolbar.editor-markdown-toolbar(dense, color='primary', dark, flat, style='overflow-x: hidden;')
|
2019-05-21 20:45:27 +00:00
|
|
|
template(v-if='isModalShown')
|
|
|
|
v-spacer
|
2019-08-04 02:51:29 +00:00
|
|
|
v-btn.animated.fadeInRight(text, @click='closeAllModal')
|
|
|
|
v-icon(left) mdi-arrow-left-circle
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:backToEditor')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
template(v-else)
|
|
|
|
v-tooltip(bottom, color='primary')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn(icon, tile, v-on='on', @click='toggleMarkup({ start: `**` })').mx-0
|
|
|
|
v-icon mdi-format-bold
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.bold')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-tooltip(bottom, color='primary')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn.wait-p1s(icon, tile, v-on='on', @click='toggleMarkup({ start: `*` })').mx-0
|
|
|
|
v-icon mdi-format-italic
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.italic')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-tooltip(bottom, color='primary')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn.wait-p2s(icon, tile, v-on='on', @click='toggleMarkup({ start: `~~` })').mx-0
|
|
|
|
v-icon mdi-format-strikethrough
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.strikethrough')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-menu(offset-y, open-on-hover)
|
2019-08-03 04:48:55 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2019-08-04 02:51:29 +00:00
|
|
|
v-btn.animated.fadeIn.wait-p3s(icon, tile, v-on='on').mx-0
|
2019-08-03 04:48:55 +00:00
|
|
|
v-icon mdi-format-header-pound
|
2019-05-11 05:23:32 +00:00
|
|
|
v-list.py-0
|
|
|
|
template(v-for='(n, idx) in 6')
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item(@click='setHeaderLine(n)', :key='idx')
|
|
|
|
v-list-item-action
|
2019-08-03 04:48:55 +00:00
|
|
|
v-icon(:size='24 - (idx - 1) * 2') mdi-format-header-{{n}}
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-title {{$t('editor:markup.heading', { level: n })}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-divider(v-if='idx < 5')
|
|
|
|
v-tooltip(bottom, color='primary')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn.wait-p4s(icon, tile, v-on='on', @click='toggleMarkup({ start: `~` })').mx-0
|
|
|
|
v-icon mdi-format-subscript
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.subscript')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-tooltip(bottom, color='primary')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn.wait-p5s(icon, tile, v-on='on', @click='toggleMarkup({ start: `^` })').mx-0
|
|
|
|
v-icon mdi-format-superscript
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.superscript')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-menu(offset-y, open-on-hover)
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn.wait-p6s(icon, tile, v-on='on').mx-0
|
|
|
|
v-icon mdi-alpha-t-box-outline
|
2019-05-11 05:23:32 +00:00
|
|
|
v-list.py-0
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item(@click='insertBeforeEachLine({ content: `> `})')
|
|
|
|
v-list-item-action
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon mdi-alpha-t-box-outline
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-title {{$t('editor:markup.blockquote')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-divider
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item(@click='insertBeforeEachLine({ content: `> `, after: `{.is-info}`})')
|
|
|
|
v-list-item-action
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon(color='blue') mdi-alpha-i-box-outline
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-title {{$t('editor:markup.blockquoteInfo')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-divider
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item(@click='insertBeforeEachLine({ content: `> `, after: `{.is-success}`})')
|
|
|
|
v-list-item-action
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon(color='success') mdi-alpha-s-box-outline
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-title {{$t('editor:markup.blockquoteSuccess')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-divider
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item(@click='insertBeforeEachLine({ content: `> `, after: `{.is-warning}`})')
|
|
|
|
v-list-item-action
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon(color='warning') mdi-alpha-w-box-outline
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-title {{$t('editor:markup.blockquoteWarning')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-divider
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item(@click='insertBeforeEachLine({ content: `> `, after: `{.is-danger}`})')
|
|
|
|
v-list-item-action
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon(color='error') mdi-alpha-e-box-outline
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-title {{$t('editor:markup.blockquoteError')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-divider
|
|
|
|
v-tooltip(bottom, color='primary')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn.wait-p7s(icon, tile, v-on='on', @click='insertBeforeEachLine({ content: `- `})').mx-0
|
|
|
|
v-icon mdi-format-list-bulleted
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.unorderedList')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-tooltip(bottom, color='primary')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn.wait-p8s(icon, tile, v-on='on', @click='insertBeforeEachLine({ content: `1. `})').mx-0
|
|
|
|
v-icon mdi-format-list-numbered
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.orderedList')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-tooltip(bottom, color='primary')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn.wait-p9s(icon, tile, v-on='on', @click='toggleMarkup({ start: "`" })').mx-0
|
|
|
|
v-icon mdi-code-tags
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.inlineCode')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-tooltip(bottom, color='primary')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn.wait-p10s(icon, tile, v-on='on', @click='toggleMarkup({ start: `<kbd>`, end: `</kbd>` })').mx-0
|
|
|
|
v-icon mdi-keyboard-variant
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.keyboardKey')}}
|
2019-05-11 05:23:32 +00:00
|
|
|
v-tooltip(bottom, color='primary')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn.wait-p11s(icon, tile, v-on='on', @click='insertAfter({ content: `---`, newLine: true })').mx-0
|
|
|
|
v-icon mdi-minus
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.horizontalBar')}}
|
2019-06-15 21:05:56 +00:00
|
|
|
template(v-if='$vuetify.breakpoint.mdAndUp')
|
|
|
|
v-spacer
|
2020-06-22 22:10:48 +00:00
|
|
|
v-tooltip(bottom, color='primary', v-if='previewShown')
|
|
|
|
template(v-slot:activator='{ on }')
|
|
|
|
v-btn.animated.fadeIn.wait-p1s(icon, tile, v-on='on', @click='spellModeActive = !spellModeActive').mx-0
|
|
|
|
v-icon(:color='spellModeActive ? `amber` : `white`') mdi-spellcheck
|
|
|
|
span {{$t('editor:markup.toggleSpellcheck')}}
|
2019-06-15 21:05:56 +00:00
|
|
|
v-tooltip(bottom, color='primary')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2020-06-22 22:10:48 +00:00
|
|
|
v-btn.animated.fadeIn.wait-p2s(icon, tile, v-on='on', @click='previewShown = !previewShown').mx-0
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon mdi-book-open-outline
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.togglePreviewPane')}}
|
2019-01-26 01:00:30 +00:00
|
|
|
.editor-markdown-main
|
2019-03-20 04:37:33 +00:00
|
|
|
.editor-markdown-sidebar
|
2019-05-05 05:03:42 +00:00
|
|
|
v-tooltip(right, color='teal')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2020-04-11 04:19:23 +00:00
|
|
|
v-btn.animated.fadeInLeft(icon, tile, v-on='on', dark, @click='insertLink').mx-0
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon mdi-link-plus
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.insertLink')}}
|
2019-05-05 05:03:42 +00:00
|
|
|
v-tooltip(right, color='teal')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2019-08-25 18:23:56 +00:00
|
|
|
v-btn.mt-3.animated.fadeInLeft.wait-p1s(icon, tile, v-on='on', dark, @click='toggleModal(`editorModalMedia`)').mx-0
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon(:color='activeModal === `editorModalMedia` ? `teal` : ``') mdi-folder-multiple-image
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.insertAssets')}}
|
2019-05-05 05:03:42 +00:00
|
|
|
v-tooltip(right, color='teal')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2020-05-23 22:49:10 +00:00
|
|
|
v-btn.mt-3.animated.fadeInLeft.wait-p2s(icon, tile, v-on='on', dark, disabled, @click='toggleModal(`editorModalBlocks`)').mx-0
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon(:color='activeModal === `editorModalBlocks` ? `teal` : ``') mdi-view-dashboard-outline
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.insertBlock')}}
|
2019-05-05 05:03:42 +00:00
|
|
|
v-tooltip(right, color='teal')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2019-08-25 18:23:56 +00:00
|
|
|
v-btn.mt-3.animated.fadeInLeft.wait-p3s(icon, tile, v-on='on', dark, disabled).mx-0
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon mdi-code-braces
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.insertCodeBlock')}}
|
2019-05-05 05:03:42 +00:00
|
|
|
v-tooltip(right, color='teal')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2019-08-25 18:23:56 +00:00
|
|
|
v-btn.mt-3.animated.fadeInLeft.wait-p4s(icon, tile, v-on='on', dark, disabled).mx-0
|
2020-04-11 04:19:23 +00:00
|
|
|
v-icon mdi-movie
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.insertVideoAudio')}}
|
2019-05-05 05:03:42 +00:00
|
|
|
v-tooltip(right, color='teal')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2020-07-11 03:11:28 +00:00
|
|
|
v-btn.mt-3.animated.fadeInLeft.wait-p5s(icon, tile, v-on='on', dark, @click='toggleModal(`editorModalDrawio`)').mx-0
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon mdi-chart-multiline
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.insertDiagram')}}
|
2019-05-05 05:03:42 +00:00
|
|
|
v-tooltip(right, color='teal')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2019-08-25 18:23:56 +00:00
|
|
|
v-btn.mt-3.animated.fadeInLeft.wait-p6s(icon, tile, v-on='on', dark, disabled).mx-0
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon mdi-function-variant
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.insertMathExpression')}}
|
2019-05-05 05:03:42 +00:00
|
|
|
v-tooltip(right, color='teal')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2019-08-25 18:23:56 +00:00
|
|
|
v-btn.mt-3.animated.fadeInLeft.wait-p7s(icon, tile, v-on='on', dark, disabled).mx-0
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon mdi-table-plus
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.tableHelper')}}
|
2019-05-18 06:27:30 +00:00
|
|
|
template(v-if='$vuetify.breakpoint.mdAndUp')
|
|
|
|
v-spacer
|
|
|
|
v-tooltip(right, color='teal')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2019-08-25 18:23:56 +00:00
|
|
|
v-btn.mt-3.animated.fadeInLeft.wait-p8s(icon, tile, v-on='on', dark, @click='toggleFullscreen').mx-0
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon mdi-arrow-expand-all
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.distractionFreeMode')}}
|
2019-05-18 06:27:30 +00:00
|
|
|
v-tooltip(right, color='teal')
|
2019-08-04 02:51:29 +00:00
|
|
|
template(v-slot:activator='{ on }')
|
2019-08-25 18:23:56 +00:00
|
|
|
v-btn.mt-3.animated.fadeInLeft.wait-p9s(icon, tile, v-on='on', dark, @click='toggleHelp').mx-0
|
2019-08-04 02:51:29 +00:00
|
|
|
v-icon(:color='helpShown ? `teal` : ``') mdi-help-circle
|
2019-06-16 01:45:53 +00:00
|
|
|
span {{$t('editor:markup.markdownFormattingHelp')}}
|
2019-01-26 01:00:30 +00:00
|
|
|
.editor-markdown-editor
|
2019-09-01 02:10:58 +00:00
|
|
|
textarea(ref='cm')
|
2019-01-26 01:00:30 +00:00
|
|
|
transition(name='editor-markdown-preview')
|
|
|
|
.editor-markdown-preview(v-if='previewShown')
|
2019-08-31 15:14:15 +00:00
|
|
|
.editor-markdown-preview-content.contents(ref='editorPreviewContainer')
|
2020-06-22 22:10:48 +00:00
|
|
|
div(
|
|
|
|
ref='editorPreview'
|
|
|
|
v-html='previewHTML'
|
|
|
|
:spellcheck='spellModeActive'
|
|
|
|
:contenteditable='spellModeActive'
|
|
|
|
@blur='spellModeActive = false'
|
|
|
|
)
|
2018-09-16 15:59:22 +00:00
|
|
|
|
2019-03-20 04:37:33 +00:00
|
|
|
v-system-bar.editor-markdown-sysbar(dark, status, color='grey darken-3')
|
|
|
|
.caption.editor-markdown-sysbar-locale {{locale.toUpperCase()}}
|
|
|
|
.caption.px-3 /{{path}}
|
2019-05-18 06:27:30 +00:00
|
|
|
template(v-if='$vuetify.breakpoint.mdAndUp')
|
|
|
|
v-spacer
|
|
|
|
.caption Markdown
|
|
|
|
v-spacer
|
|
|
|
.caption Ln {{cursorPos.line + 1}}, Col {{cursorPos.ch + 1}}
|
2019-05-06 01:21:27 +00:00
|
|
|
|
|
|
|
markdown-help(v-if='helpShown')
|
2020-04-11 04:19:23 +00:00
|
|
|
page-selector(mode='select', v-model='insertLinkDialog', :open-handler='insertLinkHandler', :path='path', :locale='locale')
|
2018-09-16 15:59:22 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import _ from 'lodash'
|
2019-03-20 04:37:33 +00:00
|
|
|
import { get, sync } from 'vuex-pathify'
|
2019-05-06 01:21:27 +00:00
|
|
|
import markdownHelp from './markdown/help.vue'
|
2020-04-11 04:19:23 +00:00
|
|
|
import gql from 'graphql-tag'
|
2020-05-01 04:55:31 +00:00
|
|
|
import DOMPurify from 'dompurify'
|
2018-09-16 15:59:22 +00:00
|
|
|
|
2020-04-11 04:19:23 +00:00
|
|
|
/* global siteConfig, siteLangs */
|
2019-12-22 23:49:17 +00:00
|
|
|
|
2018-09-16 15:59:22 +00:00
|
|
|
// ========================================
|
|
|
|
// IMPORTS
|
|
|
|
// ========================================
|
|
|
|
|
|
|
|
// Code Mirror
|
2019-09-01 02:10:58 +00:00
|
|
|
import CodeMirror from 'codemirror'
|
2018-09-16 15:59:22 +00:00
|
|
|
import 'codemirror/lib/codemirror.css'
|
|
|
|
|
|
|
|
// Language
|
|
|
|
import 'codemirror/mode/markdown/markdown.js'
|
|
|
|
|
|
|
|
// Addons
|
|
|
|
import 'codemirror/addon/selection/active-line.js'
|
|
|
|
import 'codemirror/addon/display/fullscreen.js'
|
|
|
|
import 'codemirror/addon/display/fullscreen.css'
|
|
|
|
import 'codemirror/addon/selection/mark-selection.js'
|
|
|
|
import 'codemirror/addon/search/searchcursor.js'
|
2020-04-11 04:19:23 +00:00
|
|
|
import 'codemirror/addon/hint/show-hint.js'
|
2020-07-12 18:32:53 +00:00
|
|
|
import 'codemirror/addon/fold/foldcode.js'
|
|
|
|
import 'codemirror/addon/fold/foldgutter.js'
|
|
|
|
import 'codemirror/addon/fold/foldgutter.css'
|
|
|
|
import './markdown/fold'
|
2018-09-16 15:59:22 +00:00
|
|
|
|
|
|
|
// Markdown-it
|
|
|
|
import MarkdownIt from 'markdown-it'
|
2018-11-24 02:10:24 +00:00
|
|
|
import mdAttrs from 'markdown-it-attrs'
|
2018-09-16 15:59:22 +00:00
|
|
|
import mdEmoji from 'markdown-it-emoji'
|
|
|
|
import mdTaskLists from 'markdown-it-task-lists'
|
|
|
|
import mdExpandTabs from 'markdown-it-expand-tabs'
|
|
|
|
import mdAbbr from 'markdown-it-abbr'
|
|
|
|
import mdSup from 'markdown-it-sup'
|
|
|
|
import mdSub from 'markdown-it-sub'
|
|
|
|
import mdMark from 'markdown-it-mark'
|
2020-07-03 21:46:07 +00:00
|
|
|
import mdMultiTable from 'markdown-it-multimd-table'
|
2020-03-28 18:28:08 +00:00
|
|
|
import mdFootnote from 'markdown-it-footnote'
|
2018-09-16 15:59:22 +00:00
|
|
|
import mdImsize from 'markdown-it-imsize'
|
2020-03-06 19:31:05 +00:00
|
|
|
import katex from 'katex'
|
2020-06-18 22:37:24 +00:00
|
|
|
import underline from '../../libs/markdown-it-underline'
|
2020-03-29 21:06:32 +00:00
|
|
|
import 'katex/dist/contrib/mhchem'
|
2020-03-16 02:34:42 +00:00
|
|
|
import twemoji from 'twemoji'
|
2020-05-09 02:51:32 +00:00
|
|
|
import plantuml from './markdown/plantuml'
|
2018-09-16 15:59:22 +00:00
|
|
|
|
|
|
|
// Prism (Syntax Highlighting)
|
2019-07-13 03:56:44 +00:00
|
|
|
import Prism from 'prismjs'
|
2018-09-16 15:59:22 +00:00
|
|
|
|
2020-03-30 00:54:39 +00:00
|
|
|
// Mermaid
|
|
|
|
import mermaid from 'mermaid'
|
|
|
|
|
2020-03-06 19:31:05 +00:00
|
|
|
// Helpers
|
|
|
|
import katexHelper from './common/katex'
|
2020-07-03 23:36:33 +00:00
|
|
|
import tabsetHelper from './markdown/tabset'
|
2020-03-06 19:31:05 +00:00
|
|
|
|
2018-09-16 15:59:22 +00:00
|
|
|
// ========================================
|
|
|
|
// INIT
|
|
|
|
// ========================================
|
|
|
|
|
|
|
|
// Platform detection
|
|
|
|
const CtrlKey = /Mac/.test(navigator.platform) ? 'Cmd' : 'Ctrl'
|
|
|
|
|
2019-11-23 21:26:24 +00:00
|
|
|
// Prism Config
|
2020-05-15 21:05:11 +00:00
|
|
|
Prism.plugins.autoloader.languages_path = '/_assets/js/prism/'
|
2019-11-23 21:26:24 +00:00
|
|
|
Prism.plugins.NormalizeWhitespace.setDefaults({
|
|
|
|
'remove-trailing': true,
|
|
|
|
'remove-indent': true,
|
|
|
|
'left-trim': true,
|
|
|
|
'right-trim': true,
|
|
|
|
'remove-initial-line-feed': true,
|
|
|
|
'tabs-to-spaces': 2
|
|
|
|
})
|
|
|
|
|
2018-09-16 15:59:22 +00:00
|
|
|
// Markdown Instance
|
|
|
|
const md = new MarkdownIt({
|
|
|
|
html: true,
|
|
|
|
breaks: true,
|
|
|
|
linkify: true,
|
|
|
|
typography: true,
|
|
|
|
highlight(str, lang) {
|
2020-07-12 17:24:10 +00:00
|
|
|
if (lang === 'diagram') {
|
|
|
|
return `<pre class="diagram">` + Buffer.from(str, 'base64').toString() + `</pre>`
|
|
|
|
} else if (['mermaid', 'plantuml'].includes(lang)) {
|
2020-05-09 02:51:32 +00:00
|
|
|
return `<pre class="codeblock-${lang}"><code>${_.escape(str)}</code></pre>`
|
|
|
|
} else {
|
|
|
|
return `<pre class="line-numbers"><code class="language-${lang}">${_.escape(str)}</code></pre>`
|
|
|
|
}
|
2018-09-16 15:59:22 +00:00
|
|
|
}
|
|
|
|
})
|
2019-11-22 15:52:19 +00:00
|
|
|
.use(mdAttrs, {
|
|
|
|
allowedAttributes: ['id', 'class', 'target']
|
|
|
|
})
|
2020-06-18 22:37:24 +00:00
|
|
|
.use(underline)
|
2018-09-16 15:59:22 +00:00
|
|
|
.use(mdEmoji)
|
2018-11-24 02:10:24 +00:00
|
|
|
.use(mdTaskLists, {label: true, labelAfter: true})
|
2018-09-16 15:59:22 +00:00
|
|
|
.use(mdExpandTabs)
|
|
|
|
.use(mdAbbr)
|
|
|
|
.use(mdSup)
|
|
|
|
.use(mdSub)
|
2020-07-03 21:46:07 +00:00
|
|
|
.use(mdMultiTable, {multiline: true, rowspan: true, headerless: true})
|
2018-09-16 15:59:22 +00:00
|
|
|
.use(mdMark)
|
2020-03-28 18:28:08 +00:00
|
|
|
.use(mdFootnote)
|
2018-09-16 15:59:22 +00:00
|
|
|
.use(mdImsize)
|
|
|
|
|
2020-09-12 18:05:24 +00:00
|
|
|
// DOMPurify fix for draw.io
|
|
|
|
DOMPurify.addHook('uponSanitizeElement', (elm) => {
|
|
|
|
if (elm.querySelectorAll) {
|
|
|
|
const breaks = elm.querySelectorAll('foreignObject br, foreignObject p')
|
|
|
|
if (breaks && breaks.length) {
|
|
|
|
for (let i = 0; i < breaks.length; i++) {
|
|
|
|
breaks[i].parentNode.replaceChild(
|
|
|
|
document.createElement('div'),
|
|
|
|
breaks[i]
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-09-16 15:59:22 +00:00
|
|
|
// ========================================
|
|
|
|
// HELPER FUNCTIONS
|
|
|
|
// ========================================
|
|
|
|
|
|
|
|
// Inject line numbers for preview scroll sync
|
|
|
|
let linesMap = []
|
|
|
|
function injectLineNumbers (tokens, idx, options, env, slf) {
|
|
|
|
let line
|
|
|
|
if (tokens[idx].map && tokens[idx].level === 0) {
|
|
|
|
line = tokens[idx].map[0]
|
|
|
|
tokens[idx].attrJoin('class', 'line')
|
|
|
|
tokens[idx].attrSet('data-line', String(line))
|
|
|
|
linesMap.push(line)
|
|
|
|
}
|
|
|
|
return slf.renderToken(tokens, idx, options, env, slf)
|
|
|
|
}
|
|
|
|
md.renderer.rules.paragraph_open = injectLineNumbers
|
|
|
|
md.renderer.rules.heading_open = injectLineNumbers
|
2019-09-01 02:10:58 +00:00
|
|
|
md.renderer.rules.blockquote_open = injectLineNumbers
|
2018-09-16 15:59:22 +00:00
|
|
|
|
2020-05-09 02:51:32 +00:00
|
|
|
// ========================================
|
|
|
|
// PLANTUML
|
|
|
|
// ========================================
|
|
|
|
|
|
|
|
// TODO: Use same options as defined in backend
|
|
|
|
plantuml.init(md, {})
|
|
|
|
|
2020-03-06 19:31:05 +00:00
|
|
|
// ========================================
|
|
|
|
// KATEX
|
|
|
|
// ========================================
|
|
|
|
|
|
|
|
md.inline.ruler.after('escape', 'katex_inline', katexHelper.katexInline)
|
|
|
|
md.renderer.rules.katex_inline = (tokens, idx) => {
|
|
|
|
try {
|
|
|
|
return katex.renderToString(tokens[idx].content, {
|
|
|
|
displayMode: false
|
|
|
|
})
|
|
|
|
} catch (err) {
|
|
|
|
console.warn(err)
|
|
|
|
return tokens[idx].content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
md.block.ruler.after('blockquote', 'katex_block', katexHelper.katexBlock, {
|
|
|
|
alt: [ 'paragraph', 'reference', 'blockquote', 'list' ]
|
|
|
|
})
|
|
|
|
md.renderer.rules.katex_block = (tokens, idx) => {
|
|
|
|
try {
|
|
|
|
return `<p>` + katex.renderToString(tokens[idx].content, {
|
|
|
|
displayMode: true
|
|
|
|
}) + `</p>`
|
|
|
|
} catch (err) {
|
|
|
|
console.warn(err)
|
|
|
|
return tokens[idx].content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 02:34:42 +00:00
|
|
|
// ========================================
|
|
|
|
// TWEMOJI
|
|
|
|
// ========================================
|
|
|
|
|
|
|
|
md.renderer.rules.emoji = (token, idx) => {
|
|
|
|
return twemoji.parse(token[idx].content, {
|
|
|
|
callback (icon, opts) {
|
2020-05-17 02:46:05 +00:00
|
|
|
return `/_assets/svg/twemoji/${icon}.svg`
|
2020-03-16 02:34:42 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-16 15:59:22 +00:00
|
|
|
// ========================================
|
|
|
|
// Vue Component
|
|
|
|
// ========================================
|
|
|
|
|
2020-03-30 00:54:39 +00:00
|
|
|
let mermaidId = 0
|
|
|
|
|
2018-09-16 15:59:22 +00:00
|
|
|
export default {
|
|
|
|
components: {
|
2019-05-06 01:21:27 +00:00
|
|
|
markdownHelp
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
save: {
|
2019-06-16 01:45:53 +00:00
|
|
|
type: Function,
|
|
|
|
default: () => {}
|
2019-05-06 01:21:27 +00:00
|
|
|
}
|
2018-09-16 15:59:22 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fabInsertMenu: false,
|
2019-09-01 02:10:58 +00:00
|
|
|
cm: null,
|
2019-05-06 01:21:27 +00:00
|
|
|
cursorPos: { ch: 0, line: 1 },
|
2018-09-16 15:59:22 +00:00
|
|
|
previewShown: true,
|
2019-05-06 01:21:27 +00:00
|
|
|
previewHTML: '',
|
2020-04-11 04:19:23 +00:00
|
|
|
helpShown: false,
|
2020-06-22 22:10:48 +00:00
|
|
|
spellModeActive: false,
|
2020-04-11 04:19:23 +00:00
|
|
|
insertLinkDialog: false
|
2018-09-16 15:59:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isMobile() {
|
|
|
|
return this.$vuetify.breakpoint.smAndDown
|
2019-03-20 04:37:33 +00:00
|
|
|
},
|
2019-05-11 05:23:32 +00:00
|
|
|
isModalShown() {
|
|
|
|
return this.helpShown || this.activeModal !== ''
|
|
|
|
},
|
2019-03-20 04:37:33 +00:00
|
|
|
locale: get('page/locale'),
|
|
|
|
path: get('page/path'),
|
2019-09-08 16:01:17 +00:00
|
|
|
mode: get('editor/mode'),
|
2019-03-20 04:37:33 +00:00
|
|
|
activeModal: sync('editor/activeModal')
|
2018-09-16 15:59:22 +00:00
|
|
|
},
|
2020-03-15 23:31:59 +00:00
|
|
|
watch: {
|
|
|
|
previewShown (newValue, oldValue) {
|
|
|
|
if (newValue && !oldValue) {
|
|
|
|
this.$nextTick(() => {
|
2020-03-30 00:54:39 +00:00
|
|
|
this.renderMermaidDiagrams()
|
2020-03-15 23:31:59 +00:00
|
|
|
Prism.highlightAllUnder(this.$refs.editorPreview)
|
|
|
|
Array.from(this.$refs.editorPreview.querySelectorAll('pre.line-numbers')).forEach(pre => pre.classList.add('prismjs'))
|
|
|
|
})
|
|
|
|
}
|
2020-06-22 22:10:48 +00:00
|
|
|
},
|
|
|
|
spellModeActive (newValue, oldValue) {
|
|
|
|
if (newValue) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.editorPreview.focus()
|
|
|
|
})
|
|
|
|
}
|
2020-03-15 23:31:59 +00:00
|
|
|
}
|
|
|
|
},
|
2018-09-16 15:59:22 +00:00
|
|
|
methods: {
|
2019-03-20 04:37:33 +00:00
|
|
|
toggleModal(key) {
|
|
|
|
this.activeModal = (this.activeModal === key) ? '' : key
|
2019-05-11 05:23:32 +00:00
|
|
|
this.helpShown = false
|
|
|
|
},
|
|
|
|
closeAllModal() {
|
|
|
|
this.activeModal = ''
|
|
|
|
this.helpShown = false
|
2019-03-20 04:37:33 +00:00
|
|
|
},
|
2018-09-16 15:59:22 +00:00
|
|
|
onCmInput: _.debounce(function (newContent) {
|
2020-07-12 23:20:10 +00:00
|
|
|
this.processContent(newContent)
|
|
|
|
}, 600),
|
2019-06-15 21:05:56 +00:00
|
|
|
onCmPaste (cm, ev) {
|
2019-09-08 16:39:05 +00:00
|
|
|
// const clipItems = (ev.clipboardData || ev.originalEvent.clipboardData).items
|
|
|
|
// for (let clipItem of clipItems) {
|
|
|
|
// if (_.startsWith(clipItem.type, 'image/')) {
|
|
|
|
// const file = clipItem.getAsFile()
|
|
|
|
// const reader = new FileReader()
|
|
|
|
// reader.onload = evt => {
|
|
|
|
// this.$store.commit(`loadingStart`, 'editor-paste-image')
|
|
|
|
// this.insertAfter({
|
|
|
|
// content: `![${file.name}](${evt.target.result})`,
|
|
|
|
// newLine: true
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// reader.readAsDataURL(file)
|
|
|
|
// }
|
|
|
|
// }
|
2019-06-15 21:05:56 +00:00
|
|
|
},
|
2020-07-12 23:20:10 +00:00
|
|
|
processContent (newContent) {
|
|
|
|
linesMap = []
|
|
|
|
// this.$store.set('editor/content', newContent)
|
|
|
|
this.processMarkers(this.cm.firstLine(), this.cm.lastLine())
|
2020-09-12 18:05:24 +00:00
|
|
|
this.previewHTML = DOMPurify.sanitize(md.render(newContent), {
|
|
|
|
ADD_TAGS: ['foreignObject']
|
|
|
|
})
|
2020-07-12 23:20:10 +00:00
|
|
|
this.$nextTick(() => {
|
|
|
|
tabsetHelper.format()
|
|
|
|
this.renderMermaidDiagrams()
|
|
|
|
Prism.highlightAllUnder(this.$refs.editorPreview)
|
|
|
|
Array.from(this.$refs.editorPreview.querySelectorAll('pre.line-numbers')).forEach(pre => pre.classList.add('prismjs'))
|
|
|
|
this.scrollSync(this.cm)
|
|
|
|
})
|
|
|
|
},
|
2018-09-16 15:59:22 +00:00
|
|
|
/**
|
2019-05-06 01:21:27 +00:00
|
|
|
* Update cursor state
|
2018-09-16 15:59:22 +00:00
|
|
|
*/
|
2019-05-06 01:21:27 +00:00
|
|
|
positionSync(cm) {
|
|
|
|
this.cursorPos = cm.getCursor('head')
|
2018-09-16 15:59:22 +00:00
|
|
|
},
|
2019-05-06 01:21:27 +00:00
|
|
|
/**
|
|
|
|
* Wrap selection with start / end tags
|
|
|
|
*/
|
2019-05-05 05:03:42 +00:00
|
|
|
toggleMarkup({ start, end }) {
|
|
|
|
if (!end) { end = start }
|
|
|
|
if (!this.cm.doc.somethingSelected()) {
|
|
|
|
return this.$store.commit('showNotification', {
|
2019-06-16 01:45:53 +00:00
|
|
|
message: this.$t('editor:markup.noSelectionError'),
|
2019-05-05 05:03:42 +00:00
|
|
|
style: 'warning',
|
|
|
|
icon: 'warning'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.cm.doc.replaceSelections(this.cm.doc.getSelections().map(s => start + s + end))
|
|
|
|
},
|
2019-05-06 01:21:27 +00:00
|
|
|
/**
|
|
|
|
* Set current line as header
|
|
|
|
*/
|
2019-05-05 05:03:42 +00:00
|
|
|
setHeaderLine(lvl) {
|
|
|
|
const curLine = this.cm.doc.getCursor('head').line
|
|
|
|
let lineContent = this.cm.doc.getLine(curLine)
|
|
|
|
const lineLength = lineContent.length
|
|
|
|
if (_.startsWith(lineContent, '#')) {
|
|
|
|
lineContent = lineContent.replace(/^(#+ )/, '')
|
|
|
|
}
|
|
|
|
lineContent = _.times(lvl, n => '#').join('') + ` ` + lineContent
|
|
|
|
this.cm.doc.replaceRange(lineContent, { line: curLine, ch: 0 }, { line: curLine, ch: lineLength })
|
|
|
|
},
|
2019-05-06 01:21:27 +00:00
|
|
|
/**
|
|
|
|
* Get the header lever of the current line
|
|
|
|
*/
|
|
|
|
getHeaderLevel(cm) {
|
|
|
|
const curLine = this.cm.doc.getCursor('head').line
|
|
|
|
let lineContent = this.cm.doc.getLine(curLine)
|
|
|
|
let lvl = 0
|
|
|
|
|
|
|
|
const result = lineContent.match(/^(#+) /)
|
|
|
|
if (result) {
|
|
|
|
lvl = _.get(result, '[1]', '').length
|
|
|
|
}
|
|
|
|
return lvl
|
|
|
|
},
|
2019-05-19 18:46:08 +00:00
|
|
|
/**
|
|
|
|
* Insert content at cursor
|
|
|
|
*/
|
|
|
|
insertAtCursor({ content }) {
|
|
|
|
const cursor = this.cm.doc.getCursor('head')
|
|
|
|
this.cm.doc.replaceRange(content, cursor)
|
|
|
|
},
|
2019-05-06 01:21:27 +00:00
|
|
|
/**
|
|
|
|
* Insert content after current line
|
|
|
|
*/
|
2019-05-05 05:03:42 +00:00
|
|
|
insertAfter({ content, newLine }) {
|
|
|
|
const curLine = this.cm.doc.getCursor('to').line
|
|
|
|
const lineLength = this.cm.doc.getLine(curLine).length
|
|
|
|
this.cm.doc.replaceRange(newLine ? `\n${content}\n` : content, { line: curLine, ch: lineLength + 1 })
|
|
|
|
},
|
2019-05-06 01:21:27 +00:00
|
|
|
/**
|
|
|
|
* Insert content before current line
|
|
|
|
*/
|
2019-05-05 05:03:42 +00:00
|
|
|
insertBeforeEachLine({ content, after }) {
|
|
|
|
let lines = []
|
|
|
|
if (!this.cm.doc.somethingSelected()) {
|
|
|
|
lines.push(this.cm.doc.getCursor('head').line)
|
|
|
|
} else {
|
|
|
|
lines = _.flatten(this.cm.doc.listSelections().map(sl => {
|
|
|
|
const range = Math.abs(sl.anchor.line - sl.head.line) + 1
|
|
|
|
const lowestLine = (sl.anchor.line > sl.head.line) ? sl.head.line : sl.anchor.line
|
|
|
|
return _.times(range, l => l + lowestLine)
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
lines.forEach(ln => {
|
|
|
|
let lineContent = this.cm.doc.getLine(ln)
|
|
|
|
const lineLength = lineContent.length
|
|
|
|
if (_.startsWith(lineContent, content)) {
|
|
|
|
lineContent = lineContent.substring(content.length)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.cm.doc.replaceRange(content + lineContent, { line: ln, ch: 0 }, { line: ln, ch: lineLength })
|
|
|
|
})
|
|
|
|
if (after) {
|
|
|
|
const lastLine = _.last(lines)
|
|
|
|
this.cm.doc.replaceRange(`\n${after}\n`, { line: lastLine, ch: this.cm.doc.getLine(lastLine).length + 1 })
|
|
|
|
}
|
|
|
|
},
|
2018-09-16 15:59:22 +00:00
|
|
|
/**
|
|
|
|
* Update scroll sync
|
|
|
|
*/
|
|
|
|
scrollSync: _.debounce(function (cm) {
|
|
|
|
if (!this.previewShown || cm.somethingSelected()) { return }
|
|
|
|
let currentLine = cm.getCursor().line
|
|
|
|
if (currentLine < 3) {
|
|
|
|
this.Velocity(this.$refs.editorPreview, 'stop', true)
|
2019-09-01 02:10:58 +00:00
|
|
|
this.Velocity(this.$refs.editorPreview.firstChild, 'scroll', { offset: '-50', duration: 1000, container: this.$refs.editorPreviewContainer })
|
2018-09-16 15:59:22 +00:00
|
|
|
} else {
|
|
|
|
let closestLine = _.findLast(linesMap, n => n <= currentLine)
|
|
|
|
let destElm = this.$refs.editorPreview.querySelector(`[data-line='${closestLine}']`)
|
|
|
|
if (destElm) {
|
|
|
|
this.Velocity(this.$refs.editorPreview, 'stop', true)
|
2019-08-31 15:14:15 +00:00
|
|
|
this.Velocity(destElm, 'scroll', { offset: '-100', duration: 1000, container: this.$refs.editorPreviewContainer })
|
2018-09-16 15:59:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 500),
|
2019-05-06 01:21:27 +00:00
|
|
|
toggleHelp () {
|
|
|
|
this.helpShown = !this.helpShown
|
2019-05-11 05:23:32 +00:00
|
|
|
this.activeModal = ''
|
2019-04-07 16:12:30 +00:00
|
|
|
},
|
|
|
|
toggleFullscreen () {
|
|
|
|
this.cm.setOption('fullScreen', true)
|
2019-09-01 02:10:58 +00:00
|
|
|
},
|
|
|
|
refresh() {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.cm.refresh()
|
|
|
|
})
|
2020-03-30 00:54:39 +00:00
|
|
|
},
|
|
|
|
renderMermaidDiagrams () {
|
2020-05-09 02:51:32 +00:00
|
|
|
document.querySelectorAll('.editor-markdown-preview pre.codeblock-mermaid > code').forEach(elm => {
|
2020-03-30 00:54:39 +00:00
|
|
|
mermaidId++
|
|
|
|
const mermaidDef = elm.innerText
|
|
|
|
const mmElm = document.createElement('div')
|
|
|
|
mmElm.innerHTML = `<div id="mermaid-id-${mermaidId}">${mermaid.render(`mermaid-id-${mermaidId}`, mermaidDef)}</div>`
|
|
|
|
elm.parentElement.replaceWith(mmElm)
|
|
|
|
})
|
2020-04-11 04:19:23 +00:00
|
|
|
},
|
|
|
|
autocomplete (cm, change) {
|
|
|
|
if (cm.getModeAt(cm.getCursor()).name !== 'markdown') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Links
|
|
|
|
if (change.text[0] === '(') {
|
|
|
|
const curLine = cm.getLine(change.from.line).substring(0, change.from.ch)
|
|
|
|
if (curLine[curLine.length - 1] === ']') {
|
|
|
|
cm.showHint({
|
|
|
|
hint: async (cm, options) => {
|
|
|
|
const cur = cm.getCursor()
|
2020-09-19 21:55:38 +00:00
|
|
|
const curLine = cm.getLine(cur.line).substring(0, cur.ch)
|
|
|
|
const queryString = curLine.substring(curLine.lastIndexOf('[')+1,curLine.length-2)
|
2020-04-11 04:19:23 +00:00
|
|
|
const token = cm.getTokenAt(cur)
|
|
|
|
try {
|
|
|
|
const respRaw = await this.$apollo.query({
|
|
|
|
query: gql`
|
|
|
|
query ($query: String!, $locale: String) {
|
|
|
|
pages {
|
|
|
|
search(query:$query, locale:$locale) {
|
|
|
|
results {
|
|
|
|
title
|
|
|
|
path
|
|
|
|
locale
|
|
|
|
}
|
|
|
|
totalHits
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
variables: {
|
2020-09-19 21:55:38 +00:00
|
|
|
query: queryString,
|
2020-04-11 04:19:23 +00:00
|
|
|
locale: this.locale
|
|
|
|
},
|
|
|
|
fetchPolicy: 'cache-first'
|
|
|
|
})
|
|
|
|
const resp = _.get(respRaw, 'data.pages.search', {})
|
|
|
|
if (resp && resp.totalHits > 0) {
|
|
|
|
return {
|
|
|
|
list: resp.results.map(r => ({
|
2020-09-19 21:55:38 +00:00
|
|
|
text: '(' + (siteLangs.length > 0 ? `/${r.locale}/${r.path}` : `/${r.path}`) + ')',
|
2020-04-11 04:19:23 +00:00
|
|
|
displayText: siteLangs.length > 0 ? `/${r.locale}/${r.path} - ${r.title}` : `/${r.path} - ${r.title}`
|
|
|
|
})),
|
|
|
|
from: CodeMirror.Pos(cur.line, token.start),
|
|
|
|
to: CodeMirror.Pos(cur.line, token.end)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (err) {}
|
|
|
|
return {
|
|
|
|
list: [],
|
|
|
|
from: CodeMirror.Pos(cur.line, token.start),
|
|
|
|
to: CodeMirror.Pos(cur.line, token.end)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
insertLink () {
|
|
|
|
this.insertLinkDialog = true
|
|
|
|
},
|
|
|
|
insertLinkHandler ({ locale, path }) {
|
|
|
|
const lastPart = _.last(path.split('/'))
|
|
|
|
this.insertAtCursor({
|
|
|
|
content: siteLangs.length > 0 ? `[${lastPart}](/${locale}/${path})` : `[${lastPart}](/${path})`
|
|
|
|
})
|
2020-07-12 23:20:10 +00:00
|
|
|
},
|
|
|
|
processMarkers (from, to) {
|
|
|
|
let found = null
|
|
|
|
let foundStart = 0
|
|
|
|
this.cm.doc.getAllMarks().forEach(mk => {
|
|
|
|
if (mk.__kind) {
|
|
|
|
mk.clear()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.cm.eachLine(from, to, ln => {
|
|
|
|
const line = ln.lineNo()
|
|
|
|
if (ln.text.startsWith('```diagram')) {
|
|
|
|
found = 'diagram'
|
|
|
|
foundStart = line
|
|
|
|
} else if (ln.text === '```' && found) {
|
|
|
|
switch (found) {
|
2020-07-12 23:32:17 +00:00
|
|
|
// ------------------------------
|
|
|
|
// -> DIAGRAM
|
|
|
|
// ------------------------------
|
2020-07-12 23:20:10 +00:00
|
|
|
case 'diagram': {
|
2020-07-12 23:32:17 +00:00
|
|
|
if (line - foundStart !== 2) {
|
|
|
|
return
|
|
|
|
}
|
2020-07-12 23:20:10 +00:00
|
|
|
this.addMarker({
|
|
|
|
kind: 'diagram',
|
|
|
|
from: { line: foundStart, ch: 3 },
|
|
|
|
to: { line: foundStart, ch: 10 },
|
|
|
|
text: 'Edit Diagram',
|
|
|
|
action: ((start, end) => {
|
|
|
|
return (ev) => {
|
|
|
|
this.cm.doc.setSelection({ line: start, ch: 0 }, { line: end, ch: 3 })
|
2020-07-12 23:32:17 +00:00
|
|
|
try {
|
|
|
|
const raw = this.cm.doc.getLine(end - 1)
|
|
|
|
this.$store.set('editor/activeModalData', Buffer.from(raw, 'base64').toString())
|
|
|
|
this.toggleModal(`editorModalDrawio`)
|
|
|
|
} catch (err) {
|
|
|
|
return this.$store.commit('showNotification', {
|
|
|
|
message: 'Failed to process diagram data.',
|
|
|
|
style: 'warning',
|
|
|
|
icon: 'warning'
|
|
|
|
})
|
|
|
|
}
|
2020-07-12 23:20:10 +00:00
|
|
|
}
|
|
|
|
})(foundStart, line)
|
|
|
|
})
|
|
|
|
if (ln.height > 0) {
|
|
|
|
this.cm.foldCode(foundStart)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
found = null
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
addMarker ({ kind, from, to, text, action }) {
|
|
|
|
const markerElm = document.createElement('span')
|
|
|
|
markerElm.appendChild(document.createTextNode(text))
|
|
|
|
markerElm.className = 'CodeMirror-buttonmarker'
|
|
|
|
markerElm.addEventListener('click', action)
|
|
|
|
this.cm.markText(from, to, { replacedWith: markerElm, __kind: kind })
|
2018-09-16 15:59:22 +00:00
|
|
|
}
|
2019-05-19 18:46:08 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
2019-09-08 16:01:17 +00:00
|
|
|
this.$store.set('editor/editorKey', 'markdown')
|
|
|
|
|
2020-03-01 23:22:26 +00:00
|
|
|
if (this.mode === 'create' && !this.$store.get('editor/content')) {
|
2019-09-08 16:01:17 +00:00
|
|
|
this.$store.set('editor/content', '# Header\nYour content here')
|
|
|
|
}
|
|
|
|
|
2020-03-30 00:54:39 +00:00
|
|
|
// Initialize Mermaid API
|
|
|
|
mermaid.initialize({
|
|
|
|
startOnLoad: false,
|
|
|
|
theme: this.$vuetify.theme.dark ? `dark` : `default`
|
|
|
|
})
|
|
|
|
|
2019-09-01 02:10:58 +00:00
|
|
|
// Initialize CodeMirror
|
|
|
|
|
|
|
|
this.cm = CodeMirror.fromTextArea(this.$refs.cm, {
|
|
|
|
tabSize: 2,
|
|
|
|
mode: 'text/markdown',
|
|
|
|
theme: 'wikijs-dark',
|
|
|
|
lineNumbers: true,
|
|
|
|
lineWrapping: true,
|
|
|
|
line: true,
|
|
|
|
styleActiveLine: true,
|
|
|
|
highlightSelectionMatches: {
|
|
|
|
annotateScrollbar: true
|
|
|
|
},
|
|
|
|
viewportMargin: 50,
|
|
|
|
inputStyle: 'contenteditable',
|
2019-12-22 23:49:17 +00:00
|
|
|
allowDropFileTypes: ['image/jpg', 'image/png', 'image/svg', 'image/jpeg', 'image/gif'],
|
2020-07-12 18:32:53 +00:00
|
|
|
direction: siteConfig.rtl ? 'rtl' : 'ltr',
|
|
|
|
foldGutter: true,
|
|
|
|
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter']
|
2019-09-01 02:10:58 +00:00
|
|
|
})
|
|
|
|
this.cm.setValue(this.$store.get('editor/content'))
|
|
|
|
this.cm.on('change', c => {
|
|
|
|
this.$store.set('editor/content', c.getValue())
|
|
|
|
this.onCmInput(this.$store.get('editor/content'))
|
|
|
|
})
|
|
|
|
if (this.$vuetify.breakpoint.mdAndUp) {
|
|
|
|
this.cm.setSize(null, 'calc(100vh - 112px - 24px)')
|
|
|
|
} else {
|
|
|
|
this.cm.setSize(null, 'calc(100vh - 112px - 16px)')
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set Keybindings
|
|
|
|
|
|
|
|
const keyBindings = {
|
|
|
|
'F11' (c) {
|
|
|
|
c.setOption('fullScreen', !c.getOption('fullScreen'))
|
|
|
|
},
|
|
|
|
'Esc' (c) {
|
|
|
|
if (c.getOption('fullScreen')) c.setOption('fullScreen', false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_.set(keyBindings, `${CtrlKey}-S`, c => {
|
|
|
|
this.save()
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
_.set(keyBindings, `${CtrlKey}-B`, c => {
|
|
|
|
this.toggleMarkup({ start: `**` })
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
_.set(keyBindings, `${CtrlKey}-I`, c => {
|
|
|
|
this.toggleMarkup({ start: `*` })
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
_.set(keyBindings, `${CtrlKey}-Alt-Right`, c => {
|
|
|
|
let lvl = this.getHeaderLevel(c)
|
|
|
|
if (lvl >= 6) { lvl = 5 }
|
|
|
|
this.setHeaderLine(lvl + 1)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
_.set(keyBindings, `${CtrlKey}-Alt-Left`, c => {
|
|
|
|
let lvl = this.getHeaderLevel(c)
|
|
|
|
if (lvl <= 1) { lvl = 2 }
|
|
|
|
this.setHeaderLine(lvl - 1)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
this.cm.setOption('extraKeys', keyBindings)
|
|
|
|
|
2020-04-11 04:19:23 +00:00
|
|
|
this.cm.on('inputRead', this.autocomplete)
|
|
|
|
|
2019-09-01 02:10:58 +00:00
|
|
|
// Handle cursor movement
|
|
|
|
|
|
|
|
this.cm.on('cursorActivity', c => {
|
|
|
|
this.positionSync(c)
|
|
|
|
this.scrollSync(c)
|
|
|
|
})
|
|
|
|
|
|
|
|
// Handle special paste
|
|
|
|
|
|
|
|
this.cm.on('paste', this.onCmPaste)
|
|
|
|
|
|
|
|
// Render initial preview
|
|
|
|
|
2020-07-12 23:20:10 +00:00
|
|
|
this.processContent(this.$store.get('editor/content'))
|
2019-09-01 02:10:58 +00:00
|
|
|
this.refresh()
|
|
|
|
|
2019-05-19 18:46:08 +00:00
|
|
|
this.$root.$on('editorInsert', opts => {
|
|
|
|
switch (opts.kind) {
|
|
|
|
case 'IMAGE':
|
2019-05-21 20:45:27 +00:00
|
|
|
let img = `![${opts.text}](${opts.path})`
|
|
|
|
if (opts.align && opts.align !== '') {
|
|
|
|
img += `{.align-${opts.align}}`
|
|
|
|
}
|
2019-05-19 18:46:08 +00:00
|
|
|
this.insertAtCursor({
|
2019-05-21 20:45:27 +00:00
|
|
|
content: img
|
2019-05-19 18:46:08 +00:00
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'BINARY':
|
|
|
|
this.insertAtCursor({
|
|
|
|
content: `[${opts.text}](${opts.path})`
|
|
|
|
})
|
|
|
|
break
|
2020-07-12 17:24:10 +00:00
|
|
|
case 'DIAGRAM':
|
2020-07-12 23:20:10 +00:00
|
|
|
const selStartLine = this.cm.getCursor('from').line
|
|
|
|
const selEndLine = this.cm.getCursor('to').line + 1
|
|
|
|
this.cm.doc.replaceSelection('```diagram\n' + opts.text + '\n```\n', 'start')
|
|
|
|
this.processMarkers(selStartLine, selEndLine)
|
2020-07-12 17:24:10 +00:00
|
|
|
break
|
2019-05-19 18:46:08 +00:00
|
|
|
}
|
|
|
|
})
|
2020-03-21 23:18:08 +00:00
|
|
|
|
|
|
|
// Handle save conflict
|
|
|
|
this.$root.$on('saveConflict', () => {
|
|
|
|
this.toggleModal(`editorModalConflict`)
|
|
|
|
})
|
|
|
|
this.$root.$on('overwriteEditorContent', () => {
|
|
|
|
this.cm.setValue(this.$store.get('editor/content'))
|
|
|
|
})
|
2019-05-19 18:46:08 +00:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$root.$off('editorInsert')
|
2018-09-16 15:59:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang='scss'>
|
2019-03-20 04:37:33 +00:00
|
|
|
|
|
|
|
$editor-height: calc(100vh - 112px - 24px);
|
2019-05-18 06:27:30 +00:00
|
|
|
$editor-height-mobile: calc(100vh - 112px - 16px);
|
2019-03-20 04:37:33 +00:00
|
|
|
|
2019-01-26 01:00:30 +00:00
|
|
|
.editor-markdown {
|
2018-09-16 15:59:22 +00:00
|
|
|
&-main {
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-editor {
|
|
|
|
background-color: darken(mc('grey', '900'), 4.5%);
|
|
|
|
flex: 1 1 50%;
|
|
|
|
display: block;
|
2019-03-20 04:37:33 +00:00
|
|
|
height: $editor-height;
|
2018-09-16 15:59:22 +00:00
|
|
|
position: relative;
|
|
|
|
|
2019-05-18 06:27:30 +00:00
|
|
|
@include until($tablet) {
|
|
|
|
height: $editor-height-mobile;
|
|
|
|
}
|
2018-09-16 15:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
&-preview {
|
|
|
|
flex: 1 1 50%;
|
|
|
|
background-color: mc('grey', '100');
|
|
|
|
position: relative;
|
2019-03-20 04:37:33 +00:00
|
|
|
height: $editor-height;
|
2018-09-16 15:59:22 +00:00
|
|
|
overflow: hidden;
|
2019-09-29 02:19:33 +00:00
|
|
|
padding: 1rem;
|
2018-09-16 15:59:22 +00:00
|
|
|
|
2018-12-02 04:03:14 +00:00
|
|
|
@at-root .theme--dark & {
|
|
|
|
background-color: mc('grey', '900');
|
|
|
|
}
|
|
|
|
|
2018-09-16 15:59:22 +00:00
|
|
|
@include until($tablet) {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-enter-active, &-leave-active {
|
|
|
|
transition: max-width .5s ease;
|
|
|
|
max-width: 50vw;
|
|
|
|
|
|
|
|
.editor-code-preview-content {
|
|
|
|
width: 50vw;
|
|
|
|
overflow:hidden;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
&-enter, &-leave-to {
|
|
|
|
max-width: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-content {
|
2019-03-20 04:37:33 +00:00
|
|
|
height: $editor-height;
|
2018-09-16 15:59:22 +00:00
|
|
|
overflow-y: scroll;
|
2019-09-29 02:19:33 +00:00
|
|
|
padding: 0;
|
|
|
|
width: calc(100% + 17px);
|
2018-09-16 15:59:22 +00:00
|
|
|
// -ms-overflow-style: none;
|
|
|
|
|
|
|
|
// &::-webkit-scrollbar {
|
|
|
|
// width: 0px;
|
|
|
|
// background: transparent;
|
|
|
|
// }
|
2019-05-18 06:27:30 +00:00
|
|
|
|
|
|
|
@include until($tablet) {
|
|
|
|
height: $editor-height-mobile;
|
|
|
|
}
|
2020-05-22 17:31:31 +00:00
|
|
|
|
2020-06-22 22:10:48 +00:00
|
|
|
> div {
|
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
|
2020-05-22 17:31:31 +00:00
|
|
|
p.line {
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
}
|
2020-07-03 23:36:33 +00:00
|
|
|
|
|
|
|
.tabset {
|
|
|
|
background-color: mc('teal', '700');
|
|
|
|
color: mc('teal', '100') !important;
|
|
|
|
padding: 5px 12px;
|
|
|
|
font-size: 14px;
|
|
|
|
font-weight: 500;
|
|
|
|
border-radius: 5px 0 0 0;
|
|
|
|
font-style: italic;
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-header {
|
|
|
|
background-color: mc('teal', '500');
|
|
|
|
color: #FFF !important;
|
|
|
|
padding: 5px 12px;
|
|
|
|
font-size: 14px;
|
|
|
|
font-weight: 500;
|
|
|
|
margin-top: 0 !important;
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&-content {
|
|
|
|
border-left: 5px solid mc('teal', '500');
|
|
|
|
background-color: mc('teal', '50');
|
|
|
|
padding: 0 15px 15px;
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
@at-root .theme--dark & {
|
|
|
|
background-color: rgba(mc('teal', '500'), .1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-16 15:59:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&-toolbar {
|
|
|
|
background-color: mc('blue', '700');
|
|
|
|
background-image: linear-gradient(to bottom, mc('blue', '700') 0%, mc('blue','800') 100%);
|
|
|
|
color: #FFF;
|
|
|
|
|
|
|
|
.v-toolbar__content {
|
2019-08-04 02:51:29 +00:00
|
|
|
padding-left: 64px;
|
2018-09-16 15:59:22 +00:00
|
|
|
|
|
|
|
@include until($tablet) {
|
|
|
|
padding-left: 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 01:00:30 +00:00
|
|
|
&-insert:not(.v-speed-dial--right) {
|
|
|
|
@include from($tablet) {
|
|
|
|
left: 50%;
|
|
|
|
margin-left: -28px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-20 04:37:33 +00:00
|
|
|
&-sidebar {
|
|
|
|
background-color: mc('grey', '900');
|
|
|
|
width: 64px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: center;
|
|
|
|
padding: 24px 0;
|
2019-05-18 06:27:30 +00:00
|
|
|
|
|
|
|
@include until($tablet) {
|
|
|
|
padding: 12px 0;
|
|
|
|
width: 40px;
|
|
|
|
}
|
2019-03-20 04:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
&-sysbar {
|
|
|
|
padding-left: 0;
|
|
|
|
|
|
|
|
&-locale {
|
|
|
|
background-color: rgba(255,255,255,.25);
|
|
|
|
display:inline-flex;
|
|
|
|
padding: 0 12px;
|
|
|
|
height: 24px;
|
|
|
|
width: 63px;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 15:59:22 +00:00
|
|
|
// ==========================================
|
|
|
|
// Fix FAB revealing under codemirror
|
|
|
|
// ==========================================
|
|
|
|
|
|
|
|
.speed-dial--fixed {
|
|
|
|
z-index: 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ==========================================
|
|
|
|
// CODE MIRROR
|
|
|
|
// ==========================================
|
|
|
|
|
|
|
|
.CodeMirror {
|
|
|
|
height: auto;
|
2019-09-29 02:19:33 +00:00
|
|
|
font-family: 'Roboto Mono', monospace;
|
|
|
|
font-size: .9rem;
|
2018-09-16 15:59:22 +00:00
|
|
|
|
|
|
|
.cm-header-1 {
|
|
|
|
font-size: 1.5rem;
|
|
|
|
}
|
|
|
|
.cm-header-2 {
|
|
|
|
font-size: 1.25rem;
|
|
|
|
}
|
|
|
|
.cm-header-3 {
|
|
|
|
font-size: 1.15rem;
|
|
|
|
}
|
|
|
|
.cm-header-4 {
|
|
|
|
font-size: 1.1rem;
|
|
|
|
}
|
|
|
|
.cm-header-5 {
|
|
|
|
font-size: 1.05rem;
|
|
|
|
}
|
|
|
|
.cm-header-6 {
|
|
|
|
font-size: 1.025rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-22 17:31:31 +00:00
|
|
|
.CodeMirror-wrap pre.CodeMirror-line, .CodeMirror-wrap pre.CodeMirror-line-like {
|
|
|
|
word-break: break-word;
|
|
|
|
}
|
|
|
|
|
2018-09-16 15:59:22 +00:00
|
|
|
.CodeMirror-focused .cm-matchhighlight {
|
|
|
|
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFklEQVQI12NgYGBgkKzc8x9CMDAwAAAmhwSbidEoSQAAAABJRU5ErkJggg==);
|
|
|
|
background-position: bottom;
|
|
|
|
background-repeat: repeat-x;
|
|
|
|
}
|
|
|
|
.cm-matchhighlight {
|
|
|
|
background-color: mc('grey', '800');
|
|
|
|
}
|
|
|
|
.CodeMirror-selection-highlight-scrollbar {
|
|
|
|
background-color: mc('green', '600');
|
|
|
|
}
|
2020-04-11 04:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HINT DROPDOWN
|
|
|
|
|
|
|
|
.CodeMirror-hints {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 10;
|
|
|
|
overflow: hidden;
|
|
|
|
list-style: none;
|
|
|
|
|
|
|
|
margin: 0;
|
|
|
|
padding: 1px;
|
|
|
|
|
|
|
|
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
|
|
|
border: 1px solid mc('grey', '700');
|
|
|
|
|
|
|
|
background: mc('grey', '900');
|
|
|
|
font-family: 'Roboto Mono', monospace;
|
|
|
|
font-size: .9rem;
|
|
|
|
|
|
|
|
max-height: 150px;
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
|
|
min-width: 250px;
|
|
|
|
max-width: 80vw;
|
|
|
|
}
|
|
|
|
|
|
|
|
.CodeMirror-hint {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0 4px;
|
|
|
|
white-space: pre;
|
|
|
|
color: #FFF;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2018-09-16 15:59:22 +00:00
|
|
|
|
2020-04-11 04:19:23 +00:00
|
|
|
li.CodeMirror-hint-active {
|
|
|
|
background: mc('blue', '500');
|
|
|
|
color: #FFF;
|
2018-09-16 15:59:22 +00:00
|
|
|
}
|
|
|
|
</style>
|