Skip to content

Commit

Permalink
move katex plugin to markdown.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
special-kate committed Dec 11, 2022
1 parent 6f364a4 commit 2814f23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/content-script/index.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import './styles.css'
import './katex.less'
import 'github-markdown-css'
import './katex.less'
import MarkdownItTexmath from "markdown-it-texmath";
import Katex from "katex"

import Browser from 'webextension-polyfill'
import { getMarkdownRenderer } from './markdown.mjs'
import { config } from './search-engine-configs.mjs'
import { getPossibleElementByQuerySelector } from './utils.mjs'

async function run(question, siteConfig) {
const markdown = getMarkdownRenderer().use(MarkdownItTexmath, {
engine: Katex,
delimiters: 'dollars',
katexOptions: { macros: { "\\RR": "\\mathbb{R}" }, throwOnError: false }
})
const markdown = getMarkdownRenderer()

const container = document.createElement('div')
container.className = 'chat-gpt-container'
Expand Down
9 changes: 9 additions & 0 deletions src/content-script/markdown.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import MarkdownIt from 'markdown-it'
import MarkdownItTexmath from 'markdown-it-texmath';
import Katex from 'katex'

export function getMarkdownRenderer() {
const markdown = new MarkdownIt({
Expand Down Expand Up @@ -28,5 +30,12 @@ export function getMarkdownRenderer() {
return defaultRender(tokens, idx, options, env, self)
}

// use katex for math rendering
markdown.use(MarkdownItTexmath, {
engine: Katex,
delimiters: 'dollars',
katexOptions: { macros: { '\\RR': '\\mathbb{R}' }, throwOnError: false }
})

return markdown
}

0 comments on commit 2814f23

Please sign in to comment.