-
Notifications
You must be signed in to change notification settings - Fork 3
Add equation support (KaTeX) #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import { | |
| import RichTextSpan from 'src/components/rich-text' | ||
| import Code from 'src/components/code' | ||
| import blogConfig from 'blog.config' | ||
| import katex from 'katex' | ||
|
|
||
| type Props = { | ||
| post: BlogPost | ||
|
|
@@ -302,6 +303,17 @@ function getElements(blocks, level = 0): JSX.Element[] { | |
| </div> | ||
| ) | ||
| break | ||
| case 'equation': | ||
| elements.push( | ||
| <div key={block.id} style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }} | ||
| dangerouslySetInnerHTML={{ | ||
| __html: katex.renderToString(block.equation.expression, { | ||
| throwOnError: false | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you find that this code would often throw exceptions? I'm not sure if it's better to create an error on invalid equation content, or to ignore it and keep going. |
||
| }) | ||
| }} | ||
| /> | ||
| ) | ||
| break | ||
| case 'column': | ||
| throw new Error( | ||
| `'column' type found in elements list, which should not happen.` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -701,7 +701,7 @@ combined-stream@^1.0.8: | |
| dependencies: | ||
| delayed-stream "~1.0.0" | ||
|
|
||
| commander@^8.2.0: | ||
| commander@^8.0.0, commander@^8.2.0: | ||
| version "8.3.0" | ||
| resolved "https://registry.yarnpkg.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66" | ||
| integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww== | ||
|
|
@@ -1565,6 +1565,13 @@ json5@^1.0.1: | |
| dependencies: | ||
| minimist "^1.2.0" | ||
|
|
||
| katex@^0.15.3: | ||
| version "0.15.3" | ||
| resolved "https://registry.yarnpkg.com/katex/-/katex-0.15.3.tgz#08781a7ed26800b20380d959d1ffcd62bca0ec14" | ||
| integrity sha512-Al6V7RJsmjklT9QItyHWGaQCt+NYTle1bZwB1e9MR/tLoIT1MXaHy9UpfGSB7eaqDgjjqqRxQOaQGrALCrEyBQ== | ||
| dependencies: | ||
| commander "^8.0.0" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer not to downgrade a dependency just because a new dependency needs an older version. Is this absolutely required for katex to function? It seems a bit strange for a CLI argument parser library to be required when we're not using the CLI explicitly. |
||
|
|
||
| lines-and-columns@^1.1.6: | ||
| version "1.1.6" | ||
| resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you create a
.equationclass inside ofblog.module.csswhich contains these CSS declarations?