Skip to content

Commit

Permalink
feat(#16): introduce config
Browse files Browse the repository at this point in the history
  • Loading branch information
jannis-baum committed Oct 26, 2023
1 parent e0386a1 commit a6131b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
26 changes: 26 additions & 0 deletions src/parser/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import fs from 'fs';
import { homedir } from 'os';
import path from 'path';

type Config = {
styles?: string;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
katexOptions?: any;
pageTitle?: string;
};
let config: Config = {};

const configPaths = [
path.join(homedir(), '.vivify', 'config.json'),
path.join(homedir(), '.vivify.json'),
];

for (const cp of configPaths) {
if (!fs.existsSync(cp)) continue;
try {
config = JSON.parse(fs.readFileSync(cp, 'utf8'));
break;
} catch {}
}

export default config;
10 changes: 2 additions & 8 deletions src/parser/parser.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
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'));
}
import config from './config';

const mdit = new MarkdownIt({
html: true,
Expand All @@ -29,7 +23,7 @@ mdit.use(require('markdown-it-inject-linenumbers'));
mdit.use(require('markdown-it-texmath'), {
engine: require('katex'),
delimiters: 'dollars',
katexOptions: katexConfig,
katexOptions: config.katexOptions,
});
/* eslint-enable @typescript-eslint/no-var-requires */
mdit.use(graphviz);
Expand Down

0 comments on commit a6131b5

Please sign in to comment.