Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
f4502cce
Commit
f4502cce
authored
Jul 12, 2020
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: markdown editor process markers
parent
52d0af19
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
17 deletions
+78
-17
editor-markdown.vue
client/components/editor/editor-markdown.vue
+66
-17
codemirror.scss
client/scss/components/codemirror.scss
+11
-0
editor.js
client/store/editor.js
+1
-0
No files found.
client/components/editor/editor-markdown.vue
View file @
f4502cce
...
...
@@ -436,17 +436,8 @@ export default {
this
.
helpShown
=
false
}
,
onCmInput
:
_
.
debounce
(
function
(
newContent
)
{
linesMap
=
[]
this
.
$store
.
set
(
'editor/content'
,
newContent
)
this
.
previewHTML
=
DOMPurify
.
sanitize
(
md
.
render
(
newContent
))
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
)
}
)
}
,
500
),
this
.
processContent
(
newContent
)
}
,
600
),
onCmPaste
(
cm
,
ev
)
{
// const clipItems = (ev.clipboardData || ev.originalEvent.clipboardData).items
// for (let clipItem of clipItems)
{
...
...
@@ -464,6 +455,19 @@ export default {
//
}
//
}
}
,
processContent (newContent) {
linesMap = []
// this.$store.set('editor/content', newContent)
this.processMarkers(this.cm.firstLine(), this.cm.lastLine())
this.previewHTML = DOMPurify.sanitize(md.render(newContent))
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)
}
)
}
,
/**
* Update cursor state
*/
...
...
@@ -658,6 +662,52 @@ export default {
this
.
insertAtCursor
({
content
:
siteLangs
.
length
>
0
?
`[${lastPart
}
](/${locale
}
/${path
}
)`
:
`[${lastPart
}
](/${path
}
)`
}
)
}
,
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
)
{
case
'diagram'
:
{
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
}
)
// this.$store.set('editor/activeModalData', )
this
.
toggleModal
(
`editorModalDrawio`
)
}
}
)(
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
}
)
}
}
,
mounted
()
{
...
...
@@ -755,7 +805,7 @@ export default {
// Render initial preview
this
.
onCmInpu
t
(
this
.
$store
.
get
(
'editor/content'
))
this
.
processConten
t
(
this
.
$store
.
get
(
'editor/content'
))
this
.
refresh
()
this
.
$root
.
$on
(
'editorInsert'
,
opts
=>
{
...
...
@@ -775,11 +825,10 @@ export default {
}
)
break
case
'DIAGRAM'
:
const
foldLine
=
this
.
cm
.
getCursor
().
line
this
.
insertAtCursor
({
content
:
'```diagram
\
n'
+
opts
.
text
+
'
\
n```'
}
)
this
.
cm
.
foldCode
(
foldLine
)
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
)
break
}
}
)
...
...
client/scss/components/codemirror.scss
View file @
f4502cce
...
...
@@ -87,3 +87,14 @@
border-radius
:
5px
;
text-shadow
:
none
;
}
.cm-s-wikijs-dark
.CodeMirror-buttonmarker
{
display
:
inline-block
;
background-color
:
rgba
(
mc
(
'blue'
,
'500'
)
,
.3
);
border
:
1px
solid
mc
(
'blue'
,
'800'
);
padding
:
1px
10px
;
color
:
mc
(
'blue'
,
'200'
)
!
important
;
border-radius
:
5px
;
margin-left
:
5px
;
cursor
:
pointer
;
}
client/store/editor.js
View file @
f4502cce
...
...
@@ -6,6 +6,7 @@ const state = {
content
:
''
,
mode
:
'create'
,
activeModal
:
''
,
activeModalData
:
null
,
media
:
{
folderTree
:
[],
currentFolderId
:
0
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment