@tanstack/markdown 0.0.1 → 0.0.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAuC,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAA;AAG3J,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAGpF;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CA8ChF;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAwBlF;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAE9F"}
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAuC,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAA;AAG3J,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAGpF;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAsChF;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAwBlF;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAE9F"}
package/dist/html.js CHANGED
@@ -21,14 +21,7 @@ export function renderBlock(node, options = {}) {
21
21
  case 'list': {
22
22
  const tag = node.ordered ? 'ol' : 'ul';
23
23
  const start = node.ordered && node.start && node.start !== 1 ? ` start="${node.start}"` : '';
24
- const items = node.items
25
- .map(item => {
26
- const task = item.checked === undefined
27
- ? ''
28
- : `<input type="checkbox" disabled${item.checked ? ' checked' : ''}> `;
29
- return `<li>${task}${item.children.map(child => renderBlock(child, options)).join('\n')}</li>`;
30
- })
31
- .join('\n');
24
+ const items = node.items.map(item => `<li>${renderListItemChildren(item.children, item.checked, options)}</li>`).join('\n');
32
25
  return `<${tag}${start}>\n${items}\n</${tag}>`;
33
26
  }
34
27
  case 'blockquote':
@@ -104,6 +97,16 @@ function renderCodeBlock(node, options) {
104
97
  return pre;
105
98
  return `<figure class="tm-code-frame" data-lang="${escapeAttr(lang)}"><figcaption>${escapeHtml(node.title)}</figcaption>${pre}</figure>`;
106
99
  }
100
+ function renderListItemChildren(children, checked, options) {
101
+ const [first, ...rest] = children;
102
+ const task = checked === undefined ? '' : `<input type="checkbox" disabled${checked ? ' checked' : ''}> `;
103
+ if (checked !== undefined && first?.type === 'paragraph') {
104
+ const firstLine = `${task}${renderInlines(first.children, options)}`;
105
+ const restHtml = rest.map(child => renderBlock(child, options)).join('\n');
106
+ return restHtml ? `${firstLine}\n${restHtml}` : firstLine;
107
+ }
108
+ return `${task}${children.map(child => renderBlock(child, options)).join('\n')}`;
109
+ }
107
110
  function renderCallout(node, options) {
108
111
  const kind = node.kind.toLowerCase();
109
112
  const children = node.children.map(child => renderBlock(child, options)).join('\n');
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAiB,UAAU,EAAE,aAAa,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAA;AAEnH,KAAK,YAAY,GAA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Q,EAAE,GAAG,OAAO,EAAE,EAAE,aAAa,GAAG,YAAY,CAE9E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,GAAE,oBAAyB,GAAG,SAAS,CAGvG;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,oBAAyB,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,YAAY,CA2DhH;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,oBAAyB,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAuB/G"}
package/dist/react.js CHANGED
@@ -17,14 +17,7 @@ export function renderBlockReact(node, options = {}, key) {
17
17
  return renderCodeBlockReact(node, options, key);
18
18
  case 'list': {
19
19
  const tag = node.ordered ? 'ol' : 'ul';
20
- return h(options, tag, { key, ...(node.ordered && node.start && node.start !== 1 ? { start: node.start } : {}) }, node.items.map((item, index) => h(options, 'li', { key: index }, item.checked === undefined
21
- ? null
22
- : h(options, 'input', {
23
- type: 'checkbox',
24
- disabled: true,
25
- checked: item.checked,
26
- readOnly: true,
27
- }), item.checked === undefined ? null : ' ', item.children.map((child, childIndex) => renderBlockReact(child, options, `${index}:${childIndex}`)))));
20
+ return h(options, tag, { key, ...(node.ordered && node.start && node.start !== 1 ? { start: node.start } : {}) }, node.items.map((item, index) => h(options, 'li', { key: index }, renderListItemChildrenReact(item.children, item.checked, options, `${index}`))));
28
21
  }
29
22
  case 'blockquote':
30
23
  return h(options, 'blockquote', { key }, node.children.map((child, index) => renderBlockReact(child, options, `${key}:${index}`)));
@@ -97,6 +90,29 @@ function renderCodeBlockReact(node, options, key) {
97
90
  return h(options, Fragment, { key }, pre);
98
91
  return h(options, 'figure', { key, className: 'tm-code-frame', 'data-lang': lang }, h(options, 'figcaption', null, node.title), pre);
99
92
  }
93
+ function renderListItemChildrenReact(children, checked, options, key) {
94
+ const [first, ...rest] = children;
95
+ const task = checked === undefined
96
+ ? []
97
+ : [
98
+ h(options, 'input', {
99
+ key: `${key}:checkbox`,
100
+ type: 'checkbox',
101
+ disabled: true,
102
+ checked,
103
+ readOnly: true,
104
+ }),
105
+ ' ',
106
+ ];
107
+ if (checked !== undefined && first?.type === 'paragraph') {
108
+ return [
109
+ ...task,
110
+ ...renderInlines(first.children, options),
111
+ ...rest.map((child, childIndex) => renderBlockReact(child, options, `${key}:${childIndex + 1}`)),
112
+ ];
113
+ }
114
+ return [...task, ...children.map((child, childIndex) => renderBlockReact(child, options, `${key}:${childIndex}`))];
115
+ }
100
116
  function renderTableCellReact(tag, cell, align, options, key) {
101
117
  return h(options, tag, { key, ...(align ? { style: { textAlign: align } } : {}) }, renderInlines(cell.children, options));
102
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/markdown",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "description": "A tiny deterministic TanStack-flavored markdown renderer.",
6
6
  "license": "MIT",