Skip to content

Commit

Permalink
feat: Lean syntax highlighting in Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Vtec234 committed Oct 15, 2024
1 parent db7b266 commit 603b314
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lean4-infoview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"exports": {
".": "./dist/index.development.js",
"./loader": "./dist/loader.production.min.js",
"./loader": "./dist/loader.development.js",
"./package.json": "./package.json"
},
"typesVersions": {
Expand Down Expand Up @@ -39,10 +39,12 @@
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"current-release": "npm:@leanprover/infoview@latest",
"highlightjs-lean": "^1.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^9.0.1",
"remark-math": "^6.0.0",
"rehype-highlight": "^7.0.0",
"rehype-mathjax": "^6.0.0",
"rollup": "^4.24.0",
"rollup-plugin-css-only": "^4.3.0",
Expand Down
10 changes: 9 additions & 1 deletion lean4-infoview/src/infoview/interactiveCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
TaggedText,
TaggedText_stripTags,
} from '@leanprover/infoview-api'
// @ts-ignore
import leanHljs from 'highlightjs-lean'
import ReactMarkdown from 'react-markdown'
import rehypeHighlight from 'rehype-highlight'
import rehypeMathjax from 'rehype-mathjax'
import remarkMath from 'remark-math'
import { Location } from 'vscode-languageserver-protocol'
Expand Down Expand Up @@ -73,7 +76,12 @@ function Markdown({ contents }: { contents: string }): JSX.Element {
<ReactMarkdown
children={contents}
remarkPlugins={[remarkMath]}
rehypePlugins={[rehypeMathjax]}
rehypePlugins={[
rehypeMathjax,
// NOTE: Instead of rehype-highlight,
// we could use rehype-starrynight with the TextMate grammar in this repo
opts => rehypeHighlight({ ...opts, languages: { lean: leanHljs } }),
]}
components={{
code(props) {
const { children, className, node, ...rest } = props
Expand Down
2 changes: 1 addition & 1 deletion lean4-infoview/src/infoview/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { WithRpcSessions } from './rpcSessions'
import { ServerVersion } from './serverVersion'
import { useClientNotificationEffect, useEventResult, useServerNotificationState } from './util'

function Main(props: {}) {
function Main() {
const ec = React.useContext(EditorContext)

/* Set up updates to the global infoview state on editor events. */
Expand Down
49 changes: 49 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 603b314

Please sign in to comment.