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
5f99b300
Commit
5f99b300
authored
Jul 12, 2020
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: code folding + diagram folding
parent
d209a415
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
1 deletion
+81
-1
editor-markdown.vue
client/components/editor/editor-markdown.vue
+9
-1
fold.js
client/components/editor/markdown/fold.js
+62
-0
codemirror.scss
client/scss/components/codemirror.scss
+10
-0
No files found.
client/components/editor/editor-markdown.vue
View file @
5f99b300
...
...
@@ -217,6 +217,10 @@ import 'codemirror/addon/display/fullscreen.css'
import
'codemirror/addon/selection/mark-selection.js'
import
'codemirror/addon/search/searchcursor.js'
import
'codemirror/addon/hint/show-hint.js'
import
'codemirror/addon/fold/foldcode.js'
import
'codemirror/addon/fold/foldgutter.js'
import
'codemirror/addon/fold/foldgutter.css'
import
'./markdown/fold'
// Markdown-it
import
MarkdownIt
from
'markdown-it'
...
...
@@ -685,7 +689,9 @@ export default {
viewportMargin
:
50
,
inputStyle
:
'contenteditable'
,
allowDropFileTypes
:
[
'image/jpg'
,
'image/png'
,
'image/svg'
,
'image/jpeg'
,
'image/gif'
],
direction
:
siteConfig
.
rtl
?
'rtl'
:
'ltr'
direction
:
siteConfig
.
rtl
?
'rtl'
:
'ltr'
,
foldGutter
:
true
,
gutters
:
[
'CodeMirror-linenumbers'
,
'CodeMirror-foldgutter'
]
}
)
this
.
cm
.
setValue
(
this
.
$store
.
get
(
'editor/content'
))
this
.
cm
.
on
(
'change'
,
c
=>
{
...
...
@@ -769,9 +775,11 @@ export default {
}
)
break
case
'DIAGRAM'
:
const
foldLine
=
this
.
cm
.
getCursor
().
line
this
.
insertAtCursor
({
content
:
'```diagram
\
n'
+
opts
.
text
+
'
\
n```'
}
)
this
.
cm
.
foldCode
(
foldLine
)
break
}
}
)
...
...
client/components/editor/markdown/fold.js
0 → 100644
View file @
5f99b300
// Header matching code by CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/LICENSE
import
CodeMirror
from
'codemirror'
const
maxDepth
=
100
const
codeBlockStartMatch
=
/^`
{3}[
a-zA-Z0-9
]
+$/
const
codeBlockEndMatch
=
/^`
{3}
$/
CodeMirror
.
registerHelper
(
'fold'
,
'markdown'
,
function
(
cm
,
start
)
{
const
firstLine
=
cm
.
getLine
(
start
.
line
)
const
lastLineNo
=
cm
.
lastLine
()
let
end
function
isHeader
(
lineNo
)
{
const
tokentype
=
cm
.
getTokenTypeAt
(
CodeMirror
.
Pos
(
lineNo
,
0
))
return
tokentype
&&
/
\b
header
\b
/
.
test
(
tokentype
)
}
function
headerLevel
(
lineNo
,
line
,
nextLine
)
{
let
match
=
line
&&
line
.
match
(
/^#+/
)
if
(
match
&&
isHeader
(
lineNo
))
return
match
[
0
].
length
match
=
nextLine
&&
nextLine
.
match
(
/^
[
=-
]
+
\s
*$/
)
if
(
match
&&
isHeader
(
lineNo
+
1
))
return
nextLine
[
0
]
===
'='
?
1
:
2
return
maxDepth
}
// -> CODE BLOCK
if
(
codeBlockStartMatch
.
test
(
cm
.
getLine
(
start
.
line
)))
{
end
=
start
.
line
let
nextNextLine
=
cm
.
getLine
(
end
+
1
)
while
(
end
<
lastLineNo
)
{
if
(
codeBlockEndMatch
.
test
(
nextNextLine
))
{
end
++
break
}
end
++
nextNextLine
=
cm
.
getLine
(
end
+
1
)
}
}
else
{
// -> HEADER
let
nextLine
=
cm
.
getLine
(
start
.
line
+
1
)
const
level
=
headerLevel
(
start
.
line
,
firstLine
,
nextLine
)
if
(
level
===
maxDepth
)
return
undefined
end
=
start
.
line
let
nextNextLine
=
cm
.
getLine
(
end
+
2
)
while
(
end
<
lastLineNo
)
{
if
(
headerLevel
(
end
+
1
,
nextLine
,
nextNextLine
)
<=
level
)
break
++
end
nextLine
=
nextNextLine
nextNextLine
=
cm
.
getLine
(
end
+
2
)
}
}
return
{
from
:
CodeMirror
.
Pos
(
start
.
line
,
firstLine
.
length
),
to
:
CodeMirror
.
Pos
(
end
,
cm
.
getLine
(
end
).
length
)
}
})
client/scss/components/codemirror.scss
View file @
5f99b300
...
...
@@ -77,3 +77,13 @@
text-decoration
:
underline
;
color
:
white
!
important
;
}
.cm-s-wikijs-dark
.CodeMirror-foldmarker
{
margin-left
:
10px
;
display
:
inline-block
;
background-color
:
rgba
(
mc
(
'amber'
,
'800'
)
,
.3
);
padding
:
8px
5px
;
color
:
mc
(
'amber'
,
'500'
);
border-radius
:
5px
;
text-shadow
:
none
;
}
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