mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
remove code redundancy in parsing of PlantUml
This commit is contained in:
committed by
Junyoung Choi
parent
d069722bf9
commit
5357d8dc04
@@ -183,81 +183,47 @@ class Markdown {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const deflate = require('markdown-it-plantuml/lib/deflate')
|
const deflate = require('markdown-it-plantuml/lib/deflate')
|
||||||
this.md.use(require('markdown-it-plantuml'), {
|
const plantuml = require('markdown-it-plantuml')
|
||||||
generateSource: function (umlCode) {
|
const plantUmlStripTrailingSlash = (url) => url.endsWith('/') ? url.slice(0, -1) : url
|
||||||
const stripTrailingSlash = (url) => url.endsWith('/') ? url.slice(0, -1) : url
|
const plantUmlServerAddress = plantUmlStripTrailingSlash(config.preview.plantUMLServerAddress)
|
||||||
const serverAddress = stripTrailingSlash(config.preview.plantUMLServerAddress) + '/svg'
|
const parsePlantUml = function (umlCode, openMarker, closeMarker, type){
|
||||||
const s = unescape(encodeURIComponent(umlCode))
|
const s = unescape(encodeURIComponent(umlCode))
|
||||||
const zippedCode = deflate.encode64(
|
const zippedCode = deflate.encode64(
|
||||||
deflate.zip_deflate(`@startuml\n${s}\n@enduml`, 9)
|
deflate.zip_deflate(`${openMarker}\n${s}\n${closeMarker}`, 9)
|
||||||
)
|
)
|
||||||
return `${serverAddress}/${zippedCode}`
|
return `${plantUmlServerAddress}/${type}/${zippedCode}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.md.use(plantuml, {
|
||||||
|
generateSource: (umlCode) => parsePlantUml(umlCode, '@startuml', '@enduml', 'svg')
|
||||||
})
|
})
|
||||||
|
|
||||||
const plantuml = require('markdown-it-plantuml')
|
// Ditaa support. PlantUML server doesn't support Ditaa in SVG, so we set the format as PNG at the moment.
|
||||||
// Ditaa support
|
|
||||||
this.md.use(plantuml, {
|
this.md.use(plantuml, {
|
||||||
openMarker: '@startditaa',
|
openMarker: '@startditaa',
|
||||||
closeMarker: '@endditaa',
|
closeMarker: '@endditaa',
|
||||||
generateSource: function (umlCode) {
|
generateSource: (umlCode) => parsePlantUml(umlCode, '@startditaa', '@endditaa', 'png')
|
||||||
const stripTrailingSlash = (url) => url.endsWith('/') ? url.slice(0, -1) : url
|
|
||||||
// Currently PlantUML server doesn't support Ditaa in SVG, so we set the format as PNG at the moment.
|
|
||||||
const serverAddress = stripTrailingSlash(config.preview.plantUMLServerAddress) + '/png'
|
|
||||||
const s = unescape(encodeURIComponent(umlCode))
|
|
||||||
const zippedCode = deflate.encode64(
|
|
||||||
deflate.zip_deflate(`@startditaa\n${s}\n@endditaa`, 9)
|
|
||||||
)
|
|
||||||
return `${serverAddress}/${zippedCode}`
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Mindmap support
|
// Mindmap support
|
||||||
this.md.use(plantuml, {
|
this.md.use(plantuml, {
|
||||||
openMarker: '@startmindmap',
|
openMarker: '@startmindmap',
|
||||||
closeMarker: '@endmindmap',
|
closeMarker: '@endmindmap',
|
||||||
generateSource: function (umlCode) {
|
generateSource: (umlCode) => parsePlantUml(umlCode, '@startmindmap', '@endmindmap', 'svg')
|
||||||
const stripTrailingSlash = (url) => url.endsWith('/') ? url.slice(0, -1) : url
|
|
||||||
// Currently PlantUML server doesn't support Ditaa in SVG, so we set the format as PNG at the moment.
|
|
||||||
const serverAddress = stripTrailingSlash(config.preview.plantUMLServerAddress) + '/svg'
|
|
||||||
const s = unescape(encodeURIComponent(umlCode))
|
|
||||||
const zippedCode = deflate.encode64(
|
|
||||||
deflate.zip_deflate(`@startmindmap\n${s}\n@endmindmap`, 9)
|
|
||||||
)
|
|
||||||
return `${serverAddress}/${zippedCode}`
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// WBS support
|
// WBS support
|
||||||
this.md.use(plantuml, {
|
this.md.use(plantuml, {
|
||||||
openMarker: '@startwbs',
|
openMarker: '@startwbs',
|
||||||
closeMarker: '@endwbs',
|
closeMarker: '@endwbs',
|
||||||
generateSource: function (umlCode) {
|
generateSource: (umlCode) => parsePlantUml(umlCode, '@startwbs', '@endwbs', 'svg')
|
||||||
const stripTrailingSlash = (url) => url.endsWith('/') ? url.slice(0, -1) : url
|
|
||||||
// Currently PlantUML server doesn't support Ditaa in SVG, so we set the format as PNG at the moment.
|
|
||||||
const serverAddress = stripTrailingSlash(config.preview.plantUMLServerAddress) + '/svg'
|
|
||||||
const s = unescape(encodeURIComponent(umlCode))
|
|
||||||
const zippedCode = deflate.encode64(
|
|
||||||
deflate.zip_deflate(`@startwbs\n${s}\n@endwbs`, 9)
|
|
||||||
)
|
|
||||||
return `${serverAddress}/${zippedCode}`
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Gantt support
|
// Gantt support
|
||||||
this.md.use(plantuml, {
|
this.md.use(plantuml, {
|
||||||
openMarker: '@startgantt',
|
openMarker: '@startgantt',
|
||||||
closeMarker: '@endgantt',
|
closeMarker: '@endgantt',
|
||||||
generateSource: function (umlCode) {
|
generateSource: (umlCode) => parsePlantUml(umlCode, '@startgantt', '@endgantt', 'svg')
|
||||||
const stripTrailingSlash = (url) => url.endsWith('/') ? url.slice(0, -1) : url
|
|
||||||
// Currently PlantUML server doesn't support Ditaa in SVG, so we set the format as PNG at the moment.
|
|
||||||
const serverAddress = stripTrailingSlash(config.preview.plantUMLServerAddress) + '/svg'
|
|
||||||
const s = unescape(encodeURIComponent(umlCode))
|
|
||||||
const zippedCode = deflate.encode64(
|
|
||||||
deflate.zip_deflate(`@startgantt\n${s}\n@endgantt`, 9)
|
|
||||||
)
|
|
||||||
return `${serverAddress}/${zippedCode}`
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Override task item
|
// Override task item
|
||||||
|
|||||||
Reference in New Issue
Block a user