mirror of
https://github.com/BoostIo/Boostnote
synced 2026-05-31 19:53:06 +00:00
render LaTeX
This commit is contained in:
@@ -6,6 +6,8 @@ var ReactDOM = require('react-dom')
|
|||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const shell = electron.shell
|
const shell = electron.shell
|
||||||
|
|
||||||
|
const katex = window.katex
|
||||||
|
|
||||||
function handleAnchorClick (e) {
|
function handleAnchorClick (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
@@ -17,13 +19,27 @@ function stopPropagation (e) {
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function math2Katex (display) {
|
||||||
|
return function (el) {
|
||||||
|
try {
|
||||||
|
katex.render(el.innerHTML, el, {display: display})
|
||||||
|
el.className = 'math-rendered'
|
||||||
|
} catch (e) {
|
||||||
|
el.innerHTML = e.message
|
||||||
|
el.className = 'math-failed'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default class MarkdownPreview extends React.Component {
|
export default class MarkdownPreview extends React.Component {
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
this.addListener()
|
this.addListener()
|
||||||
|
this.renderMath()
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate () {
|
componentDidUpdate () {
|
||||||
this.addListener()
|
this.addListener()
|
||||||
|
this.renderMath()
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
@@ -34,6 +50,13 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
this.removeListener()
|
this.removeListener()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderMath () {
|
||||||
|
let inline = ReactDOM.findDOMNode(this).querySelectorAll('span.math')
|
||||||
|
Array.prototype.forEach.call(inline, math2Katex(false))
|
||||||
|
let block = ReactDOM.findDOMNode(this).querySelectorAll('div.math')
|
||||||
|
Array.prototype.forEach.call(block, math2Katex(true))
|
||||||
|
}
|
||||||
|
|
||||||
addListener () {
|
addListener () {
|
||||||
var anchors = ReactDOM.findDOMNode(this).querySelectorAll('a:not(.lineAnchor)')
|
var anchors = ReactDOM.findDOMNode(this).querySelectorAll('a:not(.lineAnchor)')
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import markdownit from 'markdown-it'
|
import markdownit from 'markdown-it'
|
||||||
import hljs from 'highlight.js'
|
import hljs from 'highlight.js'
|
||||||
import emoji from 'markdown-it-emoji'
|
import emoji from 'markdown-it-emoji'
|
||||||
|
import math from 'markdown-it-math'
|
||||||
|
|
||||||
var md = markdownit({
|
var md = markdownit({
|
||||||
typographer: true,
|
typographer: true,
|
||||||
@@ -20,6 +21,14 @@ var md = markdownit({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
md.use(emoji)
|
md.use(emoji)
|
||||||
|
md.use(math, {
|
||||||
|
inlineRenderer: function (str) {
|
||||||
|
return `<span class='math'>${str}</span>`
|
||||||
|
},
|
||||||
|
blockRenderer: function (str) {
|
||||||
|
return `<div class='math'>${str}</div>`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
let originalRenderToken = md.renderer.renderToken
|
let originalRenderToken = md.renderer.renderToken
|
||||||
md.renderer.renderToken = function renderToken (tokens, idx, options) {
|
md.renderer.renderToken = function renderToken (tokens, idx, options) {
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
marked()
|
marked()
|
||||||
font-size 14px
|
font-size 14px
|
||||||
|
div.math-rendered
|
||||||
|
text-align center
|
||||||
|
.math-failed
|
||||||
|
background-color alpha(red, 0.1)
|
||||||
|
color darken(red, 15%)
|
||||||
|
padding 5px
|
||||||
|
margin -5px
|
||||||
|
border-radius 5px
|
||||||
a
|
a
|
||||||
color brandColor
|
color brandColor
|
||||||
text-decoration none
|
text-decoration none
|
||||||
|
|||||||
Vendored
+3
-3
@@ -15,9 +15,9 @@
|
|||||||
<style>
|
<style>
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'Lato';
|
font-family: 'Lato';
|
||||||
src: url('../resources/Lato-Regular.woff2') format('woff2'), /* Modern Browsers */
|
src: url('../resources/fonts/Lato-Regular.woff2') format('woff2'), /* Modern Browsers */
|
||||||
url('../resources/Lato-Regular.woff') format('woff'), /* Modern Browsers */
|
url('../resources/fonts/Lato-Regular.woff') format('woff'), /* Modern Browsers */
|
||||||
url('../resources/Lato-Regular.ttf') format('truetype');
|
url('../resources/fonts/Lato-Regular.ttf') format('truetype');
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
text-rendering: optimizeLegibility;
|
text-rendering: optimizeLegibility;
|
||||||
|
|||||||
+6
-3
@@ -9,13 +9,15 @@
|
|||||||
<link rel="stylesheet" href="../node_modules/highlight.js/styles/xcode.css">
|
<link rel="stylesheet" href="../node_modules/highlight.js/styles/xcode.css">
|
||||||
<link rel="shortcut icon" href="../resources/favicon.ico">
|
<link rel="shortcut icon" href="../resources/favicon.ico">
|
||||||
<title>Boostnote</title>
|
<title>Boostnote</title>
|
||||||
|
<link rel="stylesheet" href="../resources/katex.min.css">
|
||||||
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'Lato';
|
font-family: 'Lato';
|
||||||
src: url('../resources/Lato-Regular.woff2') format('woff2'), /* Modern Browsers */
|
src: url('../resources/fonts/Lato-Regular.woff2') format('woff2'), /* Modern Browsers */
|
||||||
url('../resources/Lato-Regular.woff') format('woff'), /* Modern Browsers */
|
url('../resources/fonts/Lato-Regular.woff') format('woff'), /* Modern Browsers */
|
||||||
url('../resources/Lato-Regular.ttf') format('truetype');
|
url('../resources/fonts/Lato-Regular.ttf') format('truetype');
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
text-rendering: optimizeLegibility;
|
text-rendering: optimizeLegibility;
|
||||||
@@ -54,6 +56,7 @@
|
|||||||
<div id="content"></div>
|
<div id="content"></div>
|
||||||
|
|
||||||
<script src="../submodules/ace/src-min/ace.js"></script>
|
<script src="../submodules/ace/src-min/ace.js"></script>
|
||||||
|
<script src="../resources/katex.min.js"></script>
|
||||||
<script type='text/javascript'>
|
<script type='text/javascript'>
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
electron.webFrame.setZoomLevelLimits(1, 1)
|
electron.webFrame.setZoomLevelLimits(1, 1)
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
"lodash": "^3.10.1",
|
"lodash": "^3.10.1",
|
||||||
"markdown-it": "^4.4.0",
|
"markdown-it": "^4.4.0",
|
||||||
"markdown-it-emoji": "^1.1.0",
|
"markdown-it-emoji": "^1.1.0",
|
||||||
|
"markdown-it-math": "^3.0.2",
|
||||||
"md5": "^2.0.0",
|
"md5": "^2.0.0",
|
||||||
"moment": "^2.10.3",
|
"moment": "^2.10.3",
|
||||||
"superagent": "^1.2.0",
|
"superagent": "^1.2.0",
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+6
File diff suppressed because one or more lines are too long
+2
-1
@@ -30,7 +30,8 @@ var config = {
|
|||||||
'moment',
|
'moment',
|
||||||
'highlight.js',
|
'highlight.js',
|
||||||
'markdown-it-emoji',
|
'markdown-it-emoji',
|
||||||
'fs-jetpack'
|
'fs-jetpack',
|
||||||
|
'markdown-it-math'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user