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 katex = window.katex
|
||||||
const config = ConfigManager.get()
|
const config = ConfigManager.get()
|
||||||
|
|
||||||
function createGutter (str) {
|
function createGutter(str) {
|
||||||
const lc = (str.match(/\n/g) || []).length
|
const lc = (str.match(/\n/g) || []).length
|
||||||
const lines = []
|
const lines = []
|
||||||
for (let i = 1; i <= lc; i++) {
|
for (let i = 1; i <= lc; i++) {
|
||||||
@@ -31,10 +31,10 @@ var md = markdownit({
|
|||||||
return `<pre class="sequence">${str}</pre>`
|
return `<pre class="sequence">${str}</pre>`
|
||||||
}
|
}
|
||||||
return '<pre class="code">' +
|
return '<pre class="code">' +
|
||||||
createGutter(str) +
|
createGutter(str) +
|
||||||
'<code class="' + lang + '">' +
|
'<code class="' + lang + '">' +
|
||||||
str +
|
str +
|
||||||
'</code></pre>'
|
'</code></pre>'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
md.use(emoji, {
|
md.use(emoji, {
|
||||||
@@ -57,7 +57,7 @@ md.use(math, {
|
|||||||
blockRenderer: function (str) {
|
blockRenderer: function (str) {
|
||||||
let output = ''
|
let output = ''
|
||||||
try {
|
try {
|
||||||
output = katex.renderToString(str.trim(), {displayMode: true})
|
output = katex.renderToString(str.trim(), { displayMode: true })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
output = `<div class="katex-error">${err.message}</div>`
|
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-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
|
// Override task item
|
||||||
md.block.ruler.at('paragraph', function (state, startLine/*, endLine */) {
|
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
|
state.line = nextLine
|
||||||
|
|
||||||
token = state.push('paragraph_open', 'p', 1)
|
token = state.push('paragraph_open', 'p', 1)
|
||||||
token.map = [ startLine, state.line ]
|
token.map = [startLine, state.line]
|
||||||
|
|
||||||
if (state.parentType === 'list') {
|
if (state.parentType === 'list') {
|
||||||
const match = content.match(/^\[( |x)\] ?(.+)/i)
|
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 = state.push('inline', '', 0)
|
||||||
token.content = content
|
token.content = content
|
||||||
token.map = [ startLine, state.line ]
|
token.map = [startLine, state.line]
|
||||||
token.children = []
|
token.children = []
|
||||||
|
|
||||||
token = state.push('paragraph_close', 'p', -1)
|
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
|
// Add line number attribute for scrolling
|
||||||
const originalRender = md.renderer.render
|
const originalRender = md.renderer.render
|
||||||
md.renderer.render = function render (tokens, options, env) {
|
md.renderer.render = function render(tokens, options, env) {
|
||||||
tokens.forEach((token) => {
|
tokens.forEach((token) => {
|
||||||
switch (token.type) {
|
switch (token.type) {
|
||||||
case 'heading_open':
|
case 'heading_open':
|
||||||
@@ -147,12 +156,12 @@ md.renderer.render = function render (tokens, options, env) {
|
|||||||
// FIXME We should not depend on global variable.
|
// FIXME We should not depend on global variable.
|
||||||
window.md = md
|
window.md = md
|
||||||
|
|
||||||
function normalizeLinkText (linkText) {
|
function normalizeLinkText(linkText) {
|
||||||
return md.normalizeLinkText(linkText)
|
return md.normalizeLinkText(linkText)
|
||||||
}
|
}
|
||||||
|
|
||||||
const markdown = {
|
const markdown = {
|
||||||
render: function markdown (content) {
|
render: function markdown(content) {
|
||||||
if (!_.isString(content)) content = ''
|
if (!_.isString(content)) content = ''
|
||||||
const renderedContent = md.render(content)
|
const renderedContent = md.render(content)
|
||||||
return renderedContent
|
return renderedContent
|
||||||
|
|||||||
Reference in New Issue
Block a user