@aiquants/markdown 13.4.0 → 13.5.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/README.md +16 -8
- package/dist/components/MarkdownViewer.d.ts +6 -2
- package/dist/components/ReadingPlaceKeeper.d.ts +1 -0
- package/dist/components/documentFont.d.ts +1 -0
- package/dist/components/viewerLabels.d.ts +2 -0
- package/dist/converter.wasm +0 -0
- package/dist/extractHeadings-BCQiyUSk.cjs +12 -0
- package/dist/{extractHeadings-DXugjr7W.js → extractHeadings-BmRzzwg1.js} +2652 -2602
- package/dist/index.cjs +1 -1
- package/dist/index.client.cjs +1 -1
- package/dist/index.client.d.ts +1 -1
- package/dist/index.client.js +1 -1
- package/dist/index.js +1 -1
- package/dist/mermaidFrame/NOTICES.md +1 -1
- package/dist/viewer-settings.d.ts +4 -0
- package/package.json +6 -6
- package/dist/extractHeadings-PPInR6qd.cjs +0 -12
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Advanced Markdown renderer for React with support for various extensions and cus
|
|
|
11
11
|
- **Dynamic Configuration**: Easily enable or disable custom extensions dynamically using parse options.
|
|
12
12
|
- **Syntax Highlighting**: Code blocks with Shiki syntax highlighting, every token at a 7:1 contrast ratio or better in the GitHub, Zenn and None styles, light and dark (see [Code blocks](#code-blocks)).
|
|
13
13
|
- **Text That Grows and Untrusted Text**: a text that grows renders block by block as the converter cuts it, keeping the reader's selection and a code block's place (see [Text that grows](#text-that-grows)), and a model's answer renders under its own allow list, its images and links handed to the host's components (see [Untrusted text](#untrusted-text)).
|
|
14
|
-
- **Reader's Display Options**: one toolbar popover holds the document style, a reading width
|
|
14
|
+
- **Reader's Display Options**: one toolbar popover holds the document style, a reading width, colour pairs that keep every text at 7:1 or better in every built-in style, and the document fonts a host offers (see [Reader's display options](#readers-display-options)).
|
|
15
15
|
- **TypeScript**: Full TypeScript support with comprehensive type definitions.
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
@@ -165,7 +165,7 @@ const parseResult = await parseMarkdown(
|
|
|
165
165
|
|
|
166
166
|
| Option | Required | Meaning |
|
|
167
167
|
| --- | --- | --- |
|
|
168
|
-
| `deniedPathSegments` | ✅ | Deny rules applied to every target the conversion resolves: `@import` targets, images and links. A pattern matches one whole path segment (`*` matches any run of characters within it), compared after NFKC normalization and case folding at every percent-decoding level (the semantics of `@aiquants/markdown-explorer`'s deny rules). Local targets must also stay inside `workspaceRoot`, also once symbolic links are resolved. A refused image renders without `src`, a refused link without a destination (with `validateExistence`, both are marked like a missing target, whether or not the target exists), and a refused import rejects the call. |
|
|
168
|
+
| `deniedPathSegments` | ✅ | Deny rules applied to every target the conversion resolves: `@import` targets, images and links. A pattern matches one whole path segment (`*` matches any run of characters within it), compared after NFKC normalization and case folding at every percent-decoding level (the semantics of `@aiquants/markdown-explorer`'s deny rules). Local targets must also stay inside `workspaceRoot`, also once symbolic links are resolved; a name holding NUL as the file system reads it cannot be examined and is refused, while a further decoding level that holds NUL (`docs/%2500.png` names the file `docs/%00.png`, whose next decoding holds NUL) names no file, so the rules read its text and no link is looked up for it. A refused image renders without `src`, a refused link without a destination (with `validateExistence`, both are marked like a missing target, whether or not the target exists), and a refused import rejects the call. |
|
|
169
169
|
| `maxHtmlBytes` | ✅ | The largest HTML in bytes, a positive integer up to `MAX_HTML_BYTES_LIMIT`; with `includeStreamingHints`, the HTML and its block offsets together, 5 bytes an offset. The service stops while it renders and the call rejects with `MarkdownResourceExhaustedError`, as it does for an answer with a longer HTML. |
|
|
170
170
|
| `resolveImports` | | Expand `<!-- @import "path" -->` directives (default `false`: a directive stays an HTML comment and nothing is read). Only Markdown (`.md`) targets the deny rules admit are read, nested imports included; a refused target rejects the call with `permission_denied`. Imports nest at most 100 deep, one inside the next; a deeper chain rejects with `MarkdownResourceExhaustedError` before the import past the limit is read. |
|
|
171
171
|
| `validateExistence` | | Probe local targets (default `true`): a local storage image also gets `data-asset-exists` (`"true"` or `"false"`) and a local doc link `data-doc-exists` (`"true"` or `"false"`). Cloud targets are never probed, and `data-asset-src` is written for every admitted storage image either way. |
|
|
@@ -189,7 +189,7 @@ An image destination is a URL decoded once: `` names the file `a%
|
|
|
189
189
|
|
|
190
190
|
- **Storage images** (a local file inside `workspaceRoot`, or a `gcs://` / `gdrive://` object) have no `src`. Their document path is in `data-asset-src`, unescaped: the path from `workspaceRoot` for a local file (`資料/進捗100%.png`, `x.data`), the URI decoded once for a cloud object (`gcs://bucket/reports/fig 1.png`). The host writes the `src` from it, encoding the path for its own route; no URL is signed.
|
|
191
191
|
- **Existence**: with `validateExistence`, a local storage image also carries `data-asset-exists` (`"true"` or `"false"`); a cloud image is never probed.
|
|
192
|
-
- **Refused targets** (the deny rules,
|
|
192
|
+
- **Refused targets** (the deny rules, outside `workspaceRoot`, or a name the file system cannot examine, such as one holding NUL: ``) have neither a `src` nor `data-asset-src`; with `validateExistence` they carry `data-asset-exists="false"` whether or not they exist.
|
|
193
193
|
- **Storage links** are `data-link-kind="doc"`: they keep the authored `href` (its fragment is what a host reads) and carry the document path in `data-doc-path`; a local one also gets `data-doc-exists` under `validateExistence`.
|
|
194
194
|
- The asset markers (`data-asset-src`, `data-asset-exists`) and the link markers (`data-link-kind`, `data-doc-path`, `data-doc-exists`) come only from the converter: those written in the document's raw HTML (on any element, an `a` without an `href` included) or added by an HTML plugin are removed, and one a plugin rewrote gets the converter's value back.
|
|
195
195
|
- Of an element's duplicate attributes only the first counts, as in a browser: the converter drops the rest, so the HTML carries no duplicate attribute and a repeated `src` or marker cannot make the converter and the browser read different values.
|
|
@@ -593,19 +593,26 @@ With the `GitHub` and `Zenn` styles of `DEFAULT_MARKDOWN_STYLES`, a wide table o
|
|
|
593
593
|
|
|
594
594
|
### Reader's display options
|
|
595
595
|
|
|
596
|
-
The toolbar's display button opens one popover with up to
|
|
596
|
+
The toolbar's display button opens one popover with up to four sections. The viewer keeps none of the values: a host passes each one, stores what the reader chooses and passes it back. The button shows while a document shows and any section does.
|
|
597
597
|
|
|
598
598
|
| Section | Value | Reader's choice | Shown when |
|
|
599
599
|
| --- | --- | --- | --- |
|
|
600
600
|
| Style | `style`, from `availableStyles` | `onStyleChange` | `showStyle` (on by default) |
|
|
601
601
|
| Width | `measure` (`ContentMeasure`: `fill`, `reading`) | `onMeasureChange` | `onMeasureChange` is given and `showMeasure` is on (the default) |
|
|
602
602
|
| Colours | `contentColors` (`ContentColors`: `default`, `sepia`, `dark-low-glare`, `high-contrast`) | `onContentColorsChange` | `onContentColorsChange` is given and `showContentColors` is on (the default) |
|
|
603
|
+
| Font | `documentFont`, a key of `documentFontOptions`, or none | `onDocumentFontChange` | `documentFontOptions` lists a font, `onDocumentFontChange` is given and `showDocumentFont` is on (the default) |
|
|
603
604
|
|
|
604
|
-
Each section lists its options as `aria-pressed` buttons of 44 px in a labelled group, and a choice closes an unpinned popover. A change of style, width or alignment, a host's own included, does not parse the document again
|
|
605
|
+
Each section lists its options as `aria-pressed` buttons of 44 px in a labelled group, and a choice closes an unpinned popover. A change of style, width or alignment, a host's own included, does not parse the document again; a change of the document's font renders it again, as a change of `theme` does.
|
|
606
|
+
A change of any of the four keeps the reader's place: the block nearest the scroller's top stays where it was (a host's `width` or `maxWidth`, like a resized pane, keeps none, and nor does a font change in plain text, which the font does not reach). The place is read just before the commit that brings the new value, however late the host passes it back, and kept for two frames after that commit, so nothing is held while a host takes its time.
|
|
605
607
|
The blocks are the children of `[data-aqmd-document]`, the renderer's root, and what lists, quotations, sections and open `details` hold, passing over anything not visible (plain text is one block, its `pre`); within any other long block the place is its top, so a reader deep inside one moves as the text above reflows. A reader's scroll, a click (where the jumps of the document and its table of contents start) or another document ends those frames, and a reader at the top of the document stays at the top.
|
|
606
608
|
A jump with no click (a script's `location.hash`, `history.back()`) that opens a closed section within those frames reads as a reflow. The place reads the block axis of the viewer's own scroller, so vertical writing and a page whose window scrolls keep none.
|
|
607
609
|
A `measure` or a `contentColors` that is not one of its values throws a `TypeError`; normalize a value read from outside with `toContentMeasure` and `toContentColors` (see [Settings without React](#settings-without-react)).
|
|
608
610
|
|
|
611
|
+
The font section names a font by its key and applies none. A host lists the fonts a reader may choose in `documentFontOptions` (`DocumentFontOption`: a `key` and a `label`, each a string that is not blank and is unique among the options; an object with more keys, such as `@aiquants/fonts`' `FontOption`, is taken as it is), keeps the key the reader chooses and passes it back as `documentFont`,
|
|
612
|
+
and resolves that key to the `documentFontFamily` it passes, the one font the viewer applies: the renderer sets it on the document root (`[data-aqmd-document]`) as `DOCUMENT_FONT_FAMILY_PROPERTY` (`--aqmd-document-font-family`), which the root's `font-family` reads, and, absent or blank, the document keeps the font of its display style. A host sanitizes any family a person typed before passing it.
|
|
613
|
+
The section opens with its default entry (`fontDefault`), which reports `undefined`, so a host drops the stored key and goes back to its own default font or none; a label is written in the page's language and read in it, as the style names are.
|
|
614
|
+
A `documentFontOptions` that is not an array of such objects throws a `TypeError`, and a blank or repeated key or label a `RangeError`, whether the section shows or not; a `documentFont` that is not a string throws a `TypeError`, and one that is not a listed key a `RangeError`, so a host passes a stored key only while it lists it.
|
|
615
|
+
|
|
609
616
|
`contentColors` picks one of three colour pairs (WCAG 1.4.8); `default` keeps the document style's own colours and writes nothing:
|
|
610
617
|
|
|
611
618
|
| Pair | Scheme | Ground | Text | Lowest text contrast |
|
|
@@ -1499,9 +1506,10 @@ The display popover's keys of `MarkdownViewerLabels`, all optional and all marke
|
|
|
1499
1506
|
| `styleTitle` | The popover's heading | Display |
|
|
1500
1507
|
| `selectStyleAria` | The display button | Display options |
|
|
1501
1508
|
| `pinStyleAria`, `unpinStyleAria` | The pin button | Pin display options / Unpin display options |
|
|
1502
|
-
| `styleSectionTitle`, `measureTitle`, `colorsTitle` | The sections' headings | Style / Width / Colors |
|
|
1509
|
+
| `styleSectionTitle`, `measureTitle`, `colorsTitle`, `fontTitle` | The sections' headings | Style / Width / Colors / Font |
|
|
1503
1510
|
| `measureFill`, `measureReading` | The width options | Full width / Reading width |
|
|
1504
1511
|
| `colorsDefault`, `colorsSepia`, `colorsDarkLowGlare`, `colorsHighContrast` | The colour options | Document colors / Sepia / Dark, low glare / High contrast |
|
|
1512
|
+
| `fontDefault` | The font section's first entry, which chooses none of the listed fonts | Default font |
|
|
1505
1513
|
|
|
1506
1514
|
`missingImage` is the notice of an image that cannot be found (`missingImageLabel` on `MarkdownRenderer`; "Image not found", marked `lang="en"`).
|
|
1507
1515
|
|
|
@@ -1679,8 +1687,8 @@ converter built to WebAssembly, on hundreds of generated layouts and bodies.
|
|
|
1679
1687
|
import { CODE_META_ATTRIBUTE, parseSpreadsheetOptions, planFencedBodyEdit } from "@aiquants/markdown/code-blocks"
|
|
1680
1688
|
```
|
|
1681
1689
|
|
|
1682
|
-
`@aiquants/markdown/viewer-settings` exports the built-in document styles, the alignments, the measures and the colour pairs without loading React, for modules that also run on the server (configuration, validation): `DEFAULT_MARKDOWN_STYLES`, `DEFAULT_MARKDOWN_STYLE` (`"Zenn"`, the name of the built-in style a host starts a reader on when neither the host nor the reader chose one;
|
|
1683
|
-
the viewer itself always shows the `style` it is given), `MarkdownStyleOption`, `ContentAlign`, `CONTENT_ALIGNS`, `DEFAULT_CONTENT_ALIGN`, `toContentAlign`, `ContentMeasure`, `CONTENT_MEASURES`, `DEFAULT_CONTENT_MEASURE` (`"fill"`), `toContentMeasure`, `ContentColors`, `CONTENT_COLORS`, `DEFAULT_CONTENT_COLORS` (`"default"`) and `toContentColors`. Each `to…` turns a value read from outside (a URL query, a stored preference) into a valid one, the default or a fallback you pass when it is not. `@aiquants/markdown` re-exports the same values.
|
|
1690
|
+
`@aiquants/markdown/viewer-settings` exports the built-in document styles, the document font's property and option, the alignments, the measures and the colour pairs without loading React, for modules that also run on the server (configuration, validation): `DEFAULT_MARKDOWN_STYLES`, `DEFAULT_MARKDOWN_STYLE` (`"Zenn"`, the name of the built-in style a host starts a reader on when neither the host nor the reader chose one;
|
|
1691
|
+
the viewer itself always shows the `style` it is given), `MarkdownStyleOption`, `DOCUMENT_FONT_FAMILY_PROPERTY`, `DocumentFontOption`, `ContentAlign`, `CONTENT_ALIGNS`, `DEFAULT_CONTENT_ALIGN`, `toContentAlign`, `ContentMeasure`, `CONTENT_MEASURES`, `DEFAULT_CONTENT_MEASURE` (`"fill"`), `toContentMeasure`, `ContentColors`, `CONTENT_COLORS`, `DEFAULT_CONTENT_COLORS` (`"default"`) and `toContentColors`. Each `to…` turns a value read from outside (a URL query, a stored preference) into a valid one, the default or a fallback you pass when it is not. `@aiquants/markdown` re-exports the same values.
|
|
1684
1692
|
|
|
1685
1693
|
```ts
|
|
1686
1694
|
import { DEFAULT_MARKDOWN_STYLE, DEFAULT_MARKDOWN_STYLES, toContentAlign, toContentColors, toContentMeasure } from "@aiquants/markdown/viewer-settings"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ScrollBarTapCircleOptions, SpreadsheetScrollBarControls } from "@aiquants/spreadsheet";
|
|
2
2
|
import { MouseEvent, ReactNode } from "react";
|
|
3
3
|
import { MarkdownEmbeds } from "../embeds/linkCards.ts";
|
|
4
|
-
import { ContentAlign, ContentColors, ContentMeasure, MarkdownStyleOption } from "../viewer-settings.ts";
|
|
4
|
+
import { ContentAlign, ContentColors, ContentMeasure, DocumentFontOption, MarkdownStyleOption } from "../viewer-settings.ts";
|
|
5
5
|
import { MarkdownScrollBarRenderer } from "./HostedScrollArea.tsx";
|
|
6
6
|
import { MarkdownLinkComponent } from "./MarkdownRenderer.tsx";
|
|
7
7
|
import { PanZoomModifier } from "./MermaidDiagram.tsx";
|
|
@@ -72,6 +72,10 @@ export interface MarkdownViewerProps {
|
|
|
72
72
|
contentColors?: ContentColors;
|
|
73
73
|
onContentColorsChange?: (colors: ContentColors) => void;
|
|
74
74
|
showContentColors?: boolean;
|
|
75
|
+
documentFontOptions?: readonly DocumentFontOption[];
|
|
76
|
+
documentFont?: string;
|
|
77
|
+
onDocumentFontChange?: (key: string | undefined) => void;
|
|
78
|
+
showDocumentFont?: boolean;
|
|
75
79
|
width?: string;
|
|
76
80
|
maxWidth?: string;
|
|
77
81
|
padding?: number;
|
|
@@ -95,4 +99,4 @@ export interface MarkdownViewerProps {
|
|
|
95
99
|
scrollBarGutter?: number | string;
|
|
96
100
|
scrollBarInlineSize?: number | string;
|
|
97
101
|
}
|
|
98
|
-
export declare function MarkdownViewer({ parseResult, content, error, isLoading, labels, labelsLang, theme, style, onStyleChange, availableStyles, align, onAlignChange, showToc, showStyle, showAlign, contentLang, measure, onMeasureChange, showMeasure, contentColors, onContentColorsChange, showContentColors, width, maxWidth, padding, iFrameAllowedDomains, embeds, fetch: hostFetch, emptyMessage, toolbar: toolbarProp, linkComponent, onHeadingSelect, headingHref, onMathDiagnostics, spreadsheetEditor, spreadsheetLocale, spreadsheetTapScrollCircle, spreadsheetScrollBarControls, mermaidModifier, documentFontFamily, imageSource, renderScrollBar, scrollBarGutter, scrollBarInlineSize, }: MarkdownViewerProps): import("react").JSX.Element;
|
|
102
|
+
export declare function MarkdownViewer({ parseResult, content, error, isLoading, labels, labelsLang, theme, style, onStyleChange, availableStyles, align, onAlignChange, showToc, showStyle, showAlign, contentLang, measure, onMeasureChange, showMeasure, contentColors, onContentColorsChange, showContentColors, documentFontOptions, documentFont, onDocumentFontChange, showDocumentFont, width, maxWidth, padding, iFrameAllowedDomains, embeds, fetch: hostFetch, emptyMessage, toolbar: toolbarProp, linkComponent, onHeadingSelect, headingHref, onMathDiagnostics, spreadsheetEditor, spreadsheetLocale, spreadsheetTapScrollCircle, spreadsheetScrollBarControls, mermaidModifier, documentFontFamily, imageSource, renderScrollBar, scrollBarGutter, scrollBarInlineSize, }: MarkdownViewerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const appliedDocumentFontFamily: (documentFontFamily: string | undefined) => string | undefined;
|
|
@@ -41,6 +41,8 @@ export interface MarkdownViewerLabels extends MermaidViewerLabels, SpreadsheetVi
|
|
|
41
41
|
colorsSepia?: string;
|
|
42
42
|
colorsDarkLowGlare?: string;
|
|
43
43
|
colorsHighContrast?: string;
|
|
44
|
+
fontTitle?: string;
|
|
45
|
+
fontDefault?: string;
|
|
44
46
|
openTocAria?: string;
|
|
45
47
|
tocTitle?: string;
|
|
46
48
|
pinTocAria?: string;
|
package/dist/converter.wasm
CHANGED
|
Binary file
|