You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

821 lines
26 KiB

5 years ago
5 years ago
  1. <template lang='pug'>
  2. .editor-markdown
  3. v-toolbar.editor-markdown-toolbar(dense, color='primary', dark, flat, style='overflow-x: hidden;')
  4. template(v-if='isModalShown')
  5. v-spacer
  6. v-btn.animated.fadeInRight(text, @click='closeAllModal')
  7. v-icon(left) mdi-arrow-left-circle
  8. span {{$t('editor:backToEditor')}}
  9. template(v-else)
  10. v-tooltip(bottom, color='primary')
  11. template(v-slot:activator='{ on }')
  12. v-btn.animated.fadeIn(icon, tile, v-on='on', @click='toggleMarkup({ start: `**` })').mx-0
  13. v-icon mdi-format-bold
  14. span {{$t('editor:markup.bold')}}
  15. v-tooltip(bottom, color='primary')
  16. template(v-slot:activator='{ on }')
  17. v-btn.animated.fadeIn.wait-p1s(icon, tile, v-on='on', @click='toggleMarkup({ start: `*` })').mx-0
  18. v-icon mdi-format-italic
  19. span {{$t('editor:markup.italic')}}
  20. v-tooltip(bottom, color='primary')
  21. template(v-slot:activator='{ on }')
  22. v-btn.animated.fadeIn.wait-p2s(icon, tile, v-on='on', @click='toggleMarkup({ start: `~~` })').mx-0
  23. v-icon mdi-format-strikethrough
  24. span {{$t('editor:markup.strikethrough')}}
  25. v-menu(offset-y, open-on-hover)
  26. template(v-slot:activator='{ on }')
  27. v-btn.animated.fadeIn.wait-p3s(icon, tile, v-on='on').mx-0
  28. v-icon mdi-format-header-pound
  29. v-list.py-0
  30. template(v-for='(n, idx) in 6')
  31. v-list-item(@click='setHeaderLine(n)', :key='idx')
  32. v-list-item-action
  33. v-icon(:size='24 - (idx - 1) * 2') mdi-format-header-{{n}}
  34. v-list-item-title {{$t('editor:markup.heading', { level: n })}}
  35. v-divider(v-if='idx < 5')
  36. v-tooltip(bottom, color='primary')
  37. template(v-slot:activator='{ on }')
  38. v-btn.animated.fadeIn.wait-p4s(icon, tile, v-on='on', @click='toggleMarkup({ start: `~` })').mx-0
  39. v-icon mdi-format-subscript
  40. span {{$t('editor:markup.subscript')}}
  41. v-tooltip(bottom, color='primary')
  42. template(v-slot:activator='{ on }')
  43. v-btn.animated.fadeIn.wait-p5s(icon, tile, v-on='on', @click='toggleMarkup({ start: `^` })').mx-0
  44. v-icon mdi-format-superscript
  45. span {{$t('editor:markup.superscript')}}
  46. v-menu(offset-y, open-on-hover)
  47. template(v-slot:activator='{ on }')
  48. v-btn.animated.fadeIn.wait-p6s(icon, tile, v-on='on').mx-0
  49. v-icon mdi-alpha-t-box-outline
  50. v-list.py-0
  51. v-list-item(@click='insertBeforeEachLine({ content: `> `})')
  52. v-list-item-action
  53. v-icon mdi-alpha-t-box-outline
  54. v-list-item-title {{$t('editor:markup.blockquote')}}
  55. v-divider
  56. v-list-item(@click='insertBeforeEachLine({ content: `> `, after: `{.is-info}`})')
  57. v-list-item-action
  58. v-icon(color='blue') mdi-alpha-i-box-outline
  59. v-list-item-title {{$t('editor:markup.blockquoteInfo')}}
  60. v-divider
  61. v-list-item(@click='insertBeforeEachLine({ content: `> `, after: `{.is-success}`})')
  62. v-list-item-action
  63. v-icon(color='success') mdi-alpha-s-box-outline
  64. v-list-item-title {{$t('editor:markup.blockquoteSuccess')}}
  65. v-divider
  66. v-list-item(@click='insertBeforeEachLine({ content: `> `, after: `{.is-warning}`})')
  67. v-list-item-action
  68. v-icon(color='warning') mdi-alpha-w-box-outline
  69. v-list-item-title {{$t('editor:markup.blockquoteWarning')}}
  70. v-divider
  71. v-list-item(@click='insertBeforeEachLine({ content: `> `, after: `{.is-danger}`})')
  72. v-list-item-action
  73. v-icon(color='error') mdi-alpha-e-box-outline
  74. v-list-item-title {{$t('editor:markup.blockquoteError')}}
  75. v-divider
  76. v-tooltip(bottom, color='primary')
  77. template(v-slot:activator='{ on }')
  78. v-btn.animated.fadeIn.wait-p7s(icon, tile, v-on='on', @click='insertBeforeEachLine({ content: `- `})').mx-0
  79. v-icon mdi-format-list-bulleted
  80. span {{$t('editor:markup.unorderedList')}}
  81. v-tooltip(bottom, color='primary')
  82. template(v-slot:activator='{ on }')
  83. v-btn.animated.fadeIn.wait-p8s(icon, tile, v-on='on', @click='insertBeforeEachLine({ content: `1. `})').mx-0
  84. v-icon mdi-format-list-numbered
  85. span {{$t('editor:markup.orderedList')}}
  86. v-tooltip(bottom, color='primary')
  87. template(v-slot:activator='{ on }')
  88. v-btn.animated.fadeIn.wait-p9s(icon, tile, v-on='on', @click='toggleMarkup({ start: "`" })').mx-0
  89. v-icon mdi-code-tags
  90. span {{$t('editor:markup.inlineCode')}}
  91. v-tooltip(bottom, color='primary')
  92. template(v-slot:activator='{ on }')
  93. v-btn.animated.fadeIn.wait-p10s(icon, tile, v-on='on', @click='toggleMarkup({ start: `<kbd>`, end: `</kbd>` })').mx-0
  94. v-icon mdi-keyboard-variant
  95. span {{$t('editor:markup.keyboardKey')}}
  96. v-tooltip(bottom, color='primary')
  97. template(v-slot:activator='{ on }')
  98. v-btn.animated.fadeIn.wait-p11s(icon, tile, v-on='on', @click='insertAfter({ content: `---`, newLine: true })').mx-0
  99. v-icon mdi-minus
  100. span {{$t('editor:markup.horizontalBar')}}
  101. template(v-if='$vuetify.breakpoint.mdAndUp')
  102. v-spacer
  103. v-tooltip(bottom, color='primary')
  104. template(v-slot:activator='{ on }')
  105. v-btn.animated.fadeIn.wait-p11s(icon, tile, v-on='on', @click='previewShown = !previewShown').mx-0
  106. v-icon mdi-book-open-outline
  107. span {{$t('editor:markup.togglePreviewPane')}}
  108. .editor-markdown-main
  109. .editor-markdown-sidebar
  110. v-tooltip(right, color='teal')
  111. template(v-slot:activator='{ on }')
  112. v-btn.animated.fadeInLeft(icon, tile, v-on='on', dark, disabled).mx-0
  113. v-icon mdi-link-plus
  114. span {{$t('editor:markup.insertLink')}}
  115. v-tooltip(right, color='teal')
  116. template(v-slot:activator='{ on }')
  117. v-btn.mt-3.animated.fadeInLeft.wait-p1s(icon, tile, v-on='on', dark, @click='toggleModal(`editorModalMedia`)').mx-0
  118. v-icon(:color='activeModal === `editorModalMedia` ? `teal` : ``') mdi-folder-multiple-image
  119. span {{$t('editor:markup.insertAssets')}}
  120. v-tooltip(right, color='teal')
  121. template(v-slot:activator='{ on }')
  122. v-btn.mt-3.animated.fadeInLeft.wait-p2s(icon, tile, v-on='on', dark, @click='toggleModal(`editorModalBlocks`)', disabled).mx-0
  123. v-icon(:color='activeModal === `editorModalBlocks` ? `teal` : ``') mdi-view-dashboard-outline
  124. span {{$t('editor:markup.insertBlock')}}
  125. v-tooltip(right, color='teal')
  126. template(v-slot:activator='{ on }')
  127. v-btn.mt-3.animated.fadeInLeft.wait-p3s(icon, tile, v-on='on', dark, disabled).mx-0
  128. v-icon mdi-code-braces
  129. span {{$t('editor:markup.insertCodeBlock')}}
  130. v-tooltip(right, color='teal')
  131. template(v-slot:activator='{ on }')
  132. v-btn.mt-3.animated.fadeInLeft.wait-p4s(icon, tile, v-on='on', dark, disabled).mx-0
  133. v-icon mdi-library-video
  134. span {{$t('editor:markup.insertVideoAudio')}}
  135. v-tooltip(right, color='teal')
  136. template(v-slot:activator='{ on }')
  137. v-btn.mt-3.animated.fadeInLeft.wait-p5s(icon, tile, v-on='on', dark, disabled).mx-0
  138. v-icon mdi-chart-multiline
  139. span {{$t('editor:markup.insertDiagram')}}
  140. v-tooltip(right, color='teal')
  141. template(v-slot:activator='{ on }')
  142. v-btn.mt-3.animated.fadeInLeft.wait-p6s(icon, tile, v-on='on', dark, disabled).mx-0
  143. v-icon mdi-function-variant
  144. span {{$t('editor:markup.insertMathExpression')}}
  145. v-tooltip(right, color='teal')
  146. template(v-slot:activator='{ on }')
  147. v-btn.mt-3.animated.fadeInLeft.wait-p7s(icon, tile, v-on='on', dark, disabled).mx-0
  148. v-icon mdi-table-plus
  149. span {{$t('editor:markup.tableHelper')}}
  150. template(v-if='$vuetify.breakpoint.mdAndUp')
  151. v-spacer
  152. v-tooltip(right, color='teal')
  153. template(v-slot:activator='{ on }')
  154. v-btn.mt-3.animated.fadeInLeft.wait-p8s(icon, tile, v-on='on', dark, @click='toggleFullscreen').mx-0
  155. v-icon mdi-arrow-expand-all
  156. span {{$t('editor:markup.distractionFreeMode')}}
  157. v-tooltip(right, color='teal')
  158. template(v-slot:activator='{ on }')
  159. v-btn.mt-3.animated.fadeInLeft.wait-p9s(icon, tile, v-on='on', dark, @click='toggleHelp').mx-0
  160. v-icon(:color='helpShown ? `teal` : ``') mdi-help-circle
  161. span {{$t('editor:markup.markdownFormattingHelp')}}
  162. .editor-markdown-editor
  163. textarea(ref='cm')
  164. transition(name='editor-markdown-preview')
  165. .editor-markdown-preview(v-if='previewShown')
  166. .editor-markdown-preview-content.contents(ref='editorPreviewContainer')
  167. div(ref='editorPreview', v-html='previewHTML')
  168. v-system-bar.editor-markdown-sysbar(dark, status, color='grey darken-3')
  169. .caption.editor-markdown-sysbar-locale {{locale.toUpperCase()}}
  170. .caption.px-3 /{{path}}
  171. template(v-if='$vuetify.breakpoint.mdAndUp')
  172. v-spacer
  173. .caption Markdown
  174. v-spacer
  175. .caption Ln {{cursorPos.line + 1}}, Col {{cursorPos.ch + 1}}
  176. markdown-help(v-if='helpShown')
  177. </template>
  178. <script>
  179. import _ from 'lodash'
  180. import { get, sync } from 'vuex-pathify'
  181. import markdownHelp from './markdown/help.vue'
  182. // ========================================
  183. // IMPORTS
  184. // ========================================
  185. // Code Mirror
  186. import CodeMirror from 'codemirror'
  187. import 'codemirror/lib/codemirror.css'
  188. // Language
  189. import 'codemirror/mode/markdown/markdown.js'
  190. // Addons
  191. import 'codemirror/addon/selection/active-line.js'
  192. import 'codemirror/addon/display/fullscreen.js'
  193. import 'codemirror/addon/display/fullscreen.css'
  194. import 'codemirror/addon/selection/mark-selection.js'
  195. import 'codemirror/addon/search/searchcursor.js'
  196. // Markdown-it
  197. import MarkdownIt from 'markdown-it'
  198. import mdAttrs from 'markdown-it-attrs'
  199. import mdEmoji from 'markdown-it-emoji'
  200. import mdTaskLists from 'markdown-it-task-lists'
  201. import mdExpandTabs from 'markdown-it-expand-tabs'
  202. import mdAbbr from 'markdown-it-abbr'
  203. import mdSup from 'markdown-it-sup'
  204. import mdSub from 'markdown-it-sub'
  205. import mdMark from 'markdown-it-mark'
  206. import mdImsize from 'markdown-it-imsize'
  207. // Prism (Syntax Highlighting)
  208. import Prism from 'prismjs'
  209. // ========================================
  210. // INIT
  211. // ========================================
  212. // Platform detection
  213. const CtrlKey = /Mac/.test(navigator.platform) ? 'Cmd' : 'Ctrl'
  214. // Markdown Instance
  215. const md = new MarkdownIt({
  216. html: true,
  217. breaks: true,
  218. linkify: true,
  219. typography: true,
  220. highlight(str, lang) {
  221. return `<pre class="line-numbers"><code class="language-${lang}">${str}</code></pre>`
  222. }
  223. })
  224. .use(mdAttrs)
  225. .use(mdEmoji)
  226. .use(mdTaskLists, {label: true, labelAfter: true})
  227. .use(mdExpandTabs)
  228. .use(mdAbbr)
  229. .use(mdSup)
  230. .use(mdSub)
  231. .use(mdMark)
  232. .use(mdImsize)
  233. // ========================================
  234. // HELPER FUNCTIONS
  235. // ========================================
  236. // Inject line numbers for preview scroll sync
  237. let linesMap = []
  238. function injectLineNumbers (tokens, idx, options, env, slf) {
  239. let line
  240. if (tokens[idx].map && tokens[idx].level === 0) {
  241. line = tokens[idx].map[0]
  242. tokens[idx].attrJoin('class', 'line')
  243. tokens[idx].attrSet('data-line', String(line))
  244. linesMap.push(line)
  245. }
  246. return slf.renderToken(tokens, idx, options, env, slf)
  247. }
  248. md.renderer.rules.paragraph_open = injectLineNumbers
  249. md.renderer.rules.heading_open = injectLineNumbers
  250. md.renderer.rules.blockquote_open = injectLineNumbers
  251. // ========================================
  252. // Vue Component
  253. // ========================================
  254. export default {
  255. components: {
  256. markdownHelp
  257. },
  258. props: {
  259. save: {
  260. type: Function,
  261. default: () => {}
  262. }
  263. },
  264. data() {
  265. return {
  266. fabInsertMenu: false,
  267. cm: null,
  268. cursorPos: { ch: 0, line: 1 },
  269. previewShown: true,
  270. previewHTML: '',
  271. helpShown: false
  272. }
  273. },
  274. computed: {
  275. isMobile() {
  276. return this.$vuetify.breakpoint.smAndDown
  277. },
  278. isModalShown() {
  279. return this.helpShown || this.activeModal !== ''
  280. },
  281. locale: get('page/locale'),
  282. path: get('page/path'),
  283. mode: get('editor/mode'),
  284. activeModal: sync('editor/activeModal')
  285. },
  286. methods: {
  287. toggleModal(key) {
  288. this.activeModal = (this.activeModal === key) ? '' : key
  289. this.helpShown = false
  290. },
  291. closeAllModal() {
  292. this.activeModal = ''
  293. this.helpShown = false
  294. },
  295. onCmInput: _.debounce(function (newContent) {
  296. linesMap = []
  297. this.$store.set('editor/content', newContent)
  298. this.previewHTML = md.render(newContent)
  299. this.$nextTick(() => {
  300. Prism.highlightAllUnder(this.$refs.editorPreview)
  301. Array.from(this.$refs.editorPreview.querySelectorAll('pre.line-numbers')).forEach(pre => pre.classList.add('prismjs'))
  302. this.scrollSync(this.cm)
  303. })
  304. }, 500),
  305. onCmPaste (cm, ev) {
  306. // const clipItems = (ev.clipboardData || ev.originalEvent.clipboardData).items
  307. // for (let clipItem of clipItems) {
  308. // if (_.startsWith(clipItem.type, 'image/')) {
  309. // const file = clipItem.getAsFile()
  310. // const reader = new FileReader()
  311. // reader.onload = evt => {
  312. // this.$store.commit(`loadingStart`, 'editor-paste-image')
  313. // this.insertAfter({
  314. // content: `![${file.name}](${evt.target.result})`,
  315. // newLine: true
  316. // })
  317. // }
  318. // reader.readAsDataURL(file)
  319. // }
  320. // }
  321. },
  322. /**
  323. * Update cursor state
  324. */
  325. positionSync(cm) {
  326. this.cursorPos = cm.getCursor('head')
  327. },
  328. /**
  329. * Wrap selection with start / end tags
  330. */
  331. toggleMarkup({ start, end }) {
  332. if (!end) { end = start }
  333. if (!this.cm.doc.somethingSelected()) {
  334. return this.$store.commit('showNotification', {
  335. message: this.$t('editor:markup.noSelectionError'),
  336. style: 'warning',
  337. icon: 'warning'
  338. })
  339. }
  340. this.cm.doc.replaceSelections(this.cm.doc.getSelections().map(s => start + s + end))
  341. },
  342. /**
  343. * Set current line as header
  344. */
  345. setHeaderLine(lvl) {
  346. const curLine = this.cm.doc.getCursor('head').line
  347. let lineContent = this.cm.doc.getLine(curLine)
  348. const lineLength = lineContent.length
  349. if (_.startsWith(lineContent, '#')) {
  350. lineContent = lineContent.replace(/^(#+ )/, '')
  351. }
  352. lineContent = _.times(lvl, n => '#').join('') + ` ` + lineContent
  353. this.cm.doc.replaceRange(lineContent, { line: curLine, ch: 0 }, { line: curLine, ch: lineLength })
  354. },
  355. /**
  356. * Get the header lever of the current line
  357. */
  358. getHeaderLevel(cm) {
  359. const curLine = this.cm.doc.getCursor('head').line
  360. let lineContent = this.cm.doc.getLine(curLine)
  361. let lvl = 0
  362. const result = lineContent.match(/^(#+) /)
  363. if (result) {
  364. lvl = _.get(result, '[1]', '').length
  365. }
  366. return lvl
  367. },
  368. /**
  369. * Insert content at cursor
  370. */
  371. insertAtCursor({ content }) {
  372. const cursor = this.cm.doc.getCursor('head')
  373. this.cm.doc.replaceRange(content, cursor)
  374. },
  375. /**
  376. * Insert content after current line
  377. */
  378. insertAfter({ content, newLine }) {
  379. const curLine = this.cm.doc.getCursor('to').line
  380. const lineLength = this.cm.doc.getLine(curLine).length
  381. this.cm.doc.replaceRange(newLine ? `\n${content}\n` : content, { line: curLine, ch: lineLength + 1 })
  382. },
  383. /**
  384. * Insert content before current line
  385. */
  386. insertBeforeEachLine({ content, after }) {
  387. let lines = []
  388. if (!this.cm.doc.somethingSelected()) {
  389. lines.push(this.cm.doc.getCursor('head').line)
  390. } else {
  391. lines = _.flatten(this.cm.doc.listSelections().map(sl => {
  392. const range = Math.abs(sl.anchor.line - sl.head.line) + 1
  393. const lowestLine = (sl.anchor.line > sl.head.line) ? sl.head.line : sl.anchor.line
  394. return _.times(range, l => l + lowestLine)
  395. }))
  396. }
  397. lines.forEach(ln => {
  398. let lineContent = this.cm.doc.getLine(ln)
  399. const lineLength = lineContent.length
  400. if (_.startsWith(lineContent, content)) {
  401. lineContent = lineContent.substring(content.length)
  402. }
  403. this.cm.doc.replaceRange(content + lineContent, { line: ln, ch: 0 }, { line: ln, ch: lineLength })
  404. })
  405. if (after) {
  406. const lastLine = _.last(lines)
  407. this.cm.doc.replaceRange(`\n${after}\n`, { line: lastLine, ch: this.cm.doc.getLine(lastLine).length + 1 })
  408. }
  409. },
  410. /**
  411. * Update scroll sync
  412. */
  413. scrollSync: _.debounce(function (cm) {
  414. if (!this.previewShown || cm.somethingSelected()) { return }
  415. let currentLine = cm.getCursor().line
  416. if (currentLine < 3) {
  417. this.Velocity(this.$refs.editorPreview, 'stop', true)
  418. this.Velocity(this.$refs.editorPreview.firstChild, 'scroll', { offset: '-50', duration: 1000, container: this.$refs.editorPreviewContainer })
  419. } else {
  420. let closestLine = _.findLast(linesMap, n => n <= currentLine)
  421. let destElm = this.$refs.editorPreview.querySelector(`[data-line='${closestLine}']`)
  422. if (destElm) {
  423. this.Velocity(this.$refs.editorPreview, 'stop', true)
  424. this.Velocity(destElm, 'scroll', { offset: '-100', duration: 1000, container: this.$refs.editorPreviewContainer })
  425. }
  426. }
  427. }, 500),
  428. toggleHelp () {
  429. this.helpShown = !this.helpShown
  430. this.activeModal = ''
  431. },
  432. toggleFullscreen () {
  433. this.cm.setOption('fullScreen', true)
  434. },
  435. refresh() {
  436. this.$nextTick(() => {
  437. this.cm.refresh()
  438. })
  439. }
  440. },
  441. mounted() {
  442. this.$store.set('editor/editorKey', 'markdown')
  443. if (this.mode === 'create') {
  444. this.$store.set('editor/content', '# Header\nYour content here')
  445. }
  446. // Initialize CodeMirror
  447. this.cm = CodeMirror.fromTextArea(this.$refs.cm, {
  448. tabSize: 2,
  449. mode: 'text/markdown',
  450. theme: 'wikijs-dark',
  451. lineNumbers: true,
  452. lineWrapping: true,
  453. line: true,
  454. styleActiveLine: true,
  455. highlightSelectionMatches: {
  456. annotateScrollbar: true
  457. },
  458. viewportMargin: 50,
  459. inputStyle: 'contenteditable',
  460. allowDropFileTypes: ['image/jpg', 'image/png', 'image/svg', 'image/jpeg', 'image/gif']
  461. })
  462. this.cm.setValue(this.$store.get('editor/content'))
  463. this.cm.on('change', c => {
  464. this.$store.set('editor/content', c.getValue())
  465. this.onCmInput(this.$store.get('editor/content'))
  466. })
  467. if (this.$vuetify.breakpoint.mdAndUp) {
  468. this.cm.setSize(null, 'calc(100vh - 112px - 24px)')
  469. } else {
  470. this.cm.setSize(null, 'calc(100vh - 112px - 16px)')
  471. }
  472. // Set Keybindings
  473. const keyBindings = {
  474. 'F11' (c) {
  475. c.setOption('fullScreen', !c.getOption('fullScreen'))
  476. },
  477. 'Esc' (c) {
  478. if (c.getOption('fullScreen')) c.setOption('fullScreen', false)
  479. }
  480. }
  481. _.set(keyBindings, `${CtrlKey}-S`, c => {
  482. this.save()
  483. return false
  484. })
  485. _.set(keyBindings, `${CtrlKey}-B`, c => {
  486. this.toggleMarkup({ start: `**` })
  487. return false
  488. })
  489. _.set(keyBindings, `${CtrlKey}-I`, c => {
  490. this.toggleMarkup({ start: `*` })
  491. return false
  492. })
  493. _.set(keyBindings, `${CtrlKey}-Alt-Right`, c => {
  494. let lvl = this.getHeaderLevel(c)
  495. if (lvl >= 6) { lvl = 5 }
  496. this.setHeaderLine(lvl + 1)
  497. return false
  498. })
  499. _.set(keyBindings, `${CtrlKey}-Alt-Left`, c => {
  500. let lvl = this.getHeaderLevel(c)
  501. if (lvl <= 1) { lvl = 2 }
  502. this.setHeaderLine(lvl - 1)
  503. return false
  504. })
  505. this.cm.setOption('extraKeys', keyBindings)
  506. // Handle cursor movement
  507. this.cm.on('cursorActivity', c => {
  508. this.positionSync(c)
  509. this.scrollSync(c)
  510. })
  511. // Handle special paste
  512. this.cm.on('paste', this.onCmPaste)
  513. // Render initial preview
  514. this.onCmInput(this.$store.get('editor/content'))
  515. this.refresh()
  516. this.$root.$on('editorInsert', opts => {
  517. switch (opts.kind) {
  518. case 'IMAGE':
  519. let img = `![${opts.text}](${opts.path})`
  520. if (opts.align && opts.align !== '') {
  521. img += `{.align-${opts.align}}`
  522. }
  523. this.insertAtCursor({
  524. content: img
  525. })
  526. break
  527. case 'BINARY':
  528. this.insertAtCursor({
  529. content: `[${opts.text}](${opts.path})`
  530. })
  531. break
  532. }
  533. })
  534. },
  535. beforeDestroy() {
  536. this.$root.$off('editorInsert')
  537. }
  538. }
  539. </script>
  540. <style lang='scss'>
  541. $editor-height: calc(100vh - 112px - 24px);
  542. $editor-height-mobile: calc(100vh - 112px - 16px);
  543. .editor-markdown {
  544. &-main {
  545. display: flex;
  546. width: 100%;
  547. }
  548. &-editor {
  549. background-color: darken(mc('grey', '900'), 4.5%);
  550. flex: 1 1 50%;
  551. display: block;
  552. height: $editor-height;
  553. position: relative;
  554. @include until($tablet) {
  555. height: $editor-height-mobile;
  556. }
  557. }
  558. &-preview {
  559. flex: 1 1 50%;
  560. background-color: mc('grey', '100');
  561. position: relative;
  562. height: $editor-height;
  563. overflow: hidden;
  564. padding: 1rem;
  565. @at-root .theme--dark & {
  566. background-color: mc('grey', '900');
  567. }
  568. @include until($tablet) {
  569. display: none;
  570. }
  571. &-enter-active, &-leave-active {
  572. transition: max-width .5s ease;
  573. max-width: 50vw;
  574. .editor-code-preview-content {
  575. width: 50vw;
  576. overflow:hidden;
  577. }
  578. }
  579. &-enter, &-leave-to {
  580. max-width: 0;
  581. }
  582. &-content {
  583. height: $editor-height;
  584. overflow-y: scroll;
  585. padding: 0;
  586. width: calc(100% + 17px);
  587. // -ms-overflow-style: none;
  588. // &::-webkit-scrollbar {
  589. // width: 0px;
  590. // background: transparent;
  591. // }
  592. @include until($tablet) {
  593. height: $editor-height-mobile;
  594. }
  595. }
  596. }
  597. &-toolbar {
  598. background-color: mc('blue', '700');
  599. background-image: linear-gradient(to bottom, mc('blue', '700') 0%, mc('blue','800') 100%);
  600. color: #FFF;
  601. .v-toolbar__content {
  602. padding-left: 64px;
  603. @include until($tablet) {
  604. padding-left: 8px;
  605. }
  606. }
  607. }
  608. &-insert:not(.v-speed-dial--right) {
  609. @include from($tablet) {
  610. left: 50%;
  611. margin-left: -28px;
  612. }
  613. }
  614. &-sidebar {
  615. background-color: mc('grey', '900');
  616. width: 64px;
  617. display: flex;
  618. flex-direction: column;
  619. justify-content: flex-start;
  620. align-items: center;
  621. padding: 24px 0;
  622. @include until($tablet) {
  623. padding: 12px 0;
  624. width: 40px;
  625. }
  626. }
  627. &-sysbar {
  628. padding-left: 0;
  629. &-locale {
  630. background-color: rgba(255,255,255,.25);
  631. display:inline-flex;
  632. padding: 0 12px;
  633. height: 24px;
  634. width: 63px;
  635. justify-content: center;
  636. align-items: center;
  637. }
  638. }
  639. // ==========================================
  640. // Fix FAB revealing under codemirror
  641. // ==========================================
  642. .speed-dial--fixed {
  643. z-index: 8;
  644. }
  645. // ==========================================
  646. // CODE MIRROR
  647. // ==========================================
  648. .CodeMirror {
  649. height: auto;
  650. font-family: 'Roboto Mono', monospace;
  651. font-size: .9rem;
  652. .cm-header-1 {
  653. font-size: 1.5rem;
  654. }
  655. .cm-header-2 {
  656. font-size: 1.25rem;
  657. }
  658. .cm-header-3 {
  659. font-size: 1.15rem;
  660. }
  661. .cm-header-4 {
  662. font-size: 1.1rem;
  663. }
  664. .cm-header-5 {
  665. font-size: 1.05rem;
  666. }
  667. .cm-header-6 {
  668. font-size: 1.025rem;
  669. }
  670. }
  671. .CodeMirror-focused .cm-matchhighlight {
  672. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFklEQVQI12NgYGBgkKzc8x9CMDAwAAAmhwSbidEoSQAAAABJRU5ErkJggg==);
  673. background-position: bottom;
  674. background-repeat: repeat-x;
  675. }
  676. .cm-matchhighlight {
  677. background-color: mc('grey', '800');
  678. }
  679. .CodeMirror-selection-highlight-scrollbar {
  680. background-color: mc('green', '600');
  681. }
  682. .cm-s-wikijs-dark.CodeMirror {
  683. background: darken(mc('grey','900'), 3%);
  684. color: #e0e0e0;
  685. }
  686. .cm-s-wikijs-dark div.CodeMirror-selected {
  687. background: mc('blue','800');
  688. }
  689. .cm-s-wikijs-dark .cm-matchhighlight {
  690. background: mc('blue','800');
  691. }
  692. .cm-s-wikijs-dark .CodeMirror-line::selection, .cm-s-wikijs-dark .CodeMirror-line > span::selection, .cm-s-wikijs-dark .CodeMirror-line > span > span::selection {
  693. background: mc('amber', '500');
  694. }
  695. .cm-s-wikijs-dark .CodeMirror-line::-moz-selection, .cm-s-wikijs-dark .CodeMirror-line > span::-moz-selection, .cm-s-wikijs-dark .CodeMirror-line > span > span::-moz-selection {
  696. background: mc('amber', '500');
  697. }
  698. .cm-s-wikijs-dark .CodeMirror-gutters {
  699. background: darken(mc('grey','900'), 6%);
  700. border-right: 1px solid mc('grey','900');
  701. }
  702. .cm-s-wikijs-dark .CodeMirror-guttermarker {
  703. color: #ac4142;
  704. }
  705. .cm-s-wikijs-dark .CodeMirror-guttermarker-subtle {
  706. color: #505050;
  707. }
  708. .cm-s-wikijs-dark .CodeMirror-linenumber {
  709. color: mc('grey','800');
  710. }
  711. .cm-s-wikijs-dark .CodeMirror-cursor {
  712. border-left: 1px solid #b0b0b0;
  713. }
  714. .cm-s-wikijs-dark span.cm-comment {
  715. color: mc('orange','800');
  716. }
  717. .cm-s-wikijs-dark span.cm-atom {
  718. color: #aa759f;
  719. }
  720. .cm-s-wikijs-dark span.cm-number {
  721. color: #aa759f;
  722. }
  723. .cm-s-wikijs-dark span.cm-property, .cm-s-wikijs-dark span.cm-attribute {
  724. color: #90a959;
  725. }
  726. .cm-s-wikijs-dark span.cm-keyword {
  727. color: #ac4142;
  728. }
  729. .cm-s-wikijs-dark span.cm-string {
  730. color: #f4bf75;
  731. }
  732. .cm-s-wikijs-dark span.cm-variable {
  733. color: #90a959;
  734. }
  735. .cm-s-wikijs-dark span.cm-variable-2 {
  736. color: #6a9fb5;
  737. }
  738. .cm-s-wikijs-dark span.cm-def {
  739. color: #d28445;
  740. }
  741. .cm-s-wikijs-dark span.cm-bracket {
  742. color: #e0e0e0;
  743. }
  744. .cm-s-wikijs-dark span.cm-tag {
  745. color: #ac4142;
  746. }
  747. .cm-s-wikijs-dark span.cm-link {
  748. color: #aa759f;
  749. }
  750. .cm-s-wikijs-dark span.cm-error {
  751. background: #ac4142;
  752. color: #b0b0b0;
  753. }
  754. .cm-s-wikijs-dark .CodeMirror-activeline-background {
  755. background: mc('grey','900');
  756. }
  757. .cm-s-wikijs-dark .CodeMirror-matchingbracket {
  758. text-decoration: underline;
  759. color: white !important;
  760. }
  761. }
  762. </style>