opentui-markdown-render 0.2.0 → 0.2.1
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/package.json +1 -1
- package/src/app.tsx +7 -0
- package/src/math/native.ts +14 -5
- package/src/view/document.tsx +3 -1
- package/src/view/math.tsx +5 -3
package/package.json
CHANGED
package/src/app.tsx
CHANGED
|
@@ -32,6 +32,8 @@ export type MarkdownRendererCommonProps = {
|
|
|
32
32
|
// `cwd` looking for `opentui-markdown-render.json[c]`.
|
|
33
33
|
readonly configPath?: string
|
|
34
34
|
readonly themeMode?: ThemeModeSetting | (() => ThemeModeSetting | null | undefined)
|
|
35
|
+
// Host-controlled display-math enlargement. Inline formulas keep text size.
|
|
36
|
+
readonly mathScale?: number | (() => number)
|
|
35
37
|
readonly cwd?: string
|
|
36
38
|
// The viewer window. `enabled: false` keeps the document in the whole area.
|
|
37
39
|
readonly frame?: FrameConfig | (() => FrameConfig)
|
|
@@ -97,6 +99,10 @@ export function MarkdownRenderer(props: MarkdownRendererProps) {
|
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
const themeModeSetting = () => (typeof props.themeMode === "function" ? props.themeMode() : props.themeMode)
|
|
102
|
+
const mathScale = () => {
|
|
103
|
+
const value = typeof props.mathScale === "function" ? props.mathScale() : props.mathScale
|
|
104
|
+
return value !== undefined && Number.isFinite(value) && value > 0 ? value : 1
|
|
105
|
+
}
|
|
100
106
|
const config = createMemo<MarkdownConfig>(() => {
|
|
101
107
|
const provided = typeof props.config === "function" ? props.config() : props.config
|
|
102
108
|
if (provided) return provided
|
|
@@ -171,6 +177,7 @@ export function MarkdownRenderer(props: MarkdownRendererProps) {
|
|
|
171
177
|
imageLimits={config().images}
|
|
172
178
|
tableOptions={tableOptions()}
|
|
173
179
|
mermaidOptions={config().mermaid}
|
|
180
|
+
mathScale={mathScale()}
|
|
174
181
|
onDiagnostic={props.onDiagnostic}
|
|
175
182
|
renderUnit={props.renderUnit}
|
|
176
183
|
/>
|
package/src/math/native.ts
CHANGED
|
@@ -30,10 +30,19 @@ export function loadNativeMath() {
|
|
|
30
30
|
|
|
31
31
|
async function importNativeMath(): Promise<NativeModule | undefined> {
|
|
32
32
|
if (process.platform !== "linux" || process.arch !== "x64") return undefined
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
const relative = path.join("prebuilds", "linux-x64-gnu", "opentui_markdown_render.node")
|
|
34
|
+
// The first location is the published package layout. The second supports a
|
|
35
|
+
// host bundling the TypeScript implementation into its own package while
|
|
36
|
+
// copying `prebuilds` beside the generated entrypoint.
|
|
37
|
+
const candidates = [
|
|
38
|
+
path.join(import.meta.dir, "..", "..", relative),
|
|
39
|
+
path.join(import.meta.dir, relative),
|
|
40
|
+
path.join(import.meta.dir, "node_modules", "opentui-markdown-render", relative),
|
|
41
|
+
]
|
|
42
|
+
for (const file of candidates) {
|
|
43
|
+
try {
|
|
44
|
+
return createRequire(import.meta.url)(file) as NativeModule
|
|
45
|
+
} catch {}
|
|
38
46
|
}
|
|
47
|
+
return undefined
|
|
39
48
|
}
|
package/src/view/document.tsx
CHANGED
|
@@ -30,6 +30,7 @@ export type DocumentViewProps = {
|
|
|
30
30
|
imageLimits?: ImagesConfig
|
|
31
31
|
tableOptions: ResolvedTableOptions
|
|
32
32
|
mermaidOptions?: MermaidConfig
|
|
33
|
+
mathScale?: number
|
|
33
34
|
onDiagnostic?: (diagnostic: { level: "warning" | "error"; message: string }) => void
|
|
34
35
|
renderUnit?: RenderUnit
|
|
35
36
|
}
|
|
@@ -88,7 +89,8 @@ export function DocumentView(props: DocumentViewProps) {
|
|
|
88
89
|
labelColor={() => props.theme.markdown.image} textColor={() => props.theme.markdown.imageText}
|
|
89
90
|
limits={props.imageLimits} />
|
|
90
91
|
case "display-math": return <DisplayMath content={block.content} open={block.open} close={block.close}
|
|
91
|
-
maxWidth={() => columns} theme={() => props.theme} graphics={props.graphics} surface={props.surface}
|
|
92
|
+
maxWidth={() => columns} theme={() => props.theme} graphics={props.graphics} surface={props.surface}
|
|
93
|
+
scale={() => props.mathScale ?? 1} />
|
|
92
94
|
case "quote": return <box border={columns > 2 ? ["left"] : []} borderColor={props.theme.markdown.blockQuote}
|
|
93
95
|
paddingLeft={columns > 2 ? 1 : 0} width="100%" flexDirection="column">
|
|
94
96
|
<For each={block.blocks}>{(child) => <BlockView block={() => child}
|
package/src/view/math.tsx
CHANGED
|
@@ -12,6 +12,7 @@ export function DisplayMath(props: {
|
|
|
12
12
|
surface: () => string
|
|
13
13
|
theme: () => Theme
|
|
14
14
|
graphics: CanvasGraphics
|
|
15
|
+
scale: () => number
|
|
15
16
|
}) {
|
|
16
17
|
const [failed, setFailed] = createSignal(false)
|
|
17
18
|
const color = () => rgbaToHex(props.theme().text.base)
|
|
@@ -27,11 +28,12 @@ export function DisplayMath(props: {
|
|
|
27
28
|
color: color(),
|
|
28
29
|
background: props.surface(),
|
|
29
30
|
cell: props.graphics.cell(),
|
|
31
|
+
scale: props.scale(),
|
|
30
32
|
}),
|
|
31
33
|
async (key): Promise<{ raster: MathImage } | { error: string }> => {
|
|
32
|
-
const input = JSON.parse(key) as { content: string; color: string; background: string; cell: CellSize | null }
|
|
34
|
+
const input = JSON.parse(key) as { content: string; color: string; background: string; cell: CellSize | null; scale: number }
|
|
33
35
|
try {
|
|
34
|
-
const raster = await renderMathImage(input.content, true, input.color, input.background, input.cell)
|
|
36
|
+
const raster = await renderMathImage(input.content, true, input.color, input.background, input.cell, input.scale)
|
|
35
37
|
return raster ? { raster } : { error: "Renderer returned no image" }
|
|
36
38
|
} catch (error) {
|
|
37
39
|
return { error: error instanceof Error ? error.message : String(error) }
|
|
@@ -69,7 +71,7 @@ export function DisplayMath(props: {
|
|
|
69
71
|
<Match when={raster()}>
|
|
70
72
|
<box width="100%" height={box().rows} flexShrink={0} alignItems="center" justifyContent="center">
|
|
71
73
|
<image
|
|
72
|
-
id={`opentui-markdown-math-${mathImageID(props.content, true, color(), props.graphics.cell())}-${props.surface()}`}
|
|
74
|
+
id={`opentui-markdown-math-${mathImageID(props.content, true, color(), props.graphics.cell(), props.scale())}-${props.surface()}`}
|
|
73
75
|
source={raster()!.png}
|
|
74
76
|
fit="fit"
|
|
75
77
|
protocol="auto"
|