@owomark/processor 0.1.5

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 ADDED
@@ -0,0 +1,41 @@
1
+ # `@owomark/processor`
2
+
3
+ Node-safe Markdown and MDX processing for OwoMark. This package owns the static rendering pipeline, remark/rehype plugins, built-in MDX components, and MDX component CSS.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @owomark/processor
9
+ ```
10
+
11
+ If you enable MDX evaluation, also install peer dependencies:
12
+
13
+ ```bash
14
+ npm install @mdx-js/mdx react react-dom
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```ts
20
+ import { createOwoMarkProcessor } from '@owomark/processor';
21
+
22
+ const processor = createOwoMarkProcessor({
23
+ mode: 'production',
24
+ enableMdx: true,
25
+ });
26
+
27
+ const html = await processor.process('# Hello');
28
+ ```
29
+
30
+ Import component styles separately:
31
+
32
+ ```ts
33
+ import '@owomark/processor/mdx-components.css';
34
+ ```
35
+
36
+ To apply official light or dark token values, layer in theme CSS from `@owomark/view`:
37
+
38
+ ```ts
39
+ import '@owomark/processor/mdx-components.css';
40
+ import '@owomark/view/light.css';
41
+ ```
@@ -0,0 +1,234 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { BlockContent, Root } from 'mdast';
4
+ import { Root as Root$1 } from 'hast';
5
+
6
+ /**
7
+ * Rehype plugin: unwrap display math from `<pre><code>` wrappers.
8
+ *
9
+ * remark-math + remark-rehype produce `<pre><code class="language-math math-display">`.
10
+ * rehype-katex renders the KaTeX HTML inside that `<code>`, but the outer
11
+ * `<pre>` triggers code-block styling and suppresses block-level math display.
12
+ * This plugin hoists the rendered KaTeX content out of `<pre><code>`.
13
+ */
14
+ declare function rehypeMathDisplayFix(): (tree: any) => void;
15
+
16
+ /**
17
+ * Remark plugin: convert paragraph-level soft line breaks into hard break nodes.
18
+ *
19
+ * Only rewrites inline phrasing content inside paragraphs, so fenced code,
20
+ * tables, math blocks, and other block structures keep their original
21
+ * Markdown semantics.
22
+ */
23
+ declare function remarkConvertSoftBreaksToHardBreaks(): (tree: any) => void;
24
+
25
+ /**
26
+ * remark-side-annotation — OwoMark Side Annotation syntax plugin.
27
+ *
28
+ * Parses four tiers of side annotation syntax and produces SideAnnotation
29
+ * container nodes in the mdast tree:
30
+ *
31
+ * - Tier 1: `text (>} annotation)` — single-block inline
32
+ * - Tier 1+: `text (>} anno)` + `(>+)` — 2-3 block continuation
33
+ * - Tier 2: `:::side (>} anno) ... :::` — 4+ block container
34
+ * - Tier 3: `:::side [>id] ... :::` + def — long-content reference
35
+ *
36
+ * @see docs/pitch/owomark-side-annotation.md
37
+ * @see docs/adr/ADR-010-owomark-side-annotation-syntax-design.md
38
+ */
39
+
40
+ /**
41
+ * Custom mdast node for side annotations.
42
+ * Discriminant: `type: 'sideAnnotation'` — use this for type guards
43
+ * (e.g. `node.type === 'sideAnnotation'`).
44
+ * Bridged to rehype via `data.hName`/`data.hProperties`.
45
+ */
46
+ interface SideAnnotationNode {
47
+ /** Discriminant — always `'sideAnnotation'`. */
48
+ type: 'sideAnnotation';
49
+ data: {
50
+ hName: 'div';
51
+ hProperties: {
52
+ className: string[];
53
+ 'data-side-type': string;
54
+ 'data-side-text'?: string;
55
+ 'data-side-orphan'?: string;
56
+ };
57
+ };
58
+ sideType: string;
59
+ sideTypeSymbol: string;
60
+ noteRef: string | null;
61
+ inlineText: string | null;
62
+ orphan?: boolean;
63
+ children: BlockContent[];
64
+ }
65
+ declare function remarkSideAnnotation(): (tree: Root) => void;
66
+
67
+ /**
68
+ * rehype-side-annotation — Transforms remark-side-annotation output into
69
+ * full HTML structure with CSS Grid layout and SVG decorations.
70
+ *
71
+ * After remark-rehype, SideAnnotation nodes become `<div>` elements with
72
+ * `data-side-type` attributes. This plugin detects them and injects the
73
+ * two-column grid structure (main content + annotation aside).
74
+ *
75
+ * SVG decorations use segmented rendering (ADR-014): fixed-height SVG
76
+ * caps/beaks + flex-stretch line divs. This prevents curve distortion
77
+ * at any container height.
78
+ *
79
+ * @see docs/adr/ADR-014-side-annotation-segmented-svg-rendering.md
80
+ * @see docs/pitch/owomark-side-annotation.md §R4
81
+ */
82
+
83
+ declare function rehypeSideAnnotation(): (tree: Root$1) => void;
84
+
85
+ /**
86
+ * micromark-side-annotation — micromark syntax extension for Side Annotation.
87
+ *
88
+ * Tokenizes `(>TYPE CONTENT)` as a single opaque token at the micromark level
89
+ * (Phase 0), preventing MDX's expression parser from intercepting `{` / `}`
90
+ * inside the annotation marker. The fromMarkdown extension converts the token
91
+ * back to a plain text node so that `remark-side-annotation` (Phase 2 tree
92
+ * transform) can process it unchanged.
93
+ *
94
+ * Also tokenizes `(>+)` continuation markers for the same reason.
95
+ */
96
+
97
+ /**
98
+ * Remark plugin that registers the micromark + fromMarkdown extensions.
99
+ * Add this BEFORE `remarkMdx` in the plugin chain so the micromark tokenizer
100
+ * is available when the parser runs.
101
+ */
102
+ declare function remarkMicromarkSideAnnotation(this: any): void;
103
+
104
+ type ProcessorMode = 'preview' | 'production';
105
+ /** A single plugin or a [plugin, ...options] tuple accepted by unified. */
106
+ type PluginEntry = unknown | [unknown, ...unknown[]];
107
+ /** Minimal processor contract shared by unified and MDX engines. */
108
+ interface OwoMarkProcessor {
109
+ process(source: string): Promise<{
110
+ toString(): string;
111
+ value: string;
112
+ }>;
113
+ }
114
+ /** React component map for MDX rendering. */
115
+ type MdxComponentMap = Record<string, React.ComponentType<any>>;
116
+ type OwoMarkProcessorOptions = {
117
+ /** Rendering mode. Defaults to 'preview'. */
118
+ mode?: ProcessorMode;
119
+ /**
120
+ * When false (default), plain newlines in paragraphs become `<br>`.
121
+ * When true, CommonMark soft-break semantics are preserved.
122
+ */
123
+ preserveSoftLineBreaks?: boolean;
124
+ /** Shiki theme for code highlighting. Defaults to 'vitesse-light'. */
125
+ codeTheme?: string;
126
+ /**
127
+ * Additional rehype plugins injected after the core chain but before
128
+ * rehype-stringify. Use this for host-specific plugins like
129
+ * rehypeSourceLines (scroll-sync anchors).
130
+ */
131
+ extraRehypePlugins?: PluginEntry[];
132
+ /**
133
+ * Additional remark plugins injected after the core remark chain but
134
+ * before remark-rehype. Use for host-specific remark transformations.
135
+ */
136
+ extraRemarkPlugins?: PluginEntry[];
137
+ /** Enable side annotation syntax. Defaults to true. */
138
+ enableSideAnnotation?: boolean;
139
+ /** Enable math (KaTeX) rendering. Defaults to true. */
140
+ enableMath?: boolean;
141
+ /** Enable fenced markdown sandbox rendering. Defaults to true. */
142
+ enableMarkdownSandbox?: boolean;
143
+ /** Markdown sandbox configuration. */
144
+ markdownSandbox?: {
145
+ outerFenceTicks?: number;
146
+ };
147
+ /**
148
+ * Enable MDX rendering via @mdx-js/mdx evaluate().
149
+ * When true, the processor delegates to evaluate() + renderToStaticMarkup()
150
+ * instead of the unified pipeline. Defaults to false.
151
+ */
152
+ enableMdx?: boolean;
153
+ /**
154
+ * Additional or override React components for MDX rendering.
155
+ * Merged on top of the built-in defaults (Callout, CodeDemo).
156
+ * Only used when enableMdx is true.
157
+ */
158
+ mdxComponents?: MdxComponentMap;
159
+ };
160
+ /**
161
+ * Create a fully configured processor (Gold Processor).
162
+ *
163
+ * When `enableMdx` is false (default), returns a unified Processor.
164
+ * When `enableMdx` is true, returns an MDX-aware processor that delegates to
165
+ * `@mdx-js/mdx` evaluate() + renderToStaticMarkup(). Both share the same
166
+ * `process(source) → HTML string` contract.
167
+ */
168
+ declare function createOwoMarkProcessor(options?: OwoMarkProcessorOptions): OwoMarkProcessor;
169
+ declare function getOwoMarkPlugins(options?: OwoMarkProcessorOptions): {
170
+ remarkPlugins: PluginEntry[];
171
+ rehypePlugins: PluginEntry[];
172
+ };
173
+
174
+ declare function Callout({ type, children }: {
175
+ type?: string;
176
+ children?: ReactNode;
177
+ }): react.DetailedReactHTMLElement<{
178
+ className: string;
179
+ 'data-callout-type': string;
180
+ }, HTMLElement>;
181
+
182
+ declare function CodeDemo({ title, language, code }: {
183
+ title?: string;
184
+ language?: string;
185
+ code: string;
186
+ }): react.DetailedReactHTMLElement<{
187
+ className: string;
188
+ 'data-code-demo': string;
189
+ }, HTMLElement>;
190
+
191
+ declare function Steps({ children }: {
192
+ children?: ReactNode;
193
+ }): react.DetailedReactHTMLElement<{
194
+ className: string;
195
+ }, HTMLElement>;
196
+ declare function Step({ title, children }: {
197
+ title?: string;
198
+ children?: ReactNode;
199
+ }): react.DetailedReactHTMLElement<{
200
+ className: string;
201
+ }, HTMLElement>;
202
+
203
+ declare function Tabs({ children }: {
204
+ children?: ReactNode;
205
+ }): react.DetailedReactHTMLElement<{
206
+ className: string;
207
+ }, HTMLElement>;
208
+ declare function Tab({ label: _label, children }: {
209
+ label?: string;
210
+ children?: ReactNode;
211
+ }): react.DetailedReactHTMLElement<react.HTMLAttributes<HTMLElement>, HTMLElement>;
212
+
213
+ declare function FileTree({ children }: {
214
+ children?: ReactNode;
215
+ }): react.DetailedReactHTMLElement<{
216
+ className: string;
217
+ }, HTMLElement>;
218
+
219
+ declare function Kbd({ children }: {
220
+ children?: ReactNode;
221
+ }): react.DetailedReactHTMLElement<{
222
+ className: string;
223
+ }, HTMLElement>;
224
+
225
+ /**
226
+ * Built-in MDX components shipped with owomark-view.
227
+ *
228
+ * These are the default components available when `enableMdx: true`.
229
+ * Users can override any of these or add new ones via the `mdxComponents` option.
230
+ */
231
+
232
+ declare const DEFAULT_MDX_COMPONENTS: MdxComponentMap;
233
+
234
+ export { Callout, CodeDemo, DEFAULT_MDX_COMPONENTS, FileTree, Kbd, type MdxComponentMap, type OwoMarkProcessor, type OwoMarkProcessorOptions, type PluginEntry, type ProcessorMode, type SideAnnotationNode, Step, Steps, Tab, Tabs, createOwoMarkProcessor, getOwoMarkPlugins, rehypeMathDisplayFix, rehypeSideAnnotation, remarkConvertSoftBreaksToHardBreaks, remarkMicromarkSideAnnotation, remarkSideAnnotation };