Skip to content

Commit cf958ba

Browse files
SamyPessegregberge
andauthored
Fallback to MathJax when KaTeX fails to compile math (#303)
* Start * Use MathJax v3 * Format * Improve font-size * Lint * Better handle loading * Copy MathJax assets to public folder * Attempt at using local assets for MathJax * Use bun 1.0.31 * Try with bun 1.0.33 * Try fixing headers * Simplify * Simplify and not use suspense module * Cleanup more * Add test for Math * Make math block scroll if needed * Update packages/react-math/src/KaTeX.tsx Co-authored-by: Greg Bergé <berge.greg@gmail.com> * Use React.use * Format * Use exports * Lint * Disable cache in CI for lint * Format --------- Co-authored-by: Greg Bergé <berge.greg@gmail.com>
1 parent 85a32fd commit cf958ba

File tree

31 files changed

+363
-187
lines changed

31 files changed

+363
-187
lines changed

.eslintrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
"pattern": "@/**",
1414
"group": "external",
1515
"position": "after"
16+
},
17+
{
18+
"pattern": "@gitbook/**",
19+
"group": "external",
20+
"position": "after"
1621
}
1722
],
1823
"alphabetize": {

.github/workflows/ci.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Setup bun
1717
uses: oven-sh/setup-bun@v1
1818
with:
19-
bun-version: 1.0.30
19+
bun-version: 1.0.33
2020
- name: Install dependencies
2121
run: bun install --frozen-lockfile
2222
env:
@@ -78,7 +78,7 @@ jobs:
7878
- name: Setup bun
7979
uses: oven-sh/setup-bun@v1
8080
with:
81-
bun-version: 1.0.30
81+
bun-version: 1.0.33
8282
- name: Install dependencies
8383
run: bun install --frozen-lockfile
8484
- name: Setup Playwright
@@ -98,7 +98,7 @@ jobs:
9898
- name: Setup bun
9999
uses: oven-sh/setup-bun@v1
100100
with:
101-
bun-version: 1.0.30
101+
bun-version: 1.0.33
102102
- name: Install dependencies
103103
run: bun install --frozen-lockfile
104104
env:
@@ -117,7 +117,7 @@ jobs:
117117
- name: Setup bun
118118
uses: oven-sh/setup-bun@v1
119119
with:
120-
bun-version: 1.0.30
120+
bun-version: 1.0.33
121121
- name: Install dependencies
122122
run: bun install --frozen-lockfile
123123
env:
@@ -132,12 +132,12 @@ jobs:
132132
- name: Setup bun
133133
uses: oven-sh/setup-bun@v1
134134
with:
135-
bun-version: 1.0.30
135+
bun-version: 1.0.33
136136
- name: Install dependencies
137137
run: bun install --frozen-lockfile
138138
env:
139139
PUPPETEER_SKIP_DOWNLOAD: 1
140-
- run: bun lint
140+
- run: bun lint --no-cache
141141
test:
142142
runs-on: ubuntu-latest
143143
name: Test
@@ -147,7 +147,7 @@ jobs:
147147
- name: Setup bun
148148
uses: oven-sh/setup-bun@v1
149149
with:
150-
bun-version: 1.0.30
150+
bun-version: 1.0.33
151151
- name: Install dependencies
152152
run: bun install --frozen-lockfile
153153
env:
@@ -162,7 +162,7 @@ jobs:
162162
- name: Setup bun
163163
uses: oven-sh/setup-bun@v1
164164
with:
165-
bun-version: 1.0.30
165+
bun-version: 1.0.33
166166
- name: Install dependencies
167167
run: bun install --frozen-lockfile
168168
env:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ screenshots/
4343
/playwright-report/
4444
/blob-report/
4545
/playwright/.cache/
46+
47+
# Generated public files
48+
/public/~gitbook/static/

bun.lockb

880 Bytes
Binary file not shown.

e2e/pages.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ const testCases: TestsCase[] = [
209209
name: 'Lists',
210210
url: 'blocks/lists',
211211
},
212+
{
213+
name: 'Math',
214+
url: 'blocks/math',
215+
},
212216
],
213217
},
214218
{

next.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,23 @@ module.exports = withSentryConfig(
2222
return config;
2323
},
2424

25+
async headers() {
26+
return [
27+
// Cache all static assets for 1 year
28+
{
29+
source: '/~gitbook/static/:path*',
30+
headers: [
31+
{
32+
key: 'Cache-Control',
33+
value: 'public, max-age=31536000, immutable',
34+
},
35+
],
36+
},
37+
];
38+
},
39+
2540
assetPrefix: process.env.GITBOOK_ASSETS_PREFIX,
41+
poweredByHeader: false,
2642
},
2743
{
2844
silent: true,

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"format:check": "prettier ./ --ignore-unknown --list-different",
1313
"typecheck": "tsc --noEmit",
1414
"unit": "bun test {src,packages}/**/*.test.ts",
15-
"e2e": "playwright test"
15+
"e2e": "playwright test",
16+
"postinstall": "rm -rf ./public/~gitbook/static/mathjax@3.2.2 && mkdir -p ./public/~gitbook/static/ && cp -R node_modules/mathjax/es5 ./public/~gitbook/static/mathjax@3.2.2"
1617
},
1718
"workspaces": [
1819
"packages/*"
@@ -59,7 +60,8 @@
5960
"tailwind-merge": "^2.2.0",
6061
"tailwind-shades": "^1.1.2",
6162
"unified": "^11.0.4",
62-
"url-join": "^5.0.0"
63+
"url-join": "^5.0.0",
64+
"mathjax": "^3.2.2"
6365
},
6466
"devDependencies": {
6567
"@argos-ci/playwright": "^2.0.0",

packages/emoji-codepoints/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@gitbook/emoji-codepoints",
33
"description": "Optimized mapping of codepoints to the fully qualified emoji codepoints",
44
"private": true,
5-
"main": "./index.ts",
5+
"exports": "./index.ts",
66
"dependencies": {},
77
"devDependencies": {
88
"emoji-assets": "^8.0.0"

packages/react-contentkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gitbook/react-contentkit",
3-
"main": "./src/index.ts",
3+
"exports": "./src/index.ts",
44
"dependencies": {
55
"classnames": "^2.5.1",
66
"@gitbook/api": "^0.36.0",

packages/react-math/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@gitbook/react-math",
3+
"exports": "./src/index.ts",
4+
"dependencies": {
5+
"object-hash": "^3.0.0"
6+
},
7+
"peerDependencies": {
8+
"react": "*"
9+
}
10+
}

0 commit comments

Comments
 (0)