Skip to content

Commit

Permalink
feat(#23): support optional KaTeX config file
Browse files Browse the repository at this point in the history
Load settings from an optional `~/.vivify/katex_config.json` file to
apply [supported KaTeX options](https://katex.org/docs/options.html).
  • Loading branch information
Anton Zickler committed Oct 26, 2023
1 parent 2a75262 commit 7ba85bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 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
9 changes: 8 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 @@ -22,7 +29,7 @@ mdit.use(require('markdown-it-inject-linenumbers'));
mdit.use(require('markdown-it-texmath'), {
engine: require('katex'),
delimiters: 'dollars',
katexOptions: { errorColor: '#cc0000', macros: { '\\RR': '\\mathbb{R}' } }
katexOptions: katexConfig
});
/* eslint-enable @typescript-eslint/no-var-requires */
mdit.use(graphviz);
Expand Down

0 comments on commit 7ba85bb

Please sign in to comment.