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
a581d983
Commit
a581d983
authored
May 18, 2020
by
Robert Lanyi
Committed by
NGPixel
May 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add Kroki renderer (#1900)
* feat: Kroki integration see
https://kroki.io/
* fix: markdown-kroki def updates Co-authored-by:
Nicolas Giard
<
github@ngpixel.com
>
parent
764d98fa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
172 additions
and
0 deletions
+172
-0
definition.yml
server/modules/rendering/markdown-kroki/definition.yml
+29
-0
renderer.js
server/modules/rendering/markdown-kroki/renderer.js
+143
-0
No files found.
server/modules/rendering/markdown-kroki/definition.yml
0 → 100644
View file @
a581d983
key
:
markdownKroki
title
:
Kroki
description
:
Kroki Diagrams Parser
author
:
rlanyi (based on PlantUML renderer)
icon
:
mdi-sitemap
enabledDefault
:
false
dependsOn
:
markdownCore
props
:
server
:
type
:
String
default
:
https://kroki.io
title
:
Kroki Server
hint
:
Kroki server used for image generation
order
:
1
public
:
true
openMarker
:
type
:
String
default
:
"
```kroki"
title
:
Open Marker
hint
:
String to use as opening delimiter. Diagram type must be put in the next line in lowercase.
order
:
2
public
:
true
closeMarker
:
type
:
String
default
:
"
```"
title
:
Close Marker
hint
:
String to use as closing delimiter
order
:
3
public
:
true
server/modules/rendering/markdown-kroki/renderer.js
0 → 100644
View file @
a581d983
const
zlib
=
require
(
'zlib'
)
// ------------------------------------
// Markdown - Kroki Preprocessor
// ------------------------------------
module
.
exports
=
{
init
(
mdinst
,
conf
)
{
mdinst
.
use
((
md
,
opts
)
=>
{
const
openMarker
=
opts
.
openMarker
||
'```kroki'
const
openChar
=
openMarker
.
charCodeAt
(
0
)
const
closeMarker
=
opts
.
closeMarker
||
'```'
const
closeChar
=
closeMarker
.
charCodeAt
(
0
)
const
server
=
opts
.
server
||
'https://kroki.io'
md
.
block
.
ruler
.
before
(
'fence'
,
'kroki'
,
(
state
,
startLine
,
endLine
,
silent
)
=>
{
let
nextLine
let
markup
let
params
let
token
let
i
let
autoClosed
=
false
let
start
=
state
.
bMarks
[
startLine
]
+
state
.
tShift
[
startLine
]
let
max
=
state
.
eMarks
[
startLine
]
// Check out the first character quickly,
// this should filter out most of non-uml blocks
//
if
(
openChar
!==
state
.
src
.
charCodeAt
(
start
))
{
return
false
}
// Check out the rest of the marker string
//
for
(
i
=
0
;
i
<
openMarker
.
length
;
++
i
)
{
if
(
openMarker
[
i
]
!==
state
.
src
[
start
+
i
])
{
return
false
}
}
markup
=
state
.
src
.
slice
(
start
,
start
+
i
)
params
=
state
.
src
.
slice
(
start
+
i
,
max
)
// Since start is found, we can report success here in validation mode
//
if
(
silent
)
{
return
true
}
// Search for the end of the block
//
nextLine
=
startLine
for
(;;)
{
nextLine
++
if
(
nextLine
>=
endLine
)
{
// unclosed block should be autoclosed by end of document.
// also block seems to be autoclosed by end of parent
break
}
start
=
state
.
bMarks
[
nextLine
]
+
state
.
tShift
[
nextLine
]
max
=
state
.
eMarks
[
nextLine
]
if
(
start
<
max
&&
state
.
sCount
[
nextLine
]
<
state
.
blkIndent
)
{
// non-empty line with negative indent should stop the list:
// - ```
// test
break
}
if
(
closeChar
!==
state
.
src
.
charCodeAt
(
start
))
{
// didn't find the closing fence
continue
}
if
(
state
.
sCount
[
nextLine
]
>
state
.
sCount
[
startLine
])
{
// closing fence should not be indented with respect of opening fence
continue
}
var
closeMarkerMatched
=
true
for
(
i
=
0
;
i
<
closeMarker
.
length
;
++
i
)
{
if
(
closeMarker
[
i
]
!==
state
.
src
[
start
+
i
])
{
closeMarkerMatched
=
false
break
}
}
if
(
!
closeMarkerMatched
)
{
continue
}
// make sure tail has spaces only
if
(
state
.
skipSpaces
(
start
+
i
)
<
max
)
{
continue
}
// found!
autoClosed
=
true
break
}
let
contents
=
state
.
src
.
split
(
'
\
n'
)
.
slice
(
startLine
+
1
,
nextLine
)
.
join
(
'
\
n'
)
// We generate a token list for the alt property, to mimic what the image parser does.
let
altToken
=
[]
// Remove leading space if any.
let
alt
=
params
?
params
.
slice
(
1
)
:
'uml diagram'
state
.
md
.
inline
.
parse
(
alt
,
state
.
md
,
state
.
env
,
altToken
)
let
firstlf
=
contents
.
indexOf
(
'
\
n'
)
if
(
firstlf
===
-
1
)
firstlf
=
undefined
let
diagramType
=
contents
.
substring
(
0
,
firstlf
)
contents
=
contents
.
substring
(
firstlf
+
1
)
let
result
=
zlib
.
deflateSync
(
contents
).
toString
(
'base64'
).
replace
(
/
\+
/g
,
'-'
).
replace
(
/
\/
/g
,
'_'
)
token
=
state
.
push
(
'kroki'
,
'img'
,
0
)
// alt is constructed from children. No point in populating it here.
token
.
attrs
=
[
[
'src'
,
`
${
server
}
/
${
diagramType
}
/svg/
${
result
}
`
],
[
'alt'
,
''
],
[
'class'
,
'uml-diagram'
]
]
token
.
block
=
true
token
.
children
=
altToken
token
.
info
=
params
token
.
map
=
[
startLine
,
nextLine
]
token
.
markup
=
markup
state
.
line
=
nextLine
+
(
autoClosed
?
1
:
0
)
return
true
},
{
alt
:
[
'paragraph'
,
'reference'
,
'blockquote'
,
'list'
]
})
md
.
renderer
.
rules
.
kroki
=
md
.
renderer
.
rules
.
image
},
{
openMarker
:
conf
.
openMarker
,
closeMarker
:
conf
.
closeMarker
,
server
:
conf
.
server
})
}
}
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