Skip to content

Commit

Permalink
Merge pull request #24 from anzic0/main
Browse files Browse the repository at this point in the history
Close #23: add support for KaTeX configuration file
  • Loading branch information
jannis-baum authored Oct 26, 2023
2 parents f812f2d + 7ba85bb commit 9fea63e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Vivify brings your (Markdown) files to life in the browser!
support](#editor-support))
- Vivify server starts lazily and automatically shuts down when no more viewers
are connected
- customize KaTeX to your needs by providing available [KaTeX
options](#KaTeX-options)

If you need any additional features, feel free to [open an
issue](https://github.com/jannis-baum/vivify/issues/new/choose) or
[contribute](CONTRIBUTING.md)!

### Markdown

Expand All @@ -25,9 +31,19 @@ Vivify brings your (Markdown) files to life in the browser!
- syntax highlighting for code
- graphviz/dot graphs

If you need any additional features, feel free to [open an
issue](https://github.com/jannis-baum/vivify/issues/new/choose) or
[contribute](CONTRIBUTING.md)!
### KaTeX options

Customize KaTeX to your needs by providing an optional
`~/.vivify/katex_config.json` config file with [available KaTeX
options](https://katex.org/docs/options.html). For example:
```
{
"errorColor": "#cc0000",
"macros": {
"\\RR": "\\mathbb{R}"
}
}
```

## Usage

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
"@viz-js/viz": "^3.1.0",
"express": "^4.18.2",
"highlight.js": "^11.8.0",
"katex": "^0.15.6",
"markdown-it": "^13.0.1",
"markdown-it-anchor": "^8.6.7",
"markdown-it-emoji": "^2.0.2",
"markdown-it-inject-linenumbers": "^0.3.0",
"markdown-it-katex": "^2.0.3",
"markdown-it-texmath": "^1.0.0",
"markdown-it-task-lists": "^2.1.1",
"uuid": "^9.0.0",
"ws": "^8.13.0"
Expand Down
13 changes: 12 additions & 1 deletion src/parser/parser.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { homedir } from 'os';
import fs from 'fs';

import MarkdownIt from 'markdown-it';
import anchor from 'markdown-it-anchor';
import highlight from './highlight';
import graphviz from './dot';

const katexConfigPath = `${homedir()}/.vivify/katex_config.json`;
let katexConfig = {};
if (fs.existsSync(katexConfigPath)) {
katexConfig = JSON.parse(fs.readFileSync(katexConfigPath, 'utf8'));
}

const mdit = new MarkdownIt({
html: true,
highlight: highlight,
Expand All @@ -19,7 +26,11 @@ mdit.use(anchor, {
mdit.use(require('markdown-it-emoji'));
mdit.use(require('markdown-it-task-lists'));
mdit.use(require('markdown-it-inject-linenumbers'));
mdit.use(require('markdown-it-katex'));
mdit.use(require('markdown-it-texmath'), {
engine: require('katex'),
delimiters: 'dollars',
katexOptions: katexConfig
});
/* eslint-enable @typescript-eslint/no-var-requires */
mdit.use(graphviz);

Expand Down
32 changes: 15 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,11 @@ color-name@~1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

commander@^8.0.0:
version "8.3.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66"
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==

[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
Expand Down Expand Up @@ -1501,12 +1506,12 @@ jsonfile@^6.0.1:
optionalDependencies:
graceful-fs "^4.1.6"

katex@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/katex/-/katex-0.6.0.tgz#12418e09121c05c92041b6b3b9fb6bab213cb6f3"
integrity sha512-rS4mY3SvHYg5LtQV6RBcK0if7ur6plyEukAOV+jGGPqFImuzu8fHL6M752iBmRGoUyF0bhZbAPoezehn7xYksA==
katex@^0.15.6:
version "0.15.6"
resolved "https://registry.yarnpkg.com/katex/-/katex-0.15.6.tgz#c4e2f6ced2ac4de1ef6f737fe7c67d3026baa0e5"
integrity sha512-UpzJy4yrnqnhXvRPhjEuLA4lcPn6eRngixW7Q3TJErjg3Aw2PuLFBzTkdUb89UtumxjhHTqL3a5GDGETMSwgJA==
dependencies:
match-at "^0.1.0"
commander "^8.0.0"

levn@^0.4.1:
version "0.4.1"
Expand Down Expand Up @@ -1562,18 +1567,16 @@ markdown-it-inject-linenumbers@^0.3.0:
resolved "https://registry.yarnpkg.com/markdown-it-inject-linenumbers/-/markdown-it-inject-linenumbers-0.3.0.tgz#654364fa7a2dcb5f4461ef6d29d2603b74b29fd7"
integrity sha512-c9ymcXUunjCJ8vNBNrg3JMT5d94IxAy6KHJ891vuZf/go98opU77X5neiVIi9Rer3v+03WYk5913J1pVmJOV0g==

markdown-it-katex@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/markdown-it-katex/-/markdown-it-katex-2.0.3.tgz#d7b86a1aea0b9d6496fab4e7919a18fdef589c39"
integrity sha512-nUkkMtRWeg7OpdflamflE/Ho/pWl64Lk9wNBKOmaj33XkQdumhXAIYhI0WO03GeiycPCsxbmX536V5NEXpC3Ng==
dependencies:
katex "^0.6.0"

markdown-it-task-lists@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/markdown-it-task-lists/-/markdown-it-task-lists-2.1.1.tgz#f68f4d2ac2bad5a2c373ba93081a1a6848417088"
integrity sha512-TxFAc76Jnhb2OUu+n3yz9RMu4CwGfaT788br6HhEDlvWfdeJcLUsxk1Hgw2yJio0OXsxv7pyIPmvECY7bMbluA==

markdown-it-texmath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/markdown-it-texmath/-/markdown-it-texmath-1.0.0.tgz#65703b235d07a8f96bc58cbf9d478af57154e5f0"
integrity sha512-4hhkiX8/gus+6e53PLCUmUrsa6ZWGgJW2XCW6O0ASvZUiezIK900ZicinTDtG3kAO2kon7oUA/ReWmpW2FByxg==

markdown-it@^13.0.1:
version "13.0.1"
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-13.0.1.tgz#c6ecc431cacf1a5da531423fc6a42807814af430"
Expand All @@ -1585,11 +1588,6 @@ markdown-it@^13.0.1:
mdurl "^1.0.1"
uc.micro "^1.0.5"

match-at@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/match-at/-/match-at-0.1.1.tgz#25d040d291777704d5e6556bbb79230ec2de0540"
integrity sha512-h4Yd392z9mST+dzc+yjuybOGFNOZjmXIPKWjxBd1Bb23r4SmDOsk2NYCU2BMUBGbSpZqwVsZYNq26QS3xfaT3Q==

mdurl@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
Expand Down

0 comments on commit 9fea63e

Please sign in to comment.