md-pipe 0.3.0 → 0.4.0

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,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.4.0",
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": {
@@ -34,6 +36,7 @@
34
36
  "dependencies": {
35
37
  "cheerio": "^1.2.0",
36
38
  "commander": "^14.0.3",
39
+ "handlebars": "^4.7.9",
37
40
  "js-yaml": "^4.1.1",
38
41
  "marked": "^18.0.3",
39
42
  "puppeteer": "^25.0.2"