mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
convert uml to utf8 before converting to base64
This commit is contained in:
@@ -8,7 +8,7 @@ import ConfigManager from 'browser/main/lib/ConfigManager'
|
||||
const katex = window.katex
|
||||
const config = ConfigManager.get()
|
||||
|
||||
function createGutter (str) {
|
||||
function createGutter(str) {
|
||||
const lc = (str.match(/\n/g) || []).length
|
||||
const lines = []
|
||||
for (let i = 1; i <= lc; i++) {
|
||||
@@ -31,10 +31,10 @@ var md = markdownit({
|
||||
return `<pre class="sequence">${str}</pre>`
|
||||
}
|
||||
return '<pre class="code">' +
|
||||
createGutter(str) +
|
||||
'<code class="' + lang + '">' +
|
||||
str +
|
||||
'</code></pre>'
|
||||
createGutter(str) +
|
||||
'<code class="' + lang + '">' +
|
||||
str +
|
||||
'</code></pre>'
|
||||
}
|
||||
})
|
||||
md.use(emoji, {
|
||||
@@ -57,7 +57,7 @@ md.use(math, {
|
||||
blockRenderer: function (str) {
|
||||
let output = ''
|
||||
try {
|
||||
output = katex.renderToString(str.trim(), {displayMode: true})
|
||||
output = katex.renderToString(str.trim(), { displayMode: true })
|
||||
} catch (err) {
|
||||
output = `<div class="katex-error">${err.message}</div>`
|
||||
}
|
||||
@@ -76,7 +76,16 @@ md.use(require('markdown-it-named-headers'), {
|
||||
}
|
||||
})
|
||||
md.use(require('markdown-it-kbd'))
|
||||
md.use(require('markdown-it-plantuml'))
|
||||
md.use(require("markdown-it-plantuml"), "", {
|
||||
generateSource: function (umlCode) {
|
||||
var deflate = require("markdown-it-plantuml/lib/deflate")
|
||||
var s = unescape(encodeURIComponent(umlCode))
|
||||
var zippedCode = deflate.encode64(
|
||||
deflate.zip_deflate("@startuml\n" + s + "\n@enduml", 9)
|
||||
);
|
||||
return "http://www.plantuml.com/plantuml/svg/" + zippedCode
|
||||
}
|
||||
})
|
||||
|
||||
// Override task item
|
||||
md.block.ruler.at('paragraph', function (state, startLine/*, endLine */) {
|
||||
@@ -110,7 +119,7 @@ md.block.ruler.at('paragraph', function (state, startLine/*, endLine */) {
|
||||
state.line = nextLine
|
||||
|
||||
token = state.push('paragraph_open', 'p', 1)
|
||||
token.map = [ startLine, state.line ]
|
||||
token.map = [startLine, state.line]
|
||||
|
||||
if (state.parentType === 'list') {
|
||||
const match = content.match(/^\[( |x)\] ?(.+)/i)
|
||||
@@ -121,7 +130,7 @@ md.block.ruler.at('paragraph', function (state, startLine/*, endLine */) {
|
||||
|
||||
token = state.push('inline', '', 0)
|
||||
token.content = content
|
||||
token.map = [ startLine, state.line ]
|
||||
token.map = [startLine, state.line]
|
||||
token.children = []
|
||||
|
||||
token = state.push('paragraph_close', 'p', -1)
|
||||
@@ -131,7 +140,7 @@ md.block.ruler.at('paragraph', function (state, startLine/*, endLine */) {
|
||||
|
||||
// Add line number attribute for scrolling
|
||||
const originalRender = md.renderer.render
|
||||
md.renderer.render = function render (tokens, options, env) {
|
||||
md.renderer.render = function render(tokens, options, env) {
|
||||
tokens.forEach((token) => {
|
||||
switch (token.type) {
|
||||
case 'heading_open':
|
||||
@@ -147,12 +156,12 @@ md.renderer.render = function render (tokens, options, env) {
|
||||
// FIXME We should not depend on global variable.
|
||||
window.md = md
|
||||
|
||||
function normalizeLinkText (linkText) {
|
||||
function normalizeLinkText(linkText) {
|
||||
return md.normalizeLinkText(linkText)
|
||||
}
|
||||
|
||||
const markdown = {
|
||||
render: function markdown (content) {
|
||||
render: function markdown(content) {
|
||||
if (!_.isString(content)) content = ''
|
||||
const renderedContent = md.render(content)
|
||||
return renderedContent
|
||||
|
||||
Reference in New Issue
Block a user