md-pipe 0.3.0 → 0.3.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.
@@ -0,0 +1,312 @@
1
+ cli_contracts: 0.1.0
2
+
3
+ info:
4
+ title: md-pipe
5
+ version: 0.3.0
6
+ description: >
7
+ A rendering engine that transforms Markdown manuscripts into HTML/PDF
8
+ through HTML-comment directives and DOM transformations,
9
+ without polluting the Markdown source.
10
+
11
+ artifact_slots:
12
+ markdown-source:
13
+ direction: read
14
+ description: Markdown manuscript files
15
+ config:
16
+ direction: read
17
+ description: md-pipe.config.yml project configuration
18
+ rendered-output:
19
+ direction: write
20
+ description: Rendered HTML/PDF output files
21
+
22
+ command_sets:
23
+ md-pipe:
24
+ summary: Extended Markdown rendering toolchain.
25
+ description: >
26
+ Converts HTML-comment directives into class/id/attribute-bearing HTML nodes,
27
+ embeds CSS, and produces HTML or PDF output.
28
+ Pipeline stages: preprocess → render → transform → html → pdf.
29
+ Use --pipeline to select which stage range to execute.
30
+ Config precedence: CLI args > frontmatter > project config > tool default.
31
+
32
+ env:
33
+ PUPPETEER_EXECUTABLE_PATH:
34
+ required: false
35
+ description: >
36
+ Explicitly specify the Chromium executable path.
37
+ When unset, auto-detects from Puppeteer cache and common install locations.
38
+
39
+ global_options:
40
+ - name: config
41
+ aliases: [c]
42
+ description: Path to the project config file. Auto-detects md-pipe.config.yml when omitted.
43
+ schema:
44
+ type: string
45
+ file:
46
+ mode: read
47
+ exists: true
48
+ media_type: text/yaml
49
+
50
+ - name: verbose
51
+ aliases: [v]
52
+ description: Enable verbose logging.
53
+ schema:
54
+ type: boolean
55
+ default: false
56
+
57
+ - name: strict
58
+ description: >
59
+ Treat undefined directives as errors.
60
+ Overrides the config strictDirectives setting.
61
+ Recommended for CI usage.
62
+ schema:
63
+ type: boolean
64
+ default: false
65
+
66
+ commands:
67
+ # ──────────────────────────────────────────────
68
+ # (default) — pipeline rendering
69
+ # Spec §17: md-pipe [input] [--pipeline [start.]end] [-o output]
70
+ # ──────────────────────────────────────────────
71
+ render:
72
+ summary: Render a Markdown file through the pipeline.
73
+ description: >
74
+ Execute the rendering pipeline on an input file or stdin.
75
+ Stages: preprocess → render → transform → html → pdf.
76
+ Use --pipeline to specify the execution range in [start.]end format;
77
+ omitting start begins from the .md source.
78
+ When --pipeline is omitted, the output format is inferred from
79
+ the -o extension (.html → html, .pdf → pdf), then from
80
+ frontmatter/config, defaulting to html.
81
+ Output is written to a file with -o, or to stdout when omitted.
82
+ usage:
83
+ - md-pipe <input> [-o output] [--pipeline [start.]end]
84
+ - md-pipe report.md -o dist/report.html
85
+ - md-pipe report.md --pipeline .pdf -o dist/report.pdf
86
+ - md-pipe report.rendered.html --pipeline render.html -o report.html
87
+ - cat report.md | md-pipe --pipeline .transform | md-pipe --pipeline transform.pdf -o report.pdf
88
+ path: []
89
+ arguments:
90
+ - name: input
91
+ index: 0
92
+ required: false
93
+ description: Input Markdown file. Reads from stdin when omitted.
94
+ schema:
95
+ type: string
96
+ file:
97
+ mode: read
98
+ exists: true
99
+ options:
100
+ - name: output
101
+ aliases: [o]
102
+ description: Output file path. Writes to stdout when omitted.
103
+ schema:
104
+ type: string
105
+ file:
106
+ mode: write
107
+
108
+ - name: pipeline
109
+ aliases: [p]
110
+ description: >
111
+ Pipeline range in [start.]end format.
112
+ Omitting start begins from the .md source.
113
+ Examples: .html (source→html), .pdf (source→pdf),
114
+ .render (source→render), render.html, transform.pdf, html.pdf.
115
+ When omitted, inferred from -o extension (.html → html, .pdf → pdf).
116
+ When -o is also omitted, follows frontmatter / config (default: html).
117
+ schema:
118
+ type: string
119
+
120
+ - name: theme
121
+ aliases: [t]
122
+ description: >
123
+ Theme name. Applies a preset defined in the project config themes section.
124
+ Overrides frontmatter theme setting.
125
+ schema:
126
+ type: string
127
+
128
+ - name: styles
129
+ description: >
130
+ Additional CSS file paths. Multiple values allowed.
131
+ Appended after theme assets in load order.
132
+ schema:
133
+ type: array
134
+ items:
135
+ type: string
136
+
137
+ - name: scripts
138
+ description: >
139
+ Additional JavaScript file paths. Multiple values allowed.
140
+ Appended after theme assets in load order.
141
+ schema:
142
+ type: array
143
+ items:
144
+ type: string
145
+
146
+ - name: paper-size
147
+ description: Paper size for the pdf stage. Overrides frontmatter paper.size.
148
+ schema:
149
+ type: string
150
+ enum: [A4, A3, Letter, Legal, Tabloid]
151
+ default: A4
152
+
153
+ - name: landscape
154
+ description: Landscape orientation for the pdf stage.
155
+ schema:
156
+ type: boolean
157
+ default: false
158
+
159
+ - name: header
160
+ description: Page header text for the pdf stage.
161
+ schema:
162
+ type: string
163
+
164
+ - name: margin
165
+ description: "Page margin for the pdf stage. Example: 16mm, 18mm."
166
+ schema:
167
+ type: string
168
+ streams:
169
+ stdin:
170
+ required: false
171
+ format: text
172
+ encoding: utf-8
173
+ framing:
174
+ type: raw
175
+ stdout:
176
+ format: text
177
+ encoding: utf-8
178
+ framing:
179
+ type: raw
180
+ effects:
181
+ risk_level: low
182
+ writes:
183
+ - target: output file
184
+ description: Writes the rendered result to a file (when -o is specified).
185
+ overwrite: true
186
+ idempotent: true
187
+ idempotent_note: Produces identical output given the same input and settings.
188
+ exits:
189
+ '0':
190
+ description: Rendering succeeded.
191
+ '1':
192
+ description: Rendering error (Chromium launch failure, PDF generation failure, etc.).
193
+ stderr:
194
+ format: text
195
+ schema:
196
+ $ref: '#/components/schemas/ErrorMessage'
197
+ '2':
198
+ description: >
199
+ Input error (file not found, syntax error, invalid pipeline specification,
200
+ undefined directive in strict mode, etc.).
201
+ stderr:
202
+ format: text
203
+ schema:
204
+ $ref: '#/components/schemas/ErrorMessage'
205
+ x-agent:
206
+ recommended_before_use:
207
+ - Check that md-pipe.config.yml exists when using themes or custom directives
208
+ - Verify Chromium is available when targeting pdf output
209
+ rollback:
210
+ supported: false
211
+ notes: Output files can be deleted manually; no side effects beyond file writes.
212
+ retryable_exit_codes: [1]
213
+ expected_duration_ms: 5000
214
+ examples:
215
+ - name: Source to HTML
216
+ command: md-pipe report.md -o dist/report.html
217
+ - name: Source to PDF
218
+ command: md-pipe report.md --pipeline .pdf -o dist/report.pdf
219
+ - name: Stop at intermediate stage
220
+ command: md-pipe report.md --pipeline .render -o report.rendered.html
221
+ - name: Resume from intermediate file
222
+ command: md-pipe report.rendered.html --pipeline render.html -o report.html
223
+ - name: stdin/stdout pipe chaining
224
+ command: cat report.md | md-pipe --pipeline .transform | md-pipe --pipeline transform.pdf -o report.pdf
225
+
226
+ # ──────────────────────────────────────────────
227
+ # init — project initialization
228
+ # ──────────────────────────────────────────────
229
+ init:
230
+ summary: Initialize a md-pipe project.
231
+ description: >
232
+ Creates a md-pipe.config.yml template in the current directory.
233
+ usage:
234
+ - md-pipe init
235
+ - md-pipe init --theme business-report
236
+ options:
237
+ - name: theme
238
+ aliases: [t]
239
+ description: Initial theme name to scaffold.
240
+ schema:
241
+ type: string
242
+ default: default
243
+
244
+ - name: force
245
+ aliases: [f]
246
+ description: Overwrite existing config file.
247
+ schema:
248
+ type: boolean
249
+ default: false
250
+ effects:
251
+ risk_level: high
252
+ overwrites: true
253
+ effects:
254
+ risk_level: medium
255
+ writes:
256
+ - target: md-pipe.config.yml
257
+ description: Generates a config file template.
258
+ exits:
259
+ '0':
260
+ description: Initialization succeeded.
261
+ stdout:
262
+ format: text
263
+ schema:
264
+ type: string
265
+ description: List of generated files.
266
+ '1':
267
+ description: Initialization error (file write failure, etc.).
268
+ stderr:
269
+ format: text
270
+ schema:
271
+ $ref: '#/components/schemas/ErrorMessage'
272
+ '3':
273
+ description: Config file already exists (without --force).
274
+ stderr:
275
+ format: text
276
+ schema:
277
+ $ref: '#/components/schemas/ErrorMessage'
278
+ x-agent:
279
+ recommended_before_use:
280
+ - Check whether md-pipe.config.yml already exists
281
+ human_review:
282
+ required: false
283
+ reason: Safe scaffolding operation; --force requires attention.
284
+ rollback:
285
+ supported: true
286
+ notes: Delete the generated md-pipe.config.yml.
287
+ examples:
288
+ - name: Initialize with defaults
289
+ command: md-pipe init
290
+ - name: Initialize with a theme
291
+ command: md-pipe init --theme business-report
292
+ - name: Overwrite existing config
293
+ command: md-pipe init --force
294
+
295
+ components:
296
+ schemas:
297
+ ErrorMessage:
298
+ type: object
299
+ required: [message]
300
+ properties:
301
+ message:
302
+ type: string
303
+ description: Error message.
304
+ file:
305
+ type: string
306
+ description: File path where the error occurred.
307
+ line:
308
+ type: integer
309
+ description: Line number where the error occurred.
310
+ detail:
311
+ type: string
312
+ description: Detailed error information.
@@ -0,0 +1,400 @@
1
+ # md-pipe
2
+
3
+ A rendering engine that transforms Markdown manuscripts into HTML/PDF through HTML-comment directives and DOM transformations, without polluting the Markdown source.
4
+
5
+
6
+ **Version:** 0.3.0
7
+
8
+ ## Table of Contents
9
+
10
+ - [md-pipe](#md-pipe)
11
+ - [render](#md-pipe-render)
12
+ - [init](#md-pipe-init)
13
+
14
+ ---
15
+
16
+ ## md-pipe
17
+
18
+ Extended Markdown rendering toolchain.
19
+
20
+ Converts HTML-comment directives into class/id/attribute-bearing HTML nodes, embeds CSS, and produces HTML or PDF output. Pipeline stages: preprocess → render → transform → html → pdf. Use --pipeline to select which stage range to execute. Config precedence: CLI args > frontmatter > project config > tool default.
21
+
22
+
23
+ ### Global Options
24
+
25
+ | Option | Aliases | Required | Default | Description |
26
+ |---|---|---|---|---|
27
+ | `--config` | -c | No | | Path to the project config file. Auto-detects md-pipe.config.yml when omitted. |
28
+ | `--verbose` | -v | No | `false` | Enable verbose logging. |
29
+ | `--strict` | | No | `false` | Treat undefined directives as errors. Overrides the config strictDirectives setting. Recommended for CI usage.
30
+ |
31
+
32
+ ### Environment Variables
33
+
34
+ | Variable | Description |
35
+ |---|---|
36
+ | `PUPPETEER_EXECUTABLE_PATH` | Explicitly specify the Chromium executable path. When unset, auto-detects from Puppeteer cache and common install locations.
37
+ |
38
+
39
+ ### render
40
+
41
+ Render a Markdown file through the pipeline.
42
+
43
+ Execute the rendering pipeline on an input file or stdin. Stages: preprocess → render → transform → html → pdf. Use --pipeline to specify the execution range in [start.]end format; omitting start begins from the .md source. When --pipeline is omitted, the output format is inferred from the -o extension (.html → html, .pdf → pdf), then from frontmatter/config, defaulting to html. Output is written to a file with -o, or to stdout when omitted.
44
+
45
+
46
+ **Usage:**
47
+
48
+ ```
49
+ md-pipe <input> [-o output] [--pipeline [start.]end]
50
+ ```
51
+ ```
52
+ md-pipe report.md -o dist/report.html
53
+ ```
54
+ ```
55
+ md-pipe report.md --pipeline .pdf -o dist/report.pdf
56
+ ```
57
+ ```
58
+ md-pipe report.rendered.html --pipeline render.html -o report.html
59
+ ```
60
+ ```
61
+ cat report.md | md-pipe --pipeline .transform | md-pipe --pipeline transform.pdf -o report.pdf
62
+ ```
63
+
64
+ #### Arguments
65
+
66
+ | Name | Required | Description |
67
+ |---|---|---|
68
+ | `input` | No | Input Markdown file. Reads from stdin when omitted. |
69
+
70
+ #### Options
71
+
72
+ | Option | Aliases | Required | Default | Description |
73
+ |---|---|---|---|---|
74
+ | `--output` | -o | No | | Output file path. Writes to stdout when omitted. |
75
+ | `--pipeline` | -p | No | | Pipeline range in [start.]end format. Omitting start begins from the .md source. Examples: .html (source→html), .pdf (source→pdf), .render (source→render), render.html, transform.pdf, html.pdf. When omitted, inferred from -o extension (.html → html, .pdf → pdf). When -o is also omitted, follows frontmatter / config (default: html).
76
+ |
77
+ | `--theme` | -t | No | | Theme name. Applies a preset defined in the project config themes section. Overrides frontmatter theme setting.
78
+ |
79
+ | `--styles` | | No | | Additional CSS file paths. Multiple values allowed. Appended after theme assets in load order.
80
+ |
81
+ | `--scripts` | | No | | Additional JavaScript file paths. Multiple values allowed. Appended after theme assets in load order.
82
+ |
83
+ | `--paper-size` | | No | `"A4"` | Paper size for the pdf stage. Overrides frontmatter paper.size. |
84
+ | `--landscape` | | No | `false` | Landscape orientation for the pdf stage. |
85
+ | `--header` | | No | | Page header text for the pdf stage. |
86
+ | `--margin` | | No | | Page margin for the pdf stage. Example: 16mm, 18mm. |
87
+
88
+ #### Streams
89
+
90
+ **stdin:**
91
+
92
+ - Format: `text`
93
+ - Encoding: `utf-8`
94
+ - Required: No
95
+ - Framing: `raw`
96
+
97
+ **stdout:**
98
+
99
+ - Format: `text`
100
+ - Encoding: `utf-8`
101
+ - Framing: `raw`
102
+
103
+ #### Exit Codes
104
+
105
+ **Exit 0:** Rendering succeeded.
106
+
107
+ **Exit 1:** Rendering error (Chromium launch failure, PDF generation failure, etc.).
108
+
109
+ - **stderr:** format=`text`
110
+
111
+ | Property | Type | Required | Description |
112
+ |---|---|---|---|
113
+ | `message` | `string` | Yes | Error message. |
114
+ | `file` | `string` | No | File path where the error occurred. |
115
+ | `line` | `integer` | No | Line number where the error occurred. |
116
+ | `detail` | `string` | No | Detailed error information. |
117
+
118
+ <details>
119
+ <summary>JSON Schema</summary>
120
+
121
+ ```json
122
+ {
123
+ "type": "object",
124
+ "required": [
125
+ "message"
126
+ ],
127
+ "properties": {
128
+ "message": {
129
+ "type": "string",
130
+ "description": "Error message."
131
+ },
132
+ "file": {
133
+ "type": "string",
134
+ "description": "File path where the error occurred."
135
+ },
136
+ "line": {
137
+ "type": "integer",
138
+ "description": "Line number where the error occurred."
139
+ },
140
+ "detail": {
141
+ "type": "string",
142
+ "description": "Detailed error information."
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ </details>
149
+
150
+ **Exit 2:** Input error (file not found, syntax error, invalid pipeline specification, undefined directive in strict mode, etc.).
151
+
152
+
153
+ - **stderr:** format=`text`
154
+
155
+ | Property | Type | Required | Description |
156
+ |---|---|---|---|
157
+ | `message` | `string` | Yes | Error message. |
158
+ | `file` | `string` | No | File path where the error occurred. |
159
+ | `line` | `integer` | No | Line number where the error occurred. |
160
+ | `detail` | `string` | No | Detailed error information. |
161
+
162
+ <details>
163
+ <summary>JSON Schema</summary>
164
+
165
+ ```json
166
+ {
167
+ "type": "object",
168
+ "required": [
169
+ "message"
170
+ ],
171
+ "properties": {
172
+ "message": {
173
+ "type": "string",
174
+ "description": "Error message."
175
+ },
176
+ "file": {
177
+ "type": "string",
178
+ "description": "File path where the error occurred."
179
+ },
180
+ "line": {
181
+ "type": "integer",
182
+ "description": "Line number where the error occurred."
183
+ },
184
+ "detail": {
185
+ "type": "string",
186
+ "description": "Detailed error information."
187
+ }
188
+ }
189
+ }
190
+ ```
191
+
192
+ </details>
193
+
194
+ #### Extensions
195
+
196
+ ```yaml
197
+ x-agent:
198
+ recommended_before_use:
199
+ - Check that md-pipe.config.yml exists when using themes or custom directives
200
+ - Verify Chromium is available when targeting pdf output
201
+ rollback:
202
+ supported: false
203
+ notes: Output files can be deleted manually; no side effects beyond file writes.
204
+ retryable_exit_codes:
205
+ - 1
206
+ expected_duration_ms: 5000
207
+ ```
208
+
209
+ ---
210
+
211
+ ### init
212
+
213
+ Initialize a md-pipe project.
214
+
215
+ Creates a md-pipe.config.yml template in the current directory.
216
+
217
+
218
+ **Usage:**
219
+
220
+ ```
221
+ md-pipe init
222
+ ```
223
+ ```
224
+ md-pipe init --theme business-report
225
+ ```
226
+
227
+ #### Options
228
+
229
+ | Option | Aliases | Required | Default | Description |
230
+ |---|---|---|---|---|
231
+ | `--theme` | -t | No | `"default"` | Initial theme name to scaffold. |
232
+ | `--force` | -f | No | `false` | Overwrite existing config file. |
233
+
234
+ #### Exit Codes
235
+
236
+ **Exit 0:** Initialization succeeded.
237
+
238
+ - **stdout:** format=`text`
239
+
240
+
241
+ <details>
242
+ <summary>JSON Schema</summary>
243
+
244
+ ```json
245
+ {
246
+ "type": "string",
247
+ "description": "List of generated files."
248
+ }
249
+ ```
250
+
251
+ </details>
252
+
253
+ **Exit 1:** Initialization error (file write failure, etc.).
254
+
255
+ - **stderr:** format=`text`
256
+
257
+ | Property | Type | Required | Description |
258
+ |---|---|---|---|
259
+ | `message` | `string` | Yes | Error message. |
260
+ | `file` | `string` | No | File path where the error occurred. |
261
+ | `line` | `integer` | No | Line number where the error occurred. |
262
+ | `detail` | `string` | No | Detailed error information. |
263
+
264
+ <details>
265
+ <summary>JSON Schema</summary>
266
+
267
+ ```json
268
+ {
269
+ "type": "object",
270
+ "required": [
271
+ "message"
272
+ ],
273
+ "properties": {
274
+ "message": {
275
+ "type": "string",
276
+ "description": "Error message."
277
+ },
278
+ "file": {
279
+ "type": "string",
280
+ "description": "File path where the error occurred."
281
+ },
282
+ "line": {
283
+ "type": "integer",
284
+ "description": "Line number where the error occurred."
285
+ },
286
+ "detail": {
287
+ "type": "string",
288
+ "description": "Detailed error information."
289
+ }
290
+ }
291
+ }
292
+ ```
293
+
294
+ </details>
295
+
296
+ **Exit 3:** Config file already exists (without --force).
297
+
298
+ - **stderr:** format=`text`
299
+
300
+ | Property | Type | Required | Description |
301
+ |---|---|---|---|
302
+ | `message` | `string` | Yes | Error message. |
303
+ | `file` | `string` | No | File path where the error occurred. |
304
+ | `line` | `integer` | No | Line number where the error occurred. |
305
+ | `detail` | `string` | No | Detailed error information. |
306
+
307
+ <details>
308
+ <summary>JSON Schema</summary>
309
+
310
+ ```json
311
+ {
312
+ "type": "object",
313
+ "required": [
314
+ "message"
315
+ ],
316
+ "properties": {
317
+ "message": {
318
+ "type": "string",
319
+ "description": "Error message."
320
+ },
321
+ "file": {
322
+ "type": "string",
323
+ "description": "File path where the error occurred."
324
+ },
325
+ "line": {
326
+ "type": "integer",
327
+ "description": "Line number where the error occurred."
328
+ },
329
+ "detail": {
330
+ "type": "string",
331
+ "description": "Detailed error information."
332
+ }
333
+ }
334
+ }
335
+ ```
336
+
337
+ </details>
338
+
339
+ #### Extensions
340
+
341
+ ```yaml
342
+ x-agent:
343
+ recommended_before_use:
344
+ - Check whether md-pipe.config.yml already exists
345
+ human_review:
346
+ required: false
347
+ reason: Safe scaffolding operation; --force requires attention.
348
+ rollback:
349
+ supported: true
350
+ notes: Delete the generated md-pipe.config.yml.
351
+ ```
352
+
353
+ ---
354
+
355
+ ---
356
+
357
+ ## Schemas
358
+
359
+ ### ErrorMessage
360
+
361
+ Type: `object`
362
+
363
+ | Property | Type | Required | Description |
364
+ |---|---|---|---|
365
+ | `message` | `string` | Yes | Error message. |
366
+ | `file` | `string` | No | File path where the error occurred. |
367
+ | `line` | `integer` | No | Line number where the error occurred. |
368
+ | `detail` | `string` | No | Detailed error information. |
369
+
370
+ <details>
371
+ <summary>JSON Schema</summary>
372
+
373
+ ```json
374
+ {
375
+ "type": "object",
376
+ "required": [
377
+ "message"
378
+ ],
379
+ "properties": {
380
+ "message": {
381
+ "type": "string",
382
+ "description": "Error message."
383
+ },
384
+ "file": {
385
+ "type": "string",
386
+ "description": "File path where the error occurred."
387
+ },
388
+ "line": {
389
+ "type": "integer",
390
+ "description": "Line number where the error occurred."
391
+ },
392
+ "detail": {
393
+ "type": "string",
394
+ "description": "Detailed error information."
395
+ }
396
+ }
397
+ }
398
+ ```
399
+
400
+ </details>
@@ -0,0 +1,463 @@
1
+ ---
2
+ title: md-pipe Styling Guide
3
+ ---
4
+
5
+ # md-pipe Styling Guide
6
+
7
+ A collection of styling techniques using md-pipe directives and class assignments.
8
+
9
+ ## Basic: Class-based Table Styling
10
+
11
+ The most fundamental md-pipe pattern — place a self-closing directive before a table to apply a class.
12
+
13
+ ### `.class_name` + table pattern
14
+
15
+ ```markdown
16
+ <!--md-pipe: .metric-table/-->
17
+
18
+ | Metric | Value | Change |
19
+ |---|---|---|
20
+ | Revenue | $12.5M | +15% |
21
+ | Cost | $8.2M | -3% |
22
+ | Margin | 34.4% | +8.2pt |
23
+ ```
24
+
25
+ A self-closing directive (`/-->`) applies the class to the next sibling element. No wrapping needed. On GitHub, it renders as a normal table; in HTML/PDF output, the element gets the specified class for CSS styling.
26
+
27
+ ---
28
+
29
+ ## Technique: Table Data to Charts
30
+
31
+ Write data as Markdown tables so it's readable on GitHub. In HTML/PDF output, client-side JS reads the table and replaces it with a chart.
32
+
33
+ **Benefits:**
34
+
35
+ - Data is readable as-is on GitHub (table rendering)
36
+ - Rich chart visualization in HTML/PDF
37
+ - Single source of truth for data in the Markdown file
38
+
39
+ ### How It Works
40
+
41
+ 1. A directive generates a `<div data-chart="bar">` wrapper around the table
42
+ 2. CSS hides the table: `[data-chart] table { display: none; }`
43
+ 3. Client-side JS finds `[data-chart]` elements, parses the table, and renders ApexCharts
44
+
45
+ ### Configuration
46
+
47
+ ```yaml
48
+ # md-pipe.config.yml
49
+ directives:
50
+ md-pipe: div
51
+
52
+ scripts:
53
+ - https://cdn.jsdelivr.net/npm/apexcharts@3/dist/apexcharts.min.js
54
+ - ./scripts/chart-transform.js
55
+ ```
56
+
57
+ ```css
58
+ /* Hide tables inside chart containers — JS renders the chart instead */
59
+ [data-chart] table { display: none; }
60
+ ```
61
+
62
+ ### Client-side JS
63
+
64
+ The `data-chart` attribute specifies chart type. JS processes it on DOMContentLoaded.
65
+
66
+ ```javascript
67
+ // scripts/chart-transform.js
68
+ (function () {
69
+ function parseTable(tableEl) {
70
+ var ths = tableEl.querySelectorAll('thead th');
71
+ var headers = Array.from(ths).map(function (th) { return th.textContent.trim(); });
72
+ var rows = Array.from(tableEl.querySelectorAll('tbody tr')).map(function (tr) {
73
+ var cells = tr.querySelectorAll('td');
74
+ return Array.from(cells).map(function (td) { return td.textContent.trim(); });
75
+ });
76
+ return { headers: headers, rows: rows };
77
+ }
78
+
79
+ document.addEventListener('DOMContentLoaded', function () {
80
+ document.querySelectorAll('[data-chart]').forEach(function (container) {
81
+ var table = container.querySelector('table');
82
+ if (!table) return;
83
+
84
+ var data = parseTable(table);
85
+ var chartType = container.getAttribute('data-chart');
86
+ var height = parseInt(container.getAttribute('data-height') || '280', 10);
87
+ var colors = (container.getAttribute('data-colors') || '').split(',').filter(Boolean);
88
+
89
+ var labels = data.rows.map(function (r) { return r[0]; });
90
+ var series = data.headers.slice(1).map(function (name, ci) {
91
+ return {
92
+ name: name,
93
+ data: data.rows.map(function (r) { return parseFloat(r[ci + 1]) || 0; })
94
+ };
95
+ });
96
+
97
+ var chartDiv = document.createElement('div');
98
+ container.appendChild(chartDiv);
99
+
100
+ var opts = {
101
+ chart: { type: chartType, height: height, toolbar: { show: false } },
102
+ series: chartType === 'donut' ? series[0].data : series,
103
+ labels: chartType === 'donut' ? labels : undefined,
104
+ xaxis: chartType !== 'donut' ? { categories: labels } : undefined,
105
+ dataLabels: { enabled: false },
106
+ };
107
+ if (colors.length) opts.colors = colors;
108
+ if (chartType === 'stacked-bar') {
109
+ opts.chart.type = 'bar';
110
+ opts.chart.stacked = true;
111
+ }
112
+
113
+ new ApexCharts(chartDiv, opts).render();
114
+ });
115
+ });
116
+ })();
117
+ ```
118
+
119
+ ### Markdown Usage
120
+
121
+ Specify chart type via the `data-chart` attribute. JS reads this attribute and converts the table to a chart.
122
+
123
+ #### Bar Chart
124
+
125
+ ```markdown
126
+ <!--md-pipe: data-chart="bar"/-->
127
+
128
+ | Month | Sales ($K) |
129
+ |---|---|
130
+ | Jan | 120 |
131
+ | Feb | 145 |
132
+ | Mar | 198 |
133
+ | Apr | 167 |
134
+ | May | 210 |
135
+ ```
136
+
137
+ #### Stacked Bar Chart
138
+
139
+ ```markdown
140
+ <!--md-pipe: data-chart="stacked-bar"/-->
141
+
142
+ | Quarter | Product A ($K) | Product B ($K) | Product C ($K) |
143
+ |---|---|---|---|
144
+ | Q1 | 80 | 45 | 30 |
145
+ | Q2 | 92 | 51 | 38 |
146
+ | Q3 | 105 | 60 | 42 |
147
+ | Q4 | 118 | 68 | 55 |
148
+ ```
149
+
150
+ #### Line Chart
151
+
152
+ ```markdown
153
+ <!--md-pipe: data-chart="line"/-->
154
+
155
+ | Date | Response Time (ms) | Error Rate (%) |
156
+ |---|---|---|
157
+ | 05/01 | 120 | 0.3 |
158
+ | 05/02 | 135 | 0.5 |
159
+ | 05/03 | 98 | 0.1 |
160
+ | 05/04 | 142 | 0.8 |
161
+ | 05/05 | 110 | 0.2 |
162
+ ```
163
+
164
+ #### Donut Chart
165
+
166
+ ```markdown
167
+ <!--md-pipe: data-chart="donut"/-->
168
+
169
+ | Category | Count |
170
+ |---|---|
171
+ | Features | 45 |
172
+ | Bug Fixes | 28 |
173
+ | Refactoring | 15 |
174
+ | Documentation | 12 |
175
+ ```
176
+
177
+ #### Options
178
+
179
+ Use `data-height` and `data-colors` to customize chart appearance.
180
+
181
+ ```markdown
182
+ <!--md-pipe: data-chart="bar" data-height="260" data-colors="#3b82f6,#f59e0b,#ef4444"/-->
183
+
184
+ | Month | Revenue | Expenses | Profit |
185
+ |---|---|---|---|
186
+ | Apr | 500 | 320 | 180 |
187
+ | May | 480 | 310 | 170 |
188
+ | Jun | 550 | 340 | 210 |
189
+ ```
190
+
191
+ ### Hidden Data + Chart Annotations
192
+
193
+ Hide a configuration table with `style="display:none"` and use it as chart annotations.
194
+
195
+ ```markdown
196
+ <!--md-pipe: .chart-annotations style="display:none"/-->
197
+
198
+ | date | color | label |
199
+ |---|---|---|
200
+ | 03/15 | #6366f1 | v2.0 Release |
201
+ | 04/01 | #10b981 | Infra Migration |
202
+ ```
203
+
204
+ On GitHub this renders as a normal table. In HTML/PDF output, the JS uses it to draw vertical annotation lines on charts.
205
+
206
+ ---
207
+
208
+ ## Technique: CSS-only Card Layout from Tables
209
+
210
+ Restyle tables as card grids using **CSS only** — no transforms or JS needed. The key is placing an empty `<div class="...">` before the table via a self-closing directive, then using the CSS adjacent sibling selector (`+`) to override the table layout.
211
+
212
+ ### FAQ Cards
213
+
214
+ ```markdown
215
+ <!--md-pipe: .faq-grid/-->
216
+
217
+ | Q | A |
218
+ |---|---|
219
+ | What file formats are supported? | Markdown (.md) only. You can add YAML metadata via frontmatter. |
220
+ | What output formats? | HTML and PDF. Control with the --pipeline option. |
221
+ | Can I use custom themes? | Yes. Specify CSS files in styles, or define themes in config. |
222
+ | How do I write plugins? | Implement a TransformFn in TypeScript and register it in transforms. |
223
+ ```
224
+
225
+ On GitHub this shows as a normal 2-column table. In HTML/PDF, CSS turns it into a card grid.
226
+
227
+ #### Configuration
228
+
229
+ Only the `div` directive is needed. No transform functions required.
230
+
231
+ ```yaml
232
+ # md-pipe.config.yml
233
+ directives:
234
+ md-pipe: div
235
+ ```
236
+
237
+ #### CSS
238
+
239
+ `.faq-grid + table` targets the sibling table and reshapes it into a card grid.
240
+
241
+ ```css
242
+ .faq-grid + table { display: block; border: none; }
243
+
244
+ .faq-grid + table thead { display: none; }
245
+
246
+ .faq-grid + table tbody {
247
+ display: grid;
248
+ grid-template-columns: 1fr 1fr;
249
+ gap: 10px;
250
+ }
251
+
252
+ .faq-grid + table tr {
253
+ display: block;
254
+ background: #f8fafc;
255
+ border: 1px solid #e2e8f0;
256
+ border-radius: 8px;
257
+ padding: 10px 14px;
258
+ break-inside: avoid;
259
+ }
260
+
261
+ .faq-grid + table td {
262
+ display: block;
263
+ border: none;
264
+ padding: 0;
265
+ background: none;
266
+ }
267
+
268
+ .faq-grid + table td:first-child {
269
+ font-weight: 700;
270
+ color: #1e40af;
271
+ margin-bottom: 4px;
272
+ }
273
+
274
+ .faq-grid + table td:last-child {
275
+ font-size: 0.9em;
276
+ line-height: 1.5;
277
+ color: #334155;
278
+ }
279
+ ```
280
+
281
+ ### KPI Cards (Client-side JS)
282
+
283
+ KPI cards require a different DOM structure than tables, so client-side JS replaces the table — same approach as charts.
284
+
285
+ ```markdown
286
+ <!--md-pipe: data-transform="kpi-cards"/-->
287
+
288
+ | label | value | sub | style |
289
+ |---|---|---|---|
290
+ | Latency | 1.2s | -30% vs last month | success |
291
+ | Error Rate | 0.02% | SLA met | success |
292
+ | Throughput | 1,200 req/s | Peak | |
293
+ | Uptime | 99.97% | 30-day | info |
294
+ ```
295
+
296
+ JS reads the table and converts each row into a `.kpi` card. The `style` column controls color variants.
297
+
298
+ ```javascript
299
+ // Add to chart-transform.js
300
+ document.querySelectorAll('[data-transform="kpi-cards"]').forEach(function (container) {
301
+ var table = container.querySelector('table');
302
+ if (!table) return;
303
+ var data = parseTable(table);
304
+ var row = document.createElement('div');
305
+ row.className = 'kpi-row';
306
+ data.rows.forEach(function (r) {
307
+ var style = (r[3] || '').toLowerCase();
308
+ var card = document.createElement('div');
309
+ card.className = 'kpi' + (style ? ' kpi-' + style : '');
310
+ card.innerHTML =
311
+ '<div class="kpi-value">' + r[1] + '</div>' +
312
+ '<div class="kpi-label">' + r[0] + '</div>' +
313
+ (r[2] ? '<div class="kpi-sub">' + r[2] + '</div>' : '');
314
+ row.appendChild(card);
315
+ });
316
+ table.replaceWith(row);
317
+ });
318
+ ```
319
+
320
+ ```css
321
+ .kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 10px 0; }
322
+ .kpi { text-align: center; padding: 12px 8px; border: 1px solid #e5e7eb; border-radius: 8px; }
323
+ .kpi-value { font-size: 22px; font-weight: 700; }
324
+ .kpi-label { font-size: 11px; color: #6b7280; margin-top: 2px; }
325
+ .kpi-sub { font-size: 10px; color: #6b7280; margin-top: 1px; }
326
+ .kpi-success .kpi-value { color: #10b981; }
327
+ .kpi-info .kpi-value { color: #6366f1; }
328
+ ```
329
+
330
+ ---
331
+
332
+ ## Technique: Layout Control
333
+
334
+ ### Grid Layout
335
+
336
+ Arrange charts or tables side-by-side in a 2-column grid.
337
+
338
+ ```markdown
339
+ <!--md-pipe: .grid-2-->
340
+ <!--md-pipe: .col-->
341
+
342
+ ### Monthly
343
+
344
+ <!--md-pipe: data-chart="bar" data-height="200"/-->
345
+
346
+ | Month | Count |
347
+ |---|---|
348
+ | Apr | 32 |
349
+ | May | 45 |
350
+ | Jun | 38 |
351
+
352
+ <!--/md-pipe-->
353
+ <!--md-pipe: .col-->
354
+
355
+ ### Cumulative
356
+
357
+ <!--md-pipe: data-chart="line" data-height="200"/-->
358
+
359
+ | Month | Total |
360
+ |---|---|
361
+ | Apr | 32 |
362
+ | May | 77 |
363
+ | Jun | 115 |
364
+
365
+ <!--/md-pipe-->
366
+ <!--/md-pipe-->
367
+ ```
368
+
369
+ ### Page Break
370
+
371
+ Insert a page break in PDF output.
372
+
373
+ ```markdown
374
+ <!--page-break /-->
375
+ ```
376
+
377
+ ---
378
+
379
+ ## Technique: Semantic Blocks
380
+
381
+ ### Note Block
382
+
383
+ ```markdown
384
+ <!--note: .warning-->
385
+
386
+ This action cannot be undone. Back up your data before proceeding.
387
+
388
+ <!--/note-->
389
+ ```
390
+
391
+ ### Section Intro
392
+
393
+ ```markdown
394
+ <!--md-pipe: .section-intro-->
395
+
396
+ This section evaluates performance improvements quantitatively.
397
+
398
+ <!--/md-pipe-->
399
+ ```
400
+
401
+ ### Summary Card
402
+
403
+ ```markdown
404
+ <!--md-pipe: .summary-card-->
405
+
406
+ ### Conclusion
407
+
408
+ By managing data in tables and controlling presentation through directives,
409
+ you maintain Markdown portability while enabling rich output.
410
+
411
+ <!--/md-pipe-->
412
+ ```
413
+
414
+ ---
415
+
416
+ ## Configuration Example
417
+
418
+ A full project configuration combining the techniques above.
419
+
420
+ ```yaml
421
+ # md-pipe.config.yml
422
+ theme: report
423
+
424
+ themes:
425
+ report:
426
+ styles:
427
+ - ./styles/base.css
428
+ - ./styles/cards.css
429
+
430
+ directives:
431
+ md-pipe: div
432
+ page-break: div
433
+ note: aside .note-block
434
+
435
+ scripts:
436
+ - https://cdn.jsdelivr.net/npm/apexcharts@3/dist/apexcharts.min.js
437
+ - ./scripts/chart-transform.js
438
+
439
+ pipeline: .pdf
440
+ ```
441
+
442
+ ```yaml
443
+ # Frontmatter example
444
+ ---
445
+ title: Monthly Report
446
+ styles:
447
+ - ./styles/report.css
448
+ scripts:
449
+ - https://cdn.jsdelivr.net/npm/apexcharts@3/dist/apexcharts.min.js
450
+ - ./scripts/chart-transform.js
451
+ pipeline: .pdf
452
+ output: ./dist/report.pdf
453
+ ---
454
+ ```
455
+
456
+ ---
457
+
458
+ ## Design Principles
459
+
460
+ 1. **Keep Markdown clean** — no `<div>` tags or framework-specific syntax in source
461
+ 2. **Data readable on GitHub** — use tables for data so it's visible without rendering
462
+ 3. **CSS first** — use adjacent sibling selectors (`.class + table`) to restyle tables. Only use JS or transforms when DOM structure must change
463
+ 4. **Escalate complexity gradually** — CSS only → client-side JS → build-time transforms
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "md-pipe",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A rendering engine that transforms Markdown to HTML/PDF via directive-driven pipelines",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",
@@ -26,6 +26,8 @@
26
26
  "license": "MIT",
27
27
  "files": [
28
28
  "dist",
29
+ "docs",
30
+ "cli-contract.yaml",
29
31
  "README.md"
30
32
  ],
31
33
  "engines": {