@abreen/tada 1.15.10 → 1.15.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/utils/code.ts +4 -4
- package/build/utils/katex.ts +37 -0
- package/build/utils/markdown-partials.ts +1 -1
- package/build/utils/markdown.ts +2 -32
- package/build/utils/render.ts +2 -5
- package/init/content/lectures/01/Rectangle.java +2 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- /package/src/{literate/style.scss → literate.scss} +0 -0
package/build/utils/code.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { getExtensionToShikiLanguage } from '../site-variables';
|
|
|
7
7
|
import { highlightCode } from './shiki-highlighter';
|
|
8
8
|
import externalLinksPlugin from '../external-links-plugin';
|
|
9
9
|
import { createApplyBasePath } from './paths';
|
|
10
|
+
import katexPlugin from './katex';
|
|
10
11
|
import { splitLines } from './literate-java';
|
|
11
12
|
import type { JavaTocEntry, SiteVariables } from '../types';
|
|
12
13
|
|
|
@@ -40,10 +41,9 @@ const log = makeLogger(import.meta.url);
|
|
|
40
41
|
const PROSE_LINE = /^\s*\/\/\/(\s|$)/;
|
|
41
42
|
|
|
42
43
|
function createCodeMarkdown(siteVariables: SiteVariables): MarkdownIt {
|
|
43
|
-
return new MarkdownIt({ html: true, typographer: true })
|
|
44
|
-
externalLinksPlugin,
|
|
45
|
-
|
|
46
|
-
);
|
|
44
|
+
return new MarkdownIt({ html: true, typographer: true })
|
|
45
|
+
.use(externalLinksPlugin, siteVariables)
|
|
46
|
+
.use(katexPlugin);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// Matches Markdown links: [text](url)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type MarkdownIt from 'markdown-it';
|
|
2
|
+
import Token from 'markdown-it/lib/token.mjs';
|
|
3
|
+
import markdownItKatex from '@vscode/markdown-it-katex';
|
|
4
|
+
import katex from 'katex';
|
|
5
|
+
import renderA11yString from 'katex/contrib/render-a11y-string';
|
|
6
|
+
|
|
7
|
+
export default function katexPlugin(markdown: MarkdownIt): void {
|
|
8
|
+
markdown.use(markdownItKatex);
|
|
9
|
+
|
|
10
|
+
// The @vscode/markdown-it-katex plugin's renderers swallow errors thrown
|
|
11
|
+
// by katex.renderToString() and return error HTML instead of propagating
|
|
12
|
+
// the exception. Override the renderers so parse errors fail the build.
|
|
13
|
+
// The plugin's tokenizer ($ and $$ delimiter parsing) is kept.
|
|
14
|
+
// Each renderer also adds an aria-label with a screen-reader-friendly
|
|
15
|
+
// description generated by katex/contrib/render-a11y-string.
|
|
16
|
+
markdown.renderer.rules.math_inline = (tokens: Token[], idx: number) => {
|
|
17
|
+
const latex = tokens[idx].content;
|
|
18
|
+
const html = katex.renderToString(latex, { throwOnError: true });
|
|
19
|
+
const a11y = markdown.utils.escapeHtml(renderA11yString(latex));
|
|
20
|
+
return html.replace(
|
|
21
|
+
'<span class="katex">',
|
|
22
|
+
`<span class="katex" aria-label="${a11y}">`,
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
const katexBlockRenderer = (tokens: Token[], idx: number) => {
|
|
26
|
+
const latex = tokens[idx].content;
|
|
27
|
+
const html = katex.renderToString(latex, {
|
|
28
|
+
throwOnError: true,
|
|
29
|
+
displayMode: true,
|
|
30
|
+
});
|
|
31
|
+
const a11y = markdown.utils.escapeHtml(renderA11yString(latex));
|
|
32
|
+
return `<p class="katex-block" aria-label="${a11y}">` + html + `</p>\n`;
|
|
33
|
+
};
|
|
34
|
+
markdown.renderer.rules.math_block = katexBlockRenderer;
|
|
35
|
+
markdown.renderer.rules.math_inline_block = katexBlockRenderer;
|
|
36
|
+
markdown.renderer.rules.math_inline_bare_block = katexBlockRenderer;
|
|
37
|
+
}
|
package/build/utils/markdown.ts
CHANGED
|
@@ -15,9 +15,7 @@ import deflistIdPlugin from '../deflist-id-plugin';
|
|
|
15
15
|
import externalLinksPlugin from '../external-links-plugin';
|
|
16
16
|
import { tocPlugin } from '../toc-plugin';
|
|
17
17
|
import columnsPlugin from '../columns-plugin';
|
|
18
|
-
import
|
|
19
|
-
import katex from 'katex';
|
|
20
|
-
import renderA11yString from 'katex/contrib/render-a11y-string';
|
|
18
|
+
import katexPlugin from './katex';
|
|
21
19
|
import markdownPartialsPlugin from './markdown-partials';
|
|
22
20
|
import type { RenderDependencyCollector, SiteVariables } from '../types';
|
|
23
21
|
|
|
@@ -81,7 +79,7 @@ export function createMarkdown(
|
|
|
81
79
|
.use(externalLinksPlugin, siteVariables)
|
|
82
80
|
.use(tocPlugin)
|
|
83
81
|
.use(columnsPlugin)
|
|
84
|
-
.use(
|
|
82
|
+
.use(katexPlugin)
|
|
85
83
|
.use(markdownItContainer, 'details', {
|
|
86
84
|
marker: '<',
|
|
87
85
|
validate: function (params: string) {
|
|
@@ -476,34 +474,6 @@ export function createMarkdown(
|
|
|
476
474
|
state.tokens = transformedTokens;
|
|
477
475
|
});
|
|
478
476
|
|
|
479
|
-
// The @vscode/markdown-it-katex plugin's renderers swallow errors thrown
|
|
480
|
-
// by katex.renderToString() and return error HTML instead of propagating
|
|
481
|
-
// the exception. Override the renderers so parse errors fail the build.
|
|
482
|
-
// The plugin's tokenizer ($ and $$ delimiter parsing) is kept.
|
|
483
|
-
// Each renderer also adds an aria-label with a screen-reader-friendly
|
|
484
|
-
// description generated by katex/contrib/render-a11y-string.
|
|
485
|
-
markdown.renderer.rules.math_inline = (tokens: Token[], idx: number) => {
|
|
486
|
-
const latex = tokens[idx].content;
|
|
487
|
-
const html = katex.renderToString(latex, { throwOnError: true });
|
|
488
|
-
const a11y = markdown.utils.escapeHtml(renderA11yString(latex));
|
|
489
|
-
return html.replace(
|
|
490
|
-
'<span class="katex">',
|
|
491
|
-
`<span class="katex" aria-label="${a11y}">`,
|
|
492
|
-
);
|
|
493
|
-
};
|
|
494
|
-
const katexBlockRenderer = (tokens: Token[], idx: number) => {
|
|
495
|
-
const latex = tokens[idx].content;
|
|
496
|
-
const html = katex.renderToString(latex, {
|
|
497
|
-
throwOnError: true,
|
|
498
|
-
displayMode: true,
|
|
499
|
-
});
|
|
500
|
-
const a11y = markdown.utils.escapeHtml(renderA11yString(latex));
|
|
501
|
-
return `<p class="katex-block" aria-label="${a11y}">` + html + `</p>\n`;
|
|
502
|
-
};
|
|
503
|
-
markdown.renderer.rules.math_block = katexBlockRenderer;
|
|
504
|
-
markdown.renderer.rules.math_inline_block = katexBlockRenderer;
|
|
505
|
-
markdown.renderer.rules.math_inline_bare_block = katexBlockRenderer;
|
|
506
|
-
|
|
507
477
|
const usedIds = new Map<string, number>();
|
|
508
478
|
markdown.use(markdownItContainer, 'alert', {
|
|
509
479
|
marker: '!',
|
package/build/utils/render.ts
CHANGED
|
@@ -359,13 +359,10 @@ export function renderCodePageAsset({
|
|
|
359
359
|
isWatchMode: isWatchMode(assetFiles),
|
|
360
360
|
});
|
|
361
361
|
|
|
362
|
+
const templateHtml = render('code.html', templateParameters) as string;
|
|
362
363
|
const finalized = finalizeHtmlPage({
|
|
363
364
|
filePath,
|
|
364
|
-
html:
|
|
365
|
-
render('code.html', templateParameters) as string,
|
|
366
|
-
assetFiles,
|
|
367
|
-
distDir,
|
|
368
|
-
),
|
|
365
|
+
html: preparePageTemplateHtml({ templateHtml, assetFiles, distDir }),
|
|
369
366
|
siteVariables,
|
|
370
367
|
sourceUrlPath,
|
|
371
368
|
validInternalTargets,
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
/// See [`rectangle.py`](./rectangle.py) for a Python version of this class.
|
|
7
7
|
///
|
|
8
8
|
/// Here's `vars.foobar`: <%= vars.foobar %>
|
|
9
|
+
///
|
|
10
|
+
/// Here's some LaTeX: $\frac{n(n-1)}{2}$ is $O(n^2)$
|
|
9
11
|
public class Rectangle {
|
|
10
12
|
private int width;
|
|
11
13
|
private int height;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
File without changes
|