Skip to content

Instantly share code, notes, and snippets.

@3846masa
Last active August 16, 2022 14:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 3846masa/cde99a18a8d7ad225cf7 to your computer and use it in GitHub Desktop.
Save 3846masa/cde99a18a8d7ad225cf7 to your computer and use it in GitHub Desktop.
#vscode Visual Studio Codeのmarkdownでmathjaxを使えるようにするパッチ(仮)

Visual Studio Codeのmarkdownでmathjaxを使えるようにするパッチ(仮)

無保証

導入方法

  • markdownWorker.js にパッチを当てる
    • WindowsではC:\Users\{USER}\AppData\Local\Code\app-0.1.0\resources\app\client\vs\languages\markdown
    • パッチを当てる前に,js-beautifyで整形してください
patch -u markdownWorker.js mathjax.patch

追伸

markdownWorker.js

sed -e 's/"Segoe WPC",/"Meiryo", "Segoe WPC",/'

すると,日本語表示がよくなります.

--- origin.js 2015-04-30 07:56:33.102179400 +0900
+++ fixed.js 2015-04-30 07:58:05.251312400 +0900
@@ -154,6 +154,7 @@
var block = {
newline: /^\n+/,
code: /^( {4}[^\n]+\n*)+/,
+ mathjax: /^ *(\${2}) *([\s\S]+?)\s*\1 *(?:\n+|$)/,
fences: noop,
hr: /^( *[-*_]){3,} *(?:\n+|$)/,
heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
@@ -186,7 +187,12 @@
type: "code",
text: this.options.pedantic ? t : t.replace(/\n+$/, "")
});
- else if (t = this.rules.fences.exec(e)) e = e.substring(t[0].length), this.tokens.push({
+ else if (t = this.rules.mathjax.exec(e)) e = e.substring(t[0].length), this.tokens.push({
+ type: "html",
+ pre: true,
+ text: t[0]
+ });
+ else if (t = this.rules.fences.exec(e)) e = e.substring(t[0].length), this.tokens.push({
type: "code",
lang: t[2],
text: t[3]
@@ -270,9 +276,10 @@
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
+ mathjax: /^(\${1,2})\s*([\s\S]*?[^\$])\s*\1(?!\$)/,
br: /^ {2,}\n(?!\s*$)/,
del: noop,
- text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
+ text: /^[\s\S]+?(?=[\\<!\[_*`\$]| {2,}\n|$)/
};
inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/, inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/, inline.link = replace(inline.link)("inside", inline._inside)("href", inline._href)(), inline.reflink = replace(inline.reflink)("inside", inline._inside)(), inline.normal = merge({}, inline), inline.pedantic = merge({}, inline.normal, {
strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
@@ -307,6 +314,7 @@
} else if (o = this.rules.strong.exec(e)) e = e.substring(o[0].length), t += this.renderer.strong(this.output(o[2] || o[1]));
else if (o = this.rules.em.exec(e)) e = e.substring(o[0].length), t += this.renderer.em(this.output(o[2] || o[1]));
else if (o = this.rules.code.exec(e)) e = e.substring(o[0].length), t += this.renderer.codespan(escape(o[2], !0));
+ else if (o = this.rules.mathjax.exec(e)) e = e.substring(o[0].length), t += o[0];
else if (o = this.rules.br.exec(e)) e = e.substring(o[0].length), t += this.renderer.br();
else if (o = this.rules.del.exec(e)) e = e.substring(o[0].length), t += this.renderer.del(this.output(o[1]));
else if (o = this.rules.text.exec(e)) e = e.substring(o[0].length), t += escape(this.smartypants(o[0]));
@@ -531,7 +539,7 @@
}, function(a, l) {
var c = ["<!DOCTYPE html>", "<html>", "<head>", '<base href="' + o + '" />', '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">', 0 !== i.length || n.isMacintosh ? "" : t.theme === h.LIGHT ? r.LIGHT_SCROLLBAR_CSS : r.DARK_SCROLLBAR_CSS, 0 === i.length ? r.DEFAULT_CSS : "", i.map(function(r) {
return '<link rel="stylesheet" href="' + t.fixHref(e, r, o) + '" type="text/css" media="screen">'
- }).join("\n"), '<style type="text/css">' + r.LANGUAGE_TOKENS_CSS + "</style>", "</head>", "<body>"].join("\n"),
+ }).join("\n"), '<style type="text/css">' + r.LANGUAGE_TOKENS_CSS + "</style>", '<script type="text/x-mathjax-config">', "MathJax.Hub.Config({", "showProcessingMessages:false,", "tex2jax:{inlineMath:[['$','$'],['\\\\(','\\\\)']]},", "TeX:{equationNumbers:{autoNumber:'AMS'}}", "});", "document.addEventListener('DOMSubtreeModified',function(){MathJax.Hub.Queue(['Typeset',MathJax.Hub]);},false);", "</script>", '<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>', "</head>", "<body>"].join("\n"),
d = [t.theme === h.LIGHT ? '<div class="vs">' : '<div class="vs-dark">', l, "</div>"].join("\n"),
u = ["</body>", "</html>"].join("\n");
s({
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment