Skip to content

Commit

Permalink
Merge pull request #42 from jannis-baum/issue/41-configurable-markdow…
Browse files Browse the repository at this point in the history
…n-file-extensions

Configurable markdown file-extensions
  • Loading branch information
jannis-baum authored Nov 21, 2023
2 parents ba4e089 + acac8a8 commit c9395e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ following optional keys:
evaluation fails, the title will be *custom title error* and you will see the
error message on the page. The default title are the last two components
joined with the path separator, e.g. `you/file.txt`
- **`"mdExtensions"`**\
An array of file extensions that Vivify will parse as Markdown. All other
files will be displayed as monospaced text with code highlighting if
available. Default Markdown extensions are `['markdown', 'md', 'mdown',
'mdwn', 'mkd', 'mkdn']`

## Usage

Expand Down
1 change: 1 addition & 0 deletions src/parser/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Config = {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
katexOptions?: any;
pageTitle?: string;
mdExtensions?: string[];
};
let config: Config = {};

Expand Down
4 changes: 2 additions & 2 deletions src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export const pathHeading = (path: string) => `# \`${path.replace(homedir(), '~')
export default function parse(src: string, path?: string) {
let md = src;

const mdEndings = ['markdown', 'md', 'mdown', 'mdwn', 'mkd', 'mkdn'];
const mdExtensions = config.mdExtensions ?? ['markdown', 'md', 'mdown', 'mdwn', 'mkd', 'mkdn'];

const fileEnding = path?.split('.')?.at(-1);
if (fileEnding && !mdEndings.includes(fileEnding)) {
if (fileEnding && !mdExtensions.includes(fileEnding)) {
md = `${pathHeading(path!)}\n\n\`\`\`${fileEnding}\n${src}\n\`\`\``;
}

Expand Down

0 comments on commit c9395e0

Please sign in to comment.