Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Mathjax #362

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dist/mavon-editor.js

This file was deleted.

8,978 changes: 0 additions & 8,978 deletions package-lock.json

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"github-markdown-css": "^2.6.0",
"html-loader": "^0.4.5",
"html-webpack-plugin": "^2.28.0",
"katex": "^0.9.0-alpha1",
"keycode": "^2.1.9",
"less": "^2.7.2",
"less-loader": "^4.0.4",
Expand All @@ -68,8 +67,8 @@
"markdown-it-highlightjs-external": "^1.0.1",
"markdown-it-images-preview": "^1.0.0",
"markdown-it-ins": "^2.0.0",
"markdown-it-katex-external": "^1.0.0",
"markdown-it-mark": "^2.0.0",
"markdown-it-mathjax": "^2.0.0",
"markdown-it-sub": "^1.0.0",
"markdown-it-sup": "^1.0.0",
"markdown-it-task-lists": "^2.1.1",
Expand Down
6 changes: 0 additions & 6 deletions src/dev/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@
},
hljs_lang: function(lang) {
return '/highlightjs/languages/' + lang + '.min.js';
},
katex_css: function() {
return '/katex/katex.min.css';
},
katex_js: function() {
return '/katex/katex.min.js';
}
},
toolbar_settings: {
Expand Down
12 changes: 6 additions & 6 deletions src/lib/core/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import hljsLangs from './hljs/lang.hljs.js'
*/
// default mode
var markdown_config = {
html: true, // Enable HTML tags in source
xhtmlOut: true, // Use '/' to close single tags (<br />).
html: false, // Disable HTML tags in source
xhtmlOut: false, // Don't Use '/' to close single tags (<br />).
breaks: true, // Convert '\n' in paragraphs into <br>
langPrefix: 'language-', // CSS language prefix for fenced blocks. Can be
linkify: false, // 自动识别url
typographer: true,
typographer: false,
quotes: '“”‘’',
highlight: function (str, lang) {
if (lang && hljsLangs[lang]) {
Expand Down Expand Up @@ -68,8 +68,8 @@ markdown.renderer.rules.link_open = function (tokens, idx, options, env, self) {
// pass token to default renderer.
return defaultRender(tokens, idx, options, env, self);
};
// math katex
var katex = require('markdown-it-katex-external');
// mathjax
var mathjax = require('markdown-it-mathjax');
var miip = require('markdown-it-images-preview');
markdown.use(emoji)
.use(taskLists)
Expand All @@ -86,5 +86,5 @@ markdown.use(emoji)
.use(mark)
.use(container)
.use(miip)
.use(katex)
.use(mathjax())
export default markdown
12 changes: 6 additions & 6 deletions src/lib/mixins/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
loadScript
} from '../core/extra-function.js'
var markdown_config = {
html: true, // Enable HTML tags in source
xhtmlOut: true, // Use '/' to close single tags (<br />).
html: false, // Disable HTML tags in source
xhtmlOut: false, // Don't Use '/' to close single tags (<br />).
breaks: true, // Convert '\n' in paragraphs into <br>
langPrefix: 'lang-', // CSS language prefix for fenced blocks. Can be
linkify: false, // 自动识别url
typographer: true,
typographer: false,
quotes: '“”‘’'
}
var markdown = require('markdown-it')(markdown_config);
Expand Down Expand Up @@ -52,8 +52,8 @@ markdown.renderer.rules.link_open = function (tokens, idx, options, env, self) {
return defaultRender(tokens, idx, options, env, self);
};
var mihe = require('markdown-it-highlightjs-external');
// math katex
var katex = require('markdown-it-katex-external');
// mathjax
var mathjax = require('markdown-it-mathjax');
var miip = require('markdown-it-images-preview');
var missLangs = {};
var needLangs = [];
Expand Down Expand Up @@ -82,7 +82,7 @@ markdown.use(mihe, hljs_opts)
.use(mark)
.use(container)
.use(miip)
.use(katex)
.use(mathjax())
.use(taskLists)
.use(toc)

Expand Down
39 changes: 31 additions & 8 deletions src/mavon-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,8 @@ export default {
}
return '';
},
katex_js: function() {
return 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.8.3/katex.min.js';
},
katex_css: function() {
return 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.8.3/katex.min.css';
mathjax_js: function() {
return 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML';
}
},
p_external_link: {}
Expand Down Expand Up @@ -305,8 +302,8 @@ export default {
// 将help添加到末尾
document.body.appendChild(this.$refs.help);
$vm.loadExternalLink('markdown_css', 'css');
$vm.loadExternalLink('katex_css', 'css')
$vm.loadExternalLink('katex_js', 'js', function() {
$vm.loadExternalLink('mathjax_js', 'js', function() {
$vm.initMathJax();
$vm.initLanguage();
$vm.iRender();
})
Expand Down Expand Up @@ -340,7 +337,7 @@ export default {
},
initExternalFuc() {
var $vm = this;
var _external_ = ['markdown_css', 'hljs_js', 'hljs_css', 'hljs_lang', 'katex_js', 'katex_css'];
var _external_ = ['markdown_css', 'hljs_js', 'hljs_css', 'hljs_lang', 'mathjax_js'];
var _type_ = typeof $vm.externalLink;
var _is_object = (_type_ === 'object');
var _is_boolean = (_type_ === 'boolean');
Expand Down Expand Up @@ -564,9 +561,32 @@ export default {
var $vm = this;
$vm.$render(CONFIG[`help_${lang}`], function(res) {
$vm.d_help = res;
if (window.MathJax && window.MathJax.isReady) {
window.MathJax.Hub.Queue(['resetEquationNumbers', MathJax.InputJax.TeX], ['Typeset', window.MathJax.Hub])
}
})
this.d_words = CONFIG[`words_${lang}`];
},
initMathJax() {
if (window.MathJax) {
window.MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: 'AMS' },
},

tex2jax: {
inlineMath: [['$', '$'], ['\\(','\\)']],
displayMath: [['$$', '$$'], ['\\[','\\]']],
processEscapes: true,
processEnvironments: true
},

linebreaks: {
automatic: true
}
})
}
},
// 编辑开关
editableTextarea() {
let text_dom = this.$refs.vNoteTextarea.$refs.vTextarea;
Expand Down Expand Up @@ -599,6 +619,9 @@ export default {
$vm.$render($vm.d_value, function(res) {
// render
$vm.d_render = res;
if (window.MathJax && window.MathJax.isReady) {
window.MathJax.Hub.Queue(['resetEquationNumbers', MathJax.InputJax.TeX], ['Typeset', window.MathJax.Hub])
}
// change回调
if ($vm.change) $vm.change($vm.d_value, $vm.d_render);
// 改变标题导航
Expand Down
3 changes: 0 additions & 3 deletions webpack/webpack.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ module.exports = {
}, {
from: path.resolve(__dirname, '../resources/markdown'),
to: path.resolve(__dirname, '../dist/markdown')
}, {
from: path.resolve(__dirname, '../node_modules/katex/dist'),
to: path.resolve(__dirname, '../dist/katex')
}])
]
}
19 changes: 5 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3553,12 +3553,6 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"

katex@^0.9.0-alpha1:
version "0.9.0"
resolved "https://registry.yarnpkg.com/katex/-/katex-0.9.0.tgz#26a7d082c21d53725422d2d71da9b2d8455fbd4a"
dependencies:
match-at "^0.1.1"

keycode@^2.1.9:
version "2.2.0"
resolved "https://registry.yarnpkg.com/keycode/-/keycode-2.2.0.tgz#3d0af56dc7b8b8e5cba8d0a97f107204eec22b04"
Expand Down Expand Up @@ -3796,14 +3790,15 @@ markdown-it-ins@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/markdown-it-ins/-/markdown-it-ins-2.0.0.tgz#a5aa6a30f1e2f71e9497567cfdff40f1fde67483"

markdown-it-katex-external@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/markdown-it-katex-external/-/markdown-it-katex-external-1.0.0.tgz#78d1786d94df8650e0bea79ffbc0b1f03fd7c606"

markdown-it-mark@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/markdown-it-mark/-/markdown-it-mark-2.0.0.tgz#46a1aa947105aed8188978e0a016179e404f42c7"

markdown-it-mathjax@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/markdown-it-mathjax/-/markdown-it-mathjax-2.0.0.tgz#ae2b4f4c5c719a03f9e475c664f7b2685231d9e9"
integrity sha1-ritPTFxxmgP55HXGZPeyaFIx2ek=

markdown-it-sub@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/markdown-it-sub/-/markdown-it-sub-1.0.0.tgz#375fd6026eae7ddcb012497f6411195ea1e3afe8"
Expand All @@ -3830,10 +3825,6 @@ markdown-it@^8.3.1:
mdurl "^1.0.1"
uc.micro "^1.0.5"

match-at@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/match-at/-/match-at-0.1.1.tgz#25d040d291777704d5e6556bbb79230ec2de0540"

math-expression-evaluator@^1.2.14:
version "1.2.17"
resolved "https://registry.yarnpkg.com/math-expression-evaluator/-/math-expression-evaluator-1.2.17.tgz#de819fdbcd84dccd8fae59c6aeb79615b9d266ac"
Expand Down