flatmarkdown-ast2html 0.1.1 → 0.1.3
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 +25 -8
- package/dist/index.global.js +32 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -12,6 +12,31 @@ bun add flatmarkdown-ast2html
|
|
|
12
12
|
npm install flatmarkdown-ast2html
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## Browser / WebView (IIFE)
|
|
16
|
+
|
|
17
|
+
A minified IIFE build is included for non-module environments (plain `<script>` tags, WebView2, Electron, etc.).
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<script src="https://unpkg.com/flatmarkdown-ast2html@0.1.2/dist/index.global.js"></script>
|
|
21
|
+
<script>
|
|
22
|
+
var html = FmAst2Html.renderToHtml(astJson);
|
|
23
|
+
document.getElementById('content').innerHTML = html;
|
|
24
|
+
</script>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The global `FmAst2Html` object exposes `renderToHtml(ast, options?)`.
|
|
28
|
+
|
|
29
|
+
To pin a specific version, use `@0.1.2` in the URL. Without a version tag, unpkg serves the latest.
|
|
30
|
+
|
|
31
|
+
## Build
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install
|
|
35
|
+
npm run build # outputs dist/ with ESM, CJS, IIFE, and .d.ts
|
|
36
|
+
npm test # runs vitest
|
|
37
|
+
npm publush #
|
|
38
|
+
```
|
|
39
|
+
|
|
15
40
|
## Quick Start
|
|
16
41
|
|
|
17
42
|
```ts
|
|
@@ -185,14 +210,6 @@ renderToHtml(ast, {
|
|
|
185
210
|
|
|
186
211
|
All node types are exported as individual TypeScript interfaces, plus the `AstNode` discriminated union.
|
|
187
212
|
|
|
188
|
-
## Build
|
|
189
|
-
|
|
190
|
-
```bash
|
|
191
|
-
bun install
|
|
192
|
-
bun run build # outputs dist/ with ESM, CJS, and .d.ts
|
|
193
|
-
bun test # runs vitest
|
|
194
|
-
```
|
|
195
|
-
|
|
196
213
|
## License
|
|
197
214
|
|
|
198
215
|
MIT
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";var FmAst2Html=(()=>{var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var b=(e,t)=>{for(var r in t)o(e,r,{get:t[r],enumerable:!0})},_=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of f(t))!k.call(e,a)&&a!==r&&o(e,a,{get:()=>t[a],enumerable:!(s=g(t,a))||s.enumerable});return e};var A=e=>_(o({},"__esModule",{value:!0}),e);var C={};b(C,{renderToHtml:()=>p});function R(e={}){return{options:e,inHeaderRow:!1,tableAlignments:[],cellIndex:0,tightList:!1}}function i(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function n(e,t){return e.children?e.children.map(r=>c(r,t)).join(""):""}function d(e){return e.type==="text"?e.value:"children"in e&&e.children?e.children.map(d).join(""):""}function c(e,t){switch(e.type){case"document":return n(e,t);case"paragraph":{let r=n(e,t);return t.tightList?`${r}
|
|
2
|
+
`:`<p>${r}</p>
|
|
3
|
+
`}case"heading":{let r=`h${e.level}`;return`<${r}>${n(e,t)}</${r}>
|
|
4
|
+
`}case"code_block":{let r=e.info;return`<pre><code${r?` class="language-${i(r)}"`:""}>${i(e.literal)}</code></pre>
|
|
5
|
+
`}case"block_quote":return`<blockquote>
|
|
6
|
+
${n(e,t)}</blockquote>
|
|
7
|
+
`;case"multiline_block_quote":return`<blockquote>
|
|
8
|
+
${n(e,t)}</blockquote>
|
|
9
|
+
`;case"list":return e.list_type==="ordered"?`<ol${e.start!=null&&e.start!==1?` start="${e.start}"`:""}>
|
|
10
|
+
${n(e,t)}</ol>
|
|
11
|
+
`:`<ul>
|
|
12
|
+
${n(e,t)}</ul>
|
|
13
|
+
`;case"item":{let r={...t,tightList:e.tight};return`<li>${n(e,r)}</li>
|
|
14
|
+
`}case"task_item":{let r=e.symbol!=null?' checked=""':"",s={...t,tightList:!0};return`<li><input type="checkbox"${r} disabled="" />${n(e,s)}</li>
|
|
15
|
+
`}case"table":{let r={...t,tableAlignments:e.alignments};return`<table>
|
|
16
|
+
${n(e,r)}</table>
|
|
17
|
+
`}case"table_row":return`<tr>
|
|
18
|
+
${(e.children||[]).map((s,a)=>{let l={...t,inHeaderRow:e.header,cellIndex:a};return c(s,l)}).join("")}</tr>
|
|
19
|
+
`;case"table_cell":{let r=t.inHeaderRow?"th":"td",s=t.tableAlignments[t.cellIndex],a=s&&s!=="none"?` align="${s}"`:"";return`<${r}${a}>${n(e,t)}</${r}>
|
|
20
|
+
`}case"thematic_break":return`<hr />
|
|
21
|
+
`;case"html_block":return e.literal;case"footnote_definition":return`<div class="footnote" id="fn-${i(e.name)}">
|
|
22
|
+
${n(e,t)}</div>
|
|
23
|
+
`;case"description_list":return`<dl>
|
|
24
|
+
${n(e,t)}</dl>
|
|
25
|
+
`;case"description_item":return n(e,t);case"description_term":return`<dt>${n(e,t)}</dt>
|
|
26
|
+
`;case"description_details":return`<dd>${n(e,t)}</dd>
|
|
27
|
+
`;case"alert":return`<div class="alert alert-${i(e.alert_type)}">
|
|
28
|
+
${n(e,t)}</div>
|
|
29
|
+
`;case"front_matter":return"";case"heex_block":return n(e,t);case"subtext":return n(e,t);case"text":return i(e.value);case"softbreak":return`
|
|
30
|
+
`;case"linebreak":return`<br />
|
|
31
|
+
`;case"emph":return`<em>${n(e,t)}</em>`;case"strong":return`<strong>${n(e,t)}</strong>`;case"strikethrough":return`<del>${n(e,t)}</del>`;case"underline":return`<u>${n(e,t)}</u>`;case"highlight":return`<mark>${n(e,t)}</mark>`;case"superscript":return`<sup>${n(e,t)}</sup>`;case"subscript":return`<sub>${n(e,t)}</sub>`;case"spoilered_text":return`<span class="spoiler">${n(e,t)}</span>`;case"code":return`<code>${i(e.literal)}</code>`;case"link":{let r=e.title?` title="${i(e.title)}"`:"";return`<a href="${i(e.url)}"${r}>${n(e,t)}</a>`}case"image":{let r=d(e),s=e.title?` title="${i(e.title)}"`:"";return`<img src="${i(e.url)}" alt="${i(r)}"${s} />`}case"wikilink":{let r=t.options.wikilink,s=r?.tagName??"a",a=r?.urlAttr??"href",l=r?.urlPrefix??"",$=r?.attrs??{"data-wikilink":"true"},h=`${l}${e.url}`,u=`${a}="${i(h)}"`;for(let[m,N]of Object.entries($))u+=` ${m}="${i(N)}"`;return`<${s} ${u}>${n(e,t)}</${s}>`}case"footnote_reference":return`<sup><a href="#fn-${i(e.name)}">[${e.ix+1}]</a></sup>`;case"shortcode":return e.emoji;case"math":return e.display_math?`<pre><code class="math math-display">${i(e.literal)}</code></pre>
|
|
32
|
+
`:`<code class="math math-inline">${i(e.literal)}</code>`;case"html_inline":return e.value;case"heex_inline":return e.value;case"raw":return e.value;case"escaped":return"";case"escaped_tag":return i(e.value);default:{let r=e;return""}}}function p(e,t){let r=typeof e=="string"?JSON.parse(e):e;return c(r,R(t))}return A(C);})();
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flatmarkdown-ast2html",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A library to convert FlatMarkdown AST to HTML.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
+
"unpkg": "./dist/index.global.js",
|
|
9
10
|
"files": [
|
|
10
11
|
"dist"
|
|
11
12
|
],
|