mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-12 17:26:17 +00:00
render LaTeX
This commit is contained in:
@@ -6,6 +6,8 @@ var ReactDOM = require('react-dom')
|
||||
const electron = require('electron')
|
||||
const shell = electron.shell
|
||||
|
||||
const katex = window.katex
|
||||
|
||||
function handleAnchorClick (e) {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
@@ -17,13 +19,27 @@ function stopPropagation (e) {
|
||||
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 {
|
||||
componentDidMount () {
|
||||
this.addListener()
|
||||
this.renderMath()
|
||||
}
|
||||
|
||||
componentDidUpdate () {
|
||||
this.addListener()
|
||||
this.renderMath()
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
@@ -34,6 +50,13 @@ export default class MarkdownPreview extends React.Component {
|
||||
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 () {
|
||||
var anchors = ReactDOM.findDOMNode(this).querySelectorAll('a:not(.lineAnchor)')
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import markdownit from 'markdown-it'
|
||||
import hljs from 'highlight.js'
|
||||
import emoji from 'markdown-it-emoji'
|
||||
import math from 'markdown-it-math'
|
||||
|
||||
var md = markdownit({
|
||||
typographer: true,
|
||||
@@ -20,6 +21,14 @@ var md = markdownit({
|
||||
}
|
||||
})
|
||||
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
|
||||
md.renderer.renderToken = function renderToken (tokens, idx, options) {
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
marked()
|
||||
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
|
||||
color brandColor
|
||||
text-decoration none
|
||||
|
||||
0
katex.min.css
vendored
Normal file
0
katex.min.css
vendored
Normal file
@@ -15,9 +15,9 @@
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'Lato';
|
||||
src: url('../resources/Lato-Regular.woff2') format('woff2'), /* Modern Browsers */
|
||||
url('../resources/Lato-Regular.woff') format('woff'), /* Modern Browsers */
|
||||
url('../resources/Lato-Regular.ttf') format('truetype');
|
||||
src: url('../resources/fonts/Lato-Regular.woff2') format('woff2'), /* Modern Browsers */
|
||||
url('../resources/fonts/Lato-Regular.woff') format('woff'), /* Modern Browsers */
|
||||
url('../resources/fonts/Lato-Regular.ttf') format('truetype');
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
text-rendering: optimizeLegibility;
|
||||
|
||||
@@ -9,13 +9,15 @@
|
||||
<link rel="stylesheet" href="../node_modules/highlight.js/styles/xcode.css">
|
||||
<link rel="shortcut icon" href="../resources/favicon.ico">
|
||||
<title>Boostnote</title>
|
||||
<link rel="stylesheet" href="../resources/katex.min.css">
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'Lato';
|
||||
src: url('../resources/Lato-Regular.woff2') format('woff2'), /* Modern Browsers */
|
||||
url('../resources/Lato-Regular.woff') format('woff'), /* Modern Browsers */
|
||||
url('../resources/Lato-Regular.ttf') format('truetype');
|
||||
src: url('../resources/fonts/Lato-Regular.woff2') format('woff2'), /* Modern Browsers */
|
||||
url('../resources/fonts/Lato-Regular.woff') format('woff'), /* Modern Browsers */
|
||||
url('../resources/fonts/Lato-Regular.ttf') format('truetype');
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
text-rendering: optimizeLegibility;
|
||||
@@ -54,6 +56,7 @@
|
||||
<div id="content"></div>
|
||||
|
||||
<script src="../submodules/ace/src-min/ace.js"></script>
|
||||
<script src="../resources/katex.min.js"></script>
|
||||
<script type='text/javascript'>
|
||||
const electron = require('electron')
|
||||
electron.webFrame.setZoomLevelLimits(1, 1)
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
"lodash": "^3.10.1",
|
||||
"markdown-it": "^4.4.0",
|
||||
"markdown-it-emoji": "^1.1.0",
|
||||
"markdown-it-math": "^3.0.2",
|
||||
"md5": "^2.0.0",
|
||||
"moment": "^2.10.3",
|
||||
"superagent": "^1.2.0",
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
resources/fonts/KaTeX_AMS-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_AMS-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_AMS-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_AMS-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_AMS-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_AMS-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_AMS-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_AMS-Regular.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Caligraphic-Bold.eot
Normal file
BIN
resources/fonts/KaTeX_Caligraphic-Bold.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Caligraphic-Bold.ttf
Normal file
BIN
resources/fonts/KaTeX_Caligraphic-Bold.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Caligraphic-Bold.woff
Normal file
BIN
resources/fonts/KaTeX_Caligraphic-Bold.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Caligraphic-Bold.woff2
Normal file
BIN
resources/fonts/KaTeX_Caligraphic-Bold.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Caligraphic-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_Caligraphic-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Caligraphic-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_Caligraphic-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Caligraphic-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_Caligraphic-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Caligraphic-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_Caligraphic-Regular.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Fraktur-Bold.eot
Normal file
BIN
resources/fonts/KaTeX_Fraktur-Bold.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Fraktur-Bold.ttf
Normal file
BIN
resources/fonts/KaTeX_Fraktur-Bold.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Fraktur-Bold.woff
Normal file
BIN
resources/fonts/KaTeX_Fraktur-Bold.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Fraktur-Bold.woff2
Normal file
BIN
resources/fonts/KaTeX_Fraktur-Bold.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Fraktur-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_Fraktur-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Fraktur-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_Fraktur-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Fraktur-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_Fraktur-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Fraktur-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_Fraktur-Regular.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Bold.eot
Normal file
BIN
resources/fonts/KaTeX_Main-Bold.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Bold.ttf
Normal file
BIN
resources/fonts/KaTeX_Main-Bold.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Bold.woff
Normal file
BIN
resources/fonts/KaTeX_Main-Bold.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Bold.woff2
Normal file
BIN
resources/fonts/KaTeX_Main-Bold.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Italic.eot
Normal file
BIN
resources/fonts/KaTeX_Main-Italic.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Italic.ttf
Normal file
BIN
resources/fonts/KaTeX_Main-Italic.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Italic.woff
Normal file
BIN
resources/fonts/KaTeX_Main-Italic.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Italic.woff2
Normal file
BIN
resources/fonts/KaTeX_Main-Italic.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_Main-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_Main-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_Main-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Main-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_Main-Regular.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-BoldItalic.eot
Normal file
BIN
resources/fonts/KaTeX_Math-BoldItalic.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-BoldItalic.ttf
Normal file
BIN
resources/fonts/KaTeX_Math-BoldItalic.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-BoldItalic.woff
Normal file
BIN
resources/fonts/KaTeX_Math-BoldItalic.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-BoldItalic.woff2
Normal file
BIN
resources/fonts/KaTeX_Math-BoldItalic.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-Italic.eot
Normal file
BIN
resources/fonts/KaTeX_Math-Italic.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-Italic.ttf
Normal file
BIN
resources/fonts/KaTeX_Math-Italic.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-Italic.woff
Normal file
BIN
resources/fonts/KaTeX_Math-Italic.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-Italic.woff2
Normal file
BIN
resources/fonts/KaTeX_Math-Italic.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_Math-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_Math-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_Math-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Math-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_Math-Regular.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Bold.eot
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Bold.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Bold.ttf
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Bold.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Bold.woff
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Bold.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Bold.woff2
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Bold.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Italic.eot
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Italic.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Italic.ttf
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Italic.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Italic.woff
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Italic.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Italic.woff2
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Italic.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_SansSerif-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_SansSerif-Regular.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Script-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_Script-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Script-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_Script-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Script-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_Script-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Script-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_Script-Regular.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size1-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_Size1-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size1-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_Size1-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size1-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_Size1-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size1-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_Size1-Regular.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size2-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_Size2-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size2-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_Size2-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size2-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_Size2-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size2-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_Size2-Regular.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size3-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_Size3-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size3-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_Size3-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size3-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_Size3-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size3-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_Size3-Regular.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size4-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_Size4-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size4-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_Size4-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size4-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_Size4-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Size4-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_Size4-Regular.woff2
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Typewriter-Regular.eot
Normal file
BIN
resources/fonts/KaTeX_Typewriter-Regular.eot
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Typewriter-Regular.ttf
Normal file
BIN
resources/fonts/KaTeX_Typewriter-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Typewriter-Regular.woff
Normal file
BIN
resources/fonts/KaTeX_Typewriter-Regular.woff
Normal file
Binary file not shown.
BIN
resources/fonts/KaTeX_Typewriter-Regular.woff2
Normal file
BIN
resources/fonts/KaTeX_Typewriter-Regular.woff2
Normal file
Binary file not shown.
1
resources/katex.min.css
vendored
Normal file
1
resources/katex.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
6
resources/katex.min.js
vendored
Normal file
6
resources/katex.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -30,7 +30,8 @@ var config = {
|
||||
'moment',
|
||||
'highlight.js',
|
||||
'markdown-it-emoji',
|
||||
'fs-jetpack'
|
||||
'fs-jetpack',
|
||||
'markdown-it-math'
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user