Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions functions/chips/[shuttle]/[project]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ export const onRequestGet: PagesFunction<Env> = async (context) => {
`<meta property="og:image:width" content="1200" />`,
`<meta property="og:image:height" content="630" />`,
'<meta name="twitter:card" content="summary_large_image"/>',

// if this stylesheet is missing, then the equation text is duplicated on page
// see https://katex.org/docs/browser
`<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"
integrity="sha384-Pu5+C18nP5dwykLJOhd2U4Xen7rjScHN/qusop27hdd2drI+lL5KvX7YntvT8yew" crossorigin="anonymous">`,
`<link href="/css/katex.css" rel="stylesheet">`,
].join('\n'),
)
.replaceAll('__ttreplace_shuttle_id__', shuttle)
Expand Down
12 changes: 11 additions & 1 deletion functions/components/ProjectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import MarkdownIt from 'markdown-it';
import React from 'react';
import katex from 'katex';
import { IProjectFeedbackList, summarizeFeedback } from '../model/feedback.js';
import { markdownHeadingLimiter, markdownImagePathTransformer } from '../model/project.js';
import { getShuttlePdk, scanchainShuttles, type IShuttleIndexProject } from '../model/shuttle.js';
Expand All @@ -27,7 +28,16 @@ export function ProjectPage({
feedback,
shuttleMapSvg,
}: IProjectPropProps) {
const md = MarkdownIt();
const md = MarkdownIt().use(require('markdown-it-texmath'), {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is using require('markdown-it-texmath') correct here? I tried using import but it wasn't auto-completing - I'm assuming I'm missing some type files for it?

engine: katex,
// see https://katex.org/docs/options for all options
katexOptions: {
throwOnError: true,
strict: true, // be faithful to LaTeX math
trust: false, // prevent commands which cause adverse behaviour
maxSize: 80,
},
});

// Add base URL to image paths
md.renderer.rules['image'] = markdownImagePathTransformer(shuttle, project.macro);
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
},
"dependencies": {
"@cloudflare/pages-plugin-vercel-og": "^0.1.2",
"katex": "^0.16.27",
"markdown-it": "^14.1.0",
"markdown-it-texmath": "^1.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
11 changes: 11 additions & 0 deletions static/css/katex.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* set font-size to match the rest of the content (https://katex.org/docs/font) */
.katex {
font-size: 1em;
}

/* hide equation numbering - this isn't supported in the datasheet, so to avoid confusion i'll just hide it
there is no option to toggle it, see https://github.com/KaTeX/KaTeX/discussions/3180
*/
.eqn-num {
display: none !important;
}