flatmarkdown-ast2html 0.1.3 → 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 +17 -7
- package/dist/index.cjs +24 -4
- package/dist/index.d.cts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.global.js +26 -25
- package/dist/index.js +24 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ npm install flatmarkdown-ast2html
|
|
|
17
17
|
A minified IIFE build is included for non-module environments (plain `<script>` tags, WebView2, Electron, etc.).
|
|
18
18
|
|
|
19
19
|
```html
|
|
20
|
-
<script src="https://unpkg.com/flatmarkdown-ast2html@0.1.
|
|
20
|
+
<script src="https://unpkg.com/flatmarkdown-ast2html@0.1.3"></script>
|
|
21
21
|
<script>
|
|
22
22
|
var html = FmAst2Html.renderToHtml(astJson);
|
|
23
23
|
document.getElementById('content').innerHTML = html;
|
|
@@ -26,15 +26,15 @@ A minified IIFE build is included for non-module environments (plain `<script>`
|
|
|
26
26
|
|
|
27
27
|
The global `FmAst2Html` object exposes `renderToHtml(ast, options?)`.
|
|
28
28
|
|
|
29
|
-
To pin a specific version, use `@0.1.
|
|
29
|
+
To pin a specific version, use `@0.1.3` in the URL. Without a version tag, unpkg serves the latest.
|
|
30
30
|
|
|
31
31
|
## Build
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
34
|
npm install
|
|
35
|
-
npm run build # outputs dist/ with ESM, CJS, IIFE, and .d.ts
|
|
35
|
+
npm run build # outputs dist/ with ESM, CJS, IIFE, and .d.tsう
|
|
36
36
|
npm test # runs vitest
|
|
37
|
-
npm
|
|
37
|
+
npm publish # publish to npm (also available via unpkg)
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Quick Start
|
|
@@ -85,6 +85,7 @@ Returns an HTML string.
|
|
|
85
85
|
```ts
|
|
86
86
|
interface RenderOptions {
|
|
87
87
|
wikilink?: WikiLinkOptions;
|
|
88
|
+
hashtag?: HashtagOptions;
|
|
88
89
|
}
|
|
89
90
|
```
|
|
90
91
|
|
|
@@ -145,6 +146,14 @@ renderToHtml(ast, {
|
|
|
145
146
|
<a href="/docs/page-name" data-wikilink="true">label</a>
|
|
146
147
|
```
|
|
147
148
|
|
|
149
|
+
### `HashtagOptions`
|
|
150
|
+
|
|
151
|
+
Customize how `#hashtag` nodes are rendered. The fields are the same as `WikiLinkOptions`. The url is `urlPrefix` followed by the tag name, and the default extra attribute is `{ 'data-hashtag': 'true' }`.
|
|
152
|
+
|
|
153
|
+
```html
|
|
154
|
+
<a href="todo" data-hashtag="true">#todo</a>
|
|
155
|
+
```
|
|
156
|
+
|
|
148
157
|
## HTML Output Reference
|
|
149
158
|
|
|
150
159
|
### Block Nodes
|
|
@@ -166,7 +175,7 @@ renderToHtml(ast, {
|
|
|
166
175
|
| `table_cell` | `<td>…</td>` or `<th>…</th>` (header row), with `align` attr |
|
|
167
176
|
| `thematic_break` | `<hr />` |
|
|
168
177
|
| `html_block` | Raw passthrough |
|
|
169
|
-
| `footnote_definition` | `<div class="footnote" id="fn-{name}">…</div>` |
|
|
178
|
+
| `footnote_definition` | `<div class="footnote" id="fn-{name}"><a href="#fnref-{name}" class="footnote-label">[{name}]:</a>…</div>` |
|
|
170
179
|
| `description_list` | `<dl>…</dl>` |
|
|
171
180
|
| `description_term` | `<dt>…</dt>` |
|
|
172
181
|
| `description_details` | `<dd>…</dd>` |
|
|
@@ -191,8 +200,9 @@ renderToHtml(ast, {
|
|
|
191
200
|
| `code` | `<code>…</code>` |
|
|
192
201
|
| `link` | `<a href="{url}" title="{title}">…</a>` |
|
|
193
202
|
| `image` | `<img src="{url}" alt="…" title="{title}" />` |
|
|
203
|
+
| `hashtag` | `<a href="{name}" data-hashtag="true">#{name}</a>` |
|
|
194
204
|
| `wikilink` | `<a href="{url}" data-wikilink="true">…</a>` (configurable) |
|
|
195
|
-
| `footnote_reference` | `<sup><a href="#fn-{name}">[{
|
|
205
|
+
| `footnote_reference` | `<sup id="fnref-{name}" class="footnote-ref"><a href="#fn-{name}">[{name}]</a></sup>` |
|
|
196
206
|
| `shortcode` | Emoji character directly |
|
|
197
207
|
| `math` (inline) | `<code class="math math-inline">…</code>` |
|
|
198
208
|
| `math` (display) | `<pre><code class="math math-display">…</code></pre>` |
|
|
@@ -206,7 +216,7 @@ renderToHtml(ast, {
|
|
|
206
216
|
|
|
207
217
|
**Block (23):** `document`, `paragraph`, `heading`, `code_block`, `block_quote`, `multiline_block_quote`, `list`, `item`, `task_item`, `table`, `table_row`, `table_cell`, `thematic_break`, `html_block`, `footnote_definition`, `description_list`, `description_item`, `description_term`, `description_details`, `alert`, `front_matter`, `heex_block`, `subtext`
|
|
208
218
|
|
|
209
|
-
**Inline (
|
|
219
|
+
**Inline (24):** `text`, `softbreak`, `linebreak`, `emph`, `strong`, `strikethrough`, `underline`, `highlight`, `superscript`, `subscript`, `spoilered_text`, `code`, `link`, `image`, `footnote_reference`, `shortcode`, `math`, `html_inline`, `heex_inline`, `raw`, `escaped`, `escaped_tag`, `wikilink`, `hashtag`
|
|
210
220
|
|
|
211
221
|
All node types are exported as individual TypeScript interfaces, plus the `AstNode` discriminated union.
|
|
212
222
|
|
package/dist/index.cjs
CHANGED
|
@@ -131,10 +131,13 @@ ${cells.join("")}</tr>
|
|
|
131
131
|
return "<hr />\n";
|
|
132
132
|
case "html_block":
|
|
133
133
|
return node.literal;
|
|
134
|
-
case "footnote_definition":
|
|
135
|
-
|
|
134
|
+
case "footnote_definition": {
|
|
135
|
+
const name = escapeHtml(node.name);
|
|
136
|
+
return `<div class="footnote" id="fn-${name}">
|
|
137
|
+
<a href="#fnref-${name}" class="footnote-label">[${name}]:</a>
|
|
136
138
|
${renderChildren(node, ctx)}</div>
|
|
137
139
|
`;
|
|
140
|
+
}
|
|
138
141
|
case "description_list":
|
|
139
142
|
return `<dl>
|
|
140
143
|
${renderChildren(node, ctx)}</dl>
|
|
@@ -204,8 +207,25 @@ ${renderChildren(node, ctx)}</div>
|
|
|
204
207
|
}
|
|
205
208
|
return `<${tagName} ${attrStr}>${renderChildren(node, ctx)}</${tagName}>`;
|
|
206
209
|
}
|
|
207
|
-
case "
|
|
208
|
-
|
|
210
|
+
case "hashtag": {
|
|
211
|
+
const opts = ctx.options.hashtag;
|
|
212
|
+
const tagName = opts?.tagName ?? "a";
|
|
213
|
+
const urlAttr = opts?.urlAttr ?? "href";
|
|
214
|
+
const urlPrefix = opts?.urlPrefix ?? "";
|
|
215
|
+
const extraAttrs = opts?.attrs ?? { "data-hashtag": "true" };
|
|
216
|
+
const url = `${urlPrefix}${node.value}`;
|
|
217
|
+
let attrStr = `${urlAttr}="${escapeHtml(url)}"`;
|
|
218
|
+
for (const [key, val] of Object.entries(extraAttrs)) {
|
|
219
|
+
attrStr += ` ${key}="${escapeHtml(val)}"`;
|
|
220
|
+
}
|
|
221
|
+
return `<${tagName} ${attrStr}>#${escapeHtml(node.value)}</${tagName}>`;
|
|
222
|
+
}
|
|
223
|
+
// The label is shown instead of `ix`: an item body is parsed alone, so `ix`
|
|
224
|
+
// restarts at 1 in every item.
|
|
225
|
+
case "footnote_reference": {
|
|
226
|
+
const name = escapeHtml(node.name);
|
|
227
|
+
return `<sup id="fnref-${name}" class="footnote-ref"><a href="#fn-${name}">[${name}]</a></sup>`;
|
|
228
|
+
}
|
|
209
229
|
case "shortcode":
|
|
210
230
|
return node.emoji;
|
|
211
231
|
case "math": {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AstNode } from 'flatmarkdown-ast';
|
|
2
|
-
export { AlertNode, AstNode, BlockQuoteNode, CodeBlockNode, CodeNode, DescriptionDetailsNode, DescriptionItemNode, DescriptionListNode, DescriptionTermNode, DocumentNode, EmphNode, EscapedNode, EscapedTagNode, FootnoteDefinitionNode, FootnoteReferenceNode, FrontMatterNode, HeadingNode, HeexBlockNode, HeexInlineNode, HighlightNode, HtmlBlockNode, HtmlInlineNode, ImageNode, ItemNode, LinebreakNode, LinkNode, ListNode, MathNode, MultilineBlockQuoteNode, ParagraphNode, RawNode, ShortcodeNode, SoftbreakNode, SpoileredTextNode, StrikethroughNode, StrongNode, SubscriptNode, SubtextNode, SuperscriptNode, TableCellNode, TableNode, TableRowNode, TaskItemNode, TextNode, ThematicBreakNode, UnderlineNode, WikilinkNode } from 'flatmarkdown-ast';
|
|
2
|
+
export { AlertNode, AstNode, BlockQuoteNode, CodeBlockNode, CodeNode, DescriptionDetailsNode, DescriptionItemNode, DescriptionListNode, DescriptionTermNode, DocumentNode, EmphNode, EscapedNode, EscapedTagNode, FootnoteDefinitionNode, FootnoteReferenceNode, FrontMatterNode, HashtagNode, HeadingNode, HeexBlockNode, HeexInlineNode, HighlightNode, HtmlBlockNode, HtmlInlineNode, ImageNode, ItemNode, LinebreakNode, LinkNode, ListNode, MathNode, MultilineBlockQuoteNode, ParagraphNode, RawNode, ShortcodeNode, SoftbreakNode, SpoileredTextNode, StrikethroughNode, StrongNode, SubscriptNode, SubtextNode, SuperscriptNode, TableCellNode, TableNode, TableRowNode, TaskItemNode, TextNode, ThematicBreakNode, UnderlineNode, WikilinkNode } from 'flatmarkdown-ast';
|
|
3
3
|
|
|
4
4
|
interface WikiLinkOptions {
|
|
5
5
|
/** Tag name. Default: 'a'. Use 'Link' for React Router, etc. */
|
|
@@ -11,8 +11,19 @@ interface WikiLinkOptions {
|
|
|
11
11
|
/** Extra attributes added to the tag. Default: { 'data-wikilink': 'true' } */
|
|
12
12
|
attrs?: Record<string, string>;
|
|
13
13
|
}
|
|
14
|
+
interface HashtagOptions {
|
|
15
|
+
/** Tag name. Default: 'a'. Use 'Link' for React Router, etc. */
|
|
16
|
+
tagName?: string;
|
|
17
|
+
/** URL attribute name. Default: 'href'. Use 'to' for React Router, etc. */
|
|
18
|
+
urlAttr?: string;
|
|
19
|
+
/** Prefix prepended to the tag name to form the url. Default: '' */
|
|
20
|
+
urlPrefix?: string;
|
|
21
|
+
/** Extra attributes added to the tag. Default: { 'data-hashtag': 'true' } */
|
|
22
|
+
attrs?: Record<string, string>;
|
|
23
|
+
}
|
|
14
24
|
interface RenderOptions {
|
|
15
25
|
wikilink?: WikiLinkOptions;
|
|
26
|
+
hashtag?: HashtagOptions;
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
/**
|
|
@@ -24,4 +35,4 @@ interface RenderOptions {
|
|
|
24
35
|
*/
|
|
25
36
|
declare function renderToHtml(ast: AstNode | string, options?: RenderOptions): string;
|
|
26
37
|
|
|
27
|
-
export { type RenderOptions, type WikiLinkOptions, renderToHtml };
|
|
38
|
+
export { type HashtagOptions, type RenderOptions, type WikiLinkOptions, renderToHtml };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AstNode } from 'flatmarkdown-ast';
|
|
2
|
-
export { AlertNode, AstNode, BlockQuoteNode, CodeBlockNode, CodeNode, DescriptionDetailsNode, DescriptionItemNode, DescriptionListNode, DescriptionTermNode, DocumentNode, EmphNode, EscapedNode, EscapedTagNode, FootnoteDefinitionNode, FootnoteReferenceNode, FrontMatterNode, HeadingNode, HeexBlockNode, HeexInlineNode, HighlightNode, HtmlBlockNode, HtmlInlineNode, ImageNode, ItemNode, LinebreakNode, LinkNode, ListNode, MathNode, MultilineBlockQuoteNode, ParagraphNode, RawNode, ShortcodeNode, SoftbreakNode, SpoileredTextNode, StrikethroughNode, StrongNode, SubscriptNode, SubtextNode, SuperscriptNode, TableCellNode, TableNode, TableRowNode, TaskItemNode, TextNode, ThematicBreakNode, UnderlineNode, WikilinkNode } from 'flatmarkdown-ast';
|
|
2
|
+
export { AlertNode, AstNode, BlockQuoteNode, CodeBlockNode, CodeNode, DescriptionDetailsNode, DescriptionItemNode, DescriptionListNode, DescriptionTermNode, DocumentNode, EmphNode, EscapedNode, EscapedTagNode, FootnoteDefinitionNode, FootnoteReferenceNode, FrontMatterNode, HashtagNode, HeadingNode, HeexBlockNode, HeexInlineNode, HighlightNode, HtmlBlockNode, HtmlInlineNode, ImageNode, ItemNode, LinebreakNode, LinkNode, ListNode, MathNode, MultilineBlockQuoteNode, ParagraphNode, RawNode, ShortcodeNode, SoftbreakNode, SpoileredTextNode, StrikethroughNode, StrongNode, SubscriptNode, SubtextNode, SuperscriptNode, TableCellNode, TableNode, TableRowNode, TaskItemNode, TextNode, ThematicBreakNode, UnderlineNode, WikilinkNode } from 'flatmarkdown-ast';
|
|
3
3
|
|
|
4
4
|
interface WikiLinkOptions {
|
|
5
5
|
/** Tag name. Default: 'a'. Use 'Link' for React Router, etc. */
|
|
@@ -11,8 +11,19 @@ interface WikiLinkOptions {
|
|
|
11
11
|
/** Extra attributes added to the tag. Default: { 'data-wikilink': 'true' } */
|
|
12
12
|
attrs?: Record<string, string>;
|
|
13
13
|
}
|
|
14
|
+
interface HashtagOptions {
|
|
15
|
+
/** Tag name. Default: 'a'. Use 'Link' for React Router, etc. */
|
|
16
|
+
tagName?: string;
|
|
17
|
+
/** URL attribute name. Default: 'href'. Use 'to' for React Router, etc. */
|
|
18
|
+
urlAttr?: string;
|
|
19
|
+
/** Prefix prepended to the tag name to form the url. Default: '' */
|
|
20
|
+
urlPrefix?: string;
|
|
21
|
+
/** Extra attributes added to the tag. Default: { 'data-hashtag': 'true' } */
|
|
22
|
+
attrs?: Record<string, string>;
|
|
23
|
+
}
|
|
14
24
|
interface RenderOptions {
|
|
15
25
|
wikilink?: WikiLinkOptions;
|
|
26
|
+
hashtag?: HashtagOptions;
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
/**
|
|
@@ -24,4 +35,4 @@ interface RenderOptions {
|
|
|
24
35
|
*/
|
|
25
36
|
declare function renderToHtml(ast: AstNode | string, options?: RenderOptions): string;
|
|
26
37
|
|
|
27
|
-
export { type RenderOptions, type WikiLinkOptions, renderToHtml };
|
|
38
|
+
export { type HashtagOptions, type RenderOptions, type WikiLinkOptions, renderToHtml };
|
package/dist/index.global.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
"use strict";var FmAst2Html=(()=>{var
|
|
2
|
-
`:`<p>${
|
|
3
|
-
`}case"heading":{let
|
|
4
|
-
`}case"code_block":{let
|
|
1
|
+
"use strict";var FmAst2Html=(()=>{var $=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var b=(e,r)=>{for(var t in r)$(e,t,{get:r[t],enumerable:!0})},_=(e,r,t,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of f(r))!k.call(e,i)&&i!==t&&$(e,i,{get:()=>r[i],enumerable:!(a=N(r,i))||a.enumerable});return e};var A=e=>_($({},"__esModule",{value:!0}),e);var v={};b(v,{renderToHtml:()=>g});function R(e={}){return{options:e,inHeaderRow:!1,tableAlignments:[],cellIndex:0,tightList:!1}}function s(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function n(e,r){return e.children?e.children.map(t=>h(t,r)).join(""):""}function m(e){return e.type==="text"?e.value:"children"in e&&e.children?e.children.map(m).join(""):""}function h(e,r){switch(e.type){case"document":return n(e,r);case"paragraph":{let t=n(e,r);return r.tightList?`${t}
|
|
2
|
+
`:`<p>${t}</p>
|
|
3
|
+
`}case"heading":{let t=`h${e.level}`;return`<${t}>${n(e,r)}</${t}>
|
|
4
|
+
`}case"code_block":{let t=e.info;return`<pre><code${t?` class="language-${s(t)}"`:""}>${s(e.literal)}</code></pre>
|
|
5
5
|
`}case"block_quote":return`<blockquote>
|
|
6
|
-
${n(e,
|
|
6
|
+
${n(e,r)}</blockquote>
|
|
7
7
|
`;case"multiline_block_quote":return`<blockquote>
|
|
8
|
-
${n(e,
|
|
8
|
+
${n(e,r)}</blockquote>
|
|
9
9
|
`;case"list":return e.list_type==="ordered"?`<ol${e.start!=null&&e.start!==1?` start="${e.start}"`:""}>
|
|
10
|
-
${n(e,
|
|
10
|
+
${n(e,r)}</ol>
|
|
11
11
|
`:`<ul>
|
|
12
|
-
${n(e,
|
|
13
|
-
`;case"item":{let
|
|
14
|
-
`}case"task_item":{let
|
|
15
|
-
`}case"table":{let
|
|
16
|
-
${n(e,
|
|
12
|
+
${n(e,r)}</ul>
|
|
13
|
+
`;case"item":{let t={...r,tightList:e.tight};return`<li>${n(e,t)}</li>
|
|
14
|
+
`}case"task_item":{let t=e.symbol!=null?' checked=""':"",a={...r,tightList:!0};return`<li><input type="checkbox"${t} disabled="" />${n(e,a)}</li>
|
|
15
|
+
`}case"table":{let t={...r,tableAlignments:e.alignments};return`<table>
|
|
16
|
+
${n(e,t)}</table>
|
|
17
17
|
`}case"table_row":return`<tr>
|
|
18
|
-
${(e.children||[]).map((
|
|
19
|
-
`;case"table_cell":{let r
|
|
18
|
+
${(e.children||[]).map((a,i)=>{let l={...r,inHeaderRow:e.header,cellIndex:i};return h(a,l)}).join("")}</tr>
|
|
19
|
+
`;case"table_cell":{let t=r.inHeaderRow?"th":"td",a=r.tableAlignments[r.cellIndex],i=a&&a!=="none"?` align="${a}"`:"";return`<${t}${i}>${n(e,r)}</${t}>
|
|
20
20
|
`}case"thematic_break":return`<hr />
|
|
21
|
-
`;case"html_block":return e.literal;case"footnote_definition":return`<div class="footnote" id="fn-${
|
|
22
|
-
${
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
`;case"
|
|
27
|
-
`;case"
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
`;case"html_block":return e.literal;case"footnote_definition":{let t=s(e.name);return`<div class="footnote" id="fn-${t}">
|
|
22
|
+
<a href="#fnref-${t}" class="footnote-label">[${t}]:</a>
|
|
23
|
+
${n(e,r)}</div>
|
|
24
|
+
`}case"description_list":return`<dl>
|
|
25
|
+
${n(e,r)}</dl>
|
|
26
|
+
`;case"description_item":return n(e,r);case"description_term":return`<dt>${n(e,r)}</dt>
|
|
27
|
+
`;case"description_details":return`<dd>${n(e,r)}</dd>
|
|
28
|
+
`;case"alert":return`<div class="alert alert-${s(e.alert_type)}">
|
|
29
|
+
${n(e,r)}</div>
|
|
30
|
+
`;case"front_matter":return"";case"heex_block":return n(e,r);case"subtext":return n(e,r);case"text":return s(e.value);case"softbreak":return`
|
|
30
31
|
`;case"linebreak":return`<br />
|
|
31
|
-
`;case"emph":return`<em>${n(e,
|
|
32
|
-
`:`<code class="math math-inline">${
|
|
32
|
+
`;case"emph":return`<em>${n(e,r)}</em>`;case"strong":return`<strong>${n(e,r)}</strong>`;case"strikethrough":return`<del>${n(e,r)}</del>`;case"underline":return`<u>${n(e,r)}</u>`;case"highlight":return`<mark>${n(e,r)}</mark>`;case"superscript":return`<sup>${n(e,r)}</sup>`;case"subscript":return`<sub>${n(e,r)}</sub>`;case"spoilered_text":return`<span class="spoiler">${n(e,r)}</span>`;case"code":return`<code>${s(e.literal)}</code>`;case"link":{let t=e.title?` title="${s(e.title)}"`:"";return`<a href="${s(e.url)}"${t}>${n(e,r)}</a>`}case"image":{let t=m(e),a=e.title?` title="${s(e.title)}"`:"";return`<img src="${s(e.url)}" alt="${s(t)}"${a} />`}case"wikilink":{let t=r.options.wikilink,a=t?.tagName??"a",i=t?.urlAttr??"href",l=t?.urlPrefix??"",c=t?.attrs??{"data-wikilink":"true"},u=`${l}${e.url}`,o=`${i}="${s(u)}"`;for(let[d,p]of Object.entries(c))o+=` ${d}="${s(p)}"`;return`<${a} ${o}>${n(e,r)}</${a}>`}case"hashtag":{let t=r.options.hashtag,a=t?.tagName??"a",i=t?.urlAttr??"href",l=t?.urlPrefix??"",c=t?.attrs??{"data-hashtag":"true"},u=`${l}${e.value}`,o=`${i}="${s(u)}"`;for(let[d,p]of Object.entries(c))o+=` ${d}="${s(p)}"`;return`<${a} ${o}>#${s(e.value)}</${a}>`}case"footnote_reference":{let t=s(e.name);return`<sup id="fnref-${t}" class="footnote-ref"><a href="#fn-${t}">[${t}]</a></sup>`}case"shortcode":return e.emoji;case"math":return e.display_math?`<pre><code class="math math-display">${s(e.literal)}</code></pre>
|
|
33
|
+
`:`<code class="math math-inline">${s(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 s(e.value);default:{let t=e;return""}}}function g(e,r){let t=typeof e=="string"?JSON.parse(e):e;return h(t,R(r))}return A(v);})();
|
package/dist/index.js
CHANGED
|
@@ -105,10 +105,13 @@ ${cells.join("")}</tr>
|
|
|
105
105
|
return "<hr />\n";
|
|
106
106
|
case "html_block":
|
|
107
107
|
return node.literal;
|
|
108
|
-
case "footnote_definition":
|
|
109
|
-
|
|
108
|
+
case "footnote_definition": {
|
|
109
|
+
const name = escapeHtml(node.name);
|
|
110
|
+
return `<div class="footnote" id="fn-${name}">
|
|
111
|
+
<a href="#fnref-${name}" class="footnote-label">[${name}]:</a>
|
|
110
112
|
${renderChildren(node, ctx)}</div>
|
|
111
113
|
`;
|
|
114
|
+
}
|
|
112
115
|
case "description_list":
|
|
113
116
|
return `<dl>
|
|
114
117
|
${renderChildren(node, ctx)}</dl>
|
|
@@ -178,8 +181,25 @@ ${renderChildren(node, ctx)}</div>
|
|
|
178
181
|
}
|
|
179
182
|
return `<${tagName} ${attrStr}>${renderChildren(node, ctx)}</${tagName}>`;
|
|
180
183
|
}
|
|
181
|
-
case "
|
|
182
|
-
|
|
184
|
+
case "hashtag": {
|
|
185
|
+
const opts = ctx.options.hashtag;
|
|
186
|
+
const tagName = opts?.tagName ?? "a";
|
|
187
|
+
const urlAttr = opts?.urlAttr ?? "href";
|
|
188
|
+
const urlPrefix = opts?.urlPrefix ?? "";
|
|
189
|
+
const extraAttrs = opts?.attrs ?? { "data-hashtag": "true" };
|
|
190
|
+
const url = `${urlPrefix}${node.value}`;
|
|
191
|
+
let attrStr = `${urlAttr}="${escapeHtml(url)}"`;
|
|
192
|
+
for (const [key, val] of Object.entries(extraAttrs)) {
|
|
193
|
+
attrStr += ` ${key}="${escapeHtml(val)}"`;
|
|
194
|
+
}
|
|
195
|
+
return `<${tagName} ${attrStr}>#${escapeHtml(node.value)}</${tagName}>`;
|
|
196
|
+
}
|
|
197
|
+
// The label is shown instead of `ix`: an item body is parsed alone, so `ix`
|
|
198
|
+
// restarts at 1 in every item.
|
|
199
|
+
case "footnote_reference": {
|
|
200
|
+
const name = escapeHtml(node.name);
|
|
201
|
+
return `<sup id="fnref-${name}" class="footnote-ref"><a href="#fn-${name}">[${name}]</a></sup>`;
|
|
202
|
+
}
|
|
183
203
|
case "shortcode":
|
|
184
204
|
return node.emoji;
|
|
185
205
|
case "math": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flatmarkdown-ast2html",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "A library to convert FlatMarkdown AST to HTML.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"author": "Hidekazu Kubota",
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"flatmarkdown-ast": "^0.
|
|
43
|
+
"flatmarkdown-ast": "^0.2.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"tsup": "^8.0.0",
|