Skip to content

Commit

Permalink
Version 2.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
goessner committed Nov 13, 2018
1 parent e9edd46 commit e3e3ab1
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 79 deletions.
10 changes: 6 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## CHANGELOG

### [2.3.4]() (Awaiting Review) on October 25, 2018
* Command to save HTML to file
* Autosave option for saving HTML when Markdown file is changed
* Ability to configure where HTML files are saved
### [2.3.5]() on October 25, 2018
* Implemented macros supported by KaTeX.
* Command to save HTML to file.
* Autosave option for saving HTML when Markdown file is changed.
* Ability to configure where HTML files are saved.
* `katex` dependency upgrade to `0.10.0`.

### [2.3.3]() on September 07, 2018
* Add support for [Kramdown](https://kramdown.gettalong.org/) . Simply write `"mdmath.delimiters": "kramdown"` into your user settings for activating it. Please note, that syntax highlighting is only properly supported with `dollars`.
Expand Down
13 changes: 11 additions & 2 deletions css/texmath.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
/* style for html inside of browsers */
.katex { font-size: 1em !important; } /* align KaTeX font-size to surrounding text */
/* align KaTeX font-size to surrounding text */
.katex { font-size: 1em !important; }
/* supress effect of display formulas with eqno having bigger margin */
.katex-display { margin:0 !important; }
/* overwrite github-markdown.css asymmetric margin values */
.markdown-body blockquote, .markdown-body dl, .markdown-body ol, .markdown-body p, .markdown-body pre, .markdown-body table, .markdown-body ul {
margin-top: 8px;
margin-bottom: 8px;
}

eq { display: inline-block; }
eqn { display: block}
eqn { display: block; margin: 0; }
section.eqno {
display: flex;
flex-direction: row;
align-content: space-between;
align-items: center;

}
section.eqno > eqn {
width: 100%;
Expand Down
17 changes: 16 additions & 1 deletion css/vscode-texmath.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
p { text-align: justify; }

table, figure {
table {
display: table !important;
width: auto !important;
margin-left: auto !important;
margin-right: auto !important;
border-collapse: collapse !important;
}

table th, table td {
border-left: none !important;
border-right: none !important;
border-top: 1px solid #000 !important;
border-bottom: 1px solid #000 !important;
}

figure {
margin: 0.5em auto;
}
figure > img {
Expand Down
109 changes: 58 additions & 51 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
'use strict';

const vscode = require('vscode'),
clipTmpl = (html,usrcss) => `<!doctype html><html><head><meta charset='utf-8'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.4.1/github-markdown.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/styles/default.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]-rc.1/dist/katex.min.css" integrity="sha384-D+9gmBxUQogRLqvARvNLmA9hS2x//eK1FhVb9PiU86gmcrBrJAQT8okdJ4LMp2uv" crossorigin="anonymous">
htmlTmpl = (html,usrcss) => `<!doctype html><html><head><meta charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-9eLZqc9ds8eNjO3TmqPeYcDj8n+Qfa4nuSiGYa6DjLNcv9BtN69ZIulL9+8CqC9Y" crossorigin="anonymous">
<link rel="stylesheet" href="https://gitcdn.xyz/repo/goessner/mdmath/master/css/texmath.css">
<link rel="stylesheet" href="https://gitcdn.xyz/repo/goessner/mdmath/master/css/vscode-texmath.css">
${usrcss ? `<link rel="stylesheet" href="${usrcss}">` : ''}
Expand All @@ -18,89 +18,96 @@ ${html}

// this method is called when extension is activated ..
exports.activate = function activate(context) {
let mdit = null,
cb = null,
mkdirp = null,
watchingFs = false;

const kt = require('katex'),
tm = require('markdown-it-texmath').use(kt),
path = require('path'),
fs = require('fs'),
mkdirp = require('mkdirp').sync,
cfg = (key) => vscode.workspace.getConfiguration('mdmath')[key],
delimiters = cfg('delimiters') || 'dollars',
macros = JSON.parse(JSON.stringify(cfg('macros'))), // wondering why this JSON stuff is necessary
options = Object.keys(macros).length !== 0 ? {delimiters,macros} : {delimiters},
runIf = (cond, f) => {
return () => {
cond() && f()
}
},
infoMsg = (msg) => {
vscode.window.showInformationMessage(`Markdown + Math: ${msg}`);
vscode.window.showInformationMessage(`Markdown + Math: ${msg}`);
},
errMsg = (msg) => {
vscode.window.showErrorMessage(`Markdown + Math: ${msg}`);
vscode.window.showErrorMessage(`Markdown + Math: ${msg}`);
},
makeHTML = () => {
const doc = vscode.window.activeTextEditor && vscode.window.activeTextEditor.document;
if (!doc || doc.languageId !== 'markdown')
return infoMsg('Active document is no markdown source document!');
if (!mdit)
return infoMsg('Corresponding markdown preview document needs to be opened at least once!');
const doc = vscode.window.activeTextEditor
&& vscode.window.activeTextEditor.document;
if (!doc || doc.languageId !== 'markdown')
return infoMsg('Active document is no markdown source document!');
if (!mdit)
return infoMsg('Corresponding markdown preview document needs to be opened at least once!');

return clipTmpl(mdit.render(doc.getText()))

return htmlTmpl(mdit.render(doc.getText()))
},
outputLocationOf = (fsPath) => {
const root = vscode.workspace.getWorkspaceFolder(fsPath) || vscode.workspace.rootPath,
parsed = path.parse(fsPath),
savePath = cfg('savePath')
.replace('${file.name}', parsed.name)
.replace('${file.ext}', parsed.ext),
out = savePath.startsWith('/') ? path.resolve(root, `.${savePath}`) : path.resolve(parsed.dir, savePath);
const root = vscode.workspace.getWorkspaceFolder(fsPath) || vscode.workspace.rootPath,
parsed = path.parse(fsPath),
savePath = cfg('savePath')
.replace('${file.name}', parsed.name)
.replace('${file.ext}', parsed.ext),
out = savePath.startsWith('/') ? path.resolve(root, `.${savePath}`) : path.resolve(parsed.dir, savePath);

return path.isAbsolute(out) ? out : path.resolve(parsed.dir, `./${parsed.name}.html`);
return path.isAbsolute(out) ? out : path.resolve(parsed.dir, `./${parsed.name}.html`);
},
clip = () => {
if (!cb) cb = require('clipboardy');
cb.write(makeHTML())
.then(()=>infoMsg('Html copied to clipboard!'),
(err)=>errMsg('Html copying to clipboard failed: ' + err.message));
if (!cb) cb = require('clipboardy');
cb.write(makeHTML())
.then(()=>infoMsg('Html copied to clipboard!'),
(err)=>errMsg('Html copying to clipboard failed: ' + err.message));
},
save = (uri) => {
try {
uri = uri || vscode.window.activeTextEditor._documentData._uri;
try {
uri = uri || vscode.window.activeTextEditor.document.uri;
if (!watchingFs) // lazy activate fileSystemWatcher ... !
watchingFs = watch(vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(path.dirname(uri.fsPath), '**/*.md')));

const dest = outputLocationOf(uri.fsPath);


if (!mkdirp) mkdirp = require('mkdirp').sync;

mkdirp(path.parse(dest).dir);

fs.writeFileSync(dest, makeHTML(), 'UTF-8');
infoMsg(`Html saved to ${dest}!`);
} catch (err) {
} catch (err) {
errMsg('Saving html failed: ' + err.message);
}

}
},
watch = (watcher) => {
const autosave = runIf(() => { return cfg('autosave') }, save);
watcher.onDidChange(autosave);
watcher.onDidCreate(autosave);
watcher.onDidDelete((uri) => {
try {
const dest = outputLocationOf(uri.fsPath);
fs.unlinkSync(dest);
infoMsg(`Removed ${dest}.`);
} catch (err) {
errMsg('Removing file failed: ' + err.message);
}
});
return true;
};
let mdit = null,
cb = null;


((watcher) => {
const autosave = runIf(() => { return cfg('autosave') }, save);
watcher.onDidChange(autosave); watcher.onDidCreate(autosave);
watcher.onDidDelete((uri) => {
try {
const dest = outputLocationOf(uri.fsPath);
fs.unlinkSync(dest);
infoMsg(`Removed ${dest}.`);
} catch (err) {
errMsg('Removing file failed: ' + err.message);
}
});

})(vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(vscode.workspace.rootPath, '**/*.md')));

context.subscriptions.push(vscode.commands.registerCommand('extension.clipToHtml', clip));
context.subscriptions.push(vscode.commands.registerCommand('extension.renderToHtml', save));
context.subscriptions.push(vscode.commands.registerCommand('extension.saveToHtml', save));

return {
extendMarkdownIt: function(md) {
return (mdit = md).use(tm, {delimiters:delimiters});
return (mdit = md).use(tm, options);
}
}
}
Expand Down
26 changes: 17 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "mdmath",
"displayName": "Markdown+Math",
"description": "LaTeX Math for Markdown",
"icon": "img/icon.png",
"version": "2.3.4",
"icon": "./img/icon.png",
"version": "2.3.5",
"author": "Stefan Goessner",
"publisher": "goessner",
"keywords": [
Expand Down Expand Up @@ -45,6 +45,14 @@
"default": "dollars",
"description": "Math formula delimiters."
},
"mdmath.macros": {
"type": "object",
"default": {
"\\RR": "\\mathbb{R}",
"\\vek": "{\\begin{pmatrix}#1\\\\#2\\end{pmatrix}}"
},
"description": "TeX macros definition."
},
"mdmath.savePath": {
"type": "string",
"default": "./${file.name}.html",
Expand All @@ -70,7 +78,7 @@
"category": "Markdown"
},
{
"command": "extension.renderToHtml",
"command": "extension.saveToHtml",
"title": "Save Markdown+Math to HTML",
"category": "Markdown"
}
Expand All @@ -82,7 +90,7 @@
"when": "editorTextFocus"
},
{
"command": "extension.renderToHtml",
"command": "extension.saveToHtml",
"key": "ctrl+K ,",
"when": "editorTextFocus"
}
Expand Down Expand Up @@ -117,16 +125,16 @@
"argparse": "^1.0.9",
"clipboardy": "^1.1.2",
"cross-spawn": "^6.0.1",
"entities": "^1.1.1",
"entities": "^1.1.2",
"execa": "^1.0.0",
"get-stream": "^4.0.0",
"get-stream": "^4.1.0",
"is-stream": "^1.1.0",
"isexe": "^2.0.0",
"katex": "^0.10.0-rc.1",
"katex": "^0.10.0",
"linkify-it": "^2.0.3",
"lru-cache": "^4.1.3",
"markdown-it": "^8.4.2",
"markdown-it-texmath": "^0.5.2",
"markdown-it-texmath": "^0.5.3",
"match-at": "^0.1.0",
"mdurl": "^1.0.1",
"mkdirp": "^0.5.1",
Expand All @@ -138,7 +146,7 @@
"shebang-regex": "^2.0.0",
"signal-exit": "^3.0.0",
"sprintf-js": "^1.1.1",
"strip-eof": "^1.0.0",
"strip-eof": "^2.0.0",
"uc.micro": "^1.0.3",
"which": "^1.3.1",
"yallist": "^3.0.0"
Expand Down
Loading

0 comments on commit e3e3ab1

Please sign in to comment.