@thi.ng/hiccup-markdown 3.2.167 → 3.2.169
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 +10 -8
- package/package.json +13 -13
- package/serialize.d.ts +11 -1
package/README.md
CHANGED
|
@@ -296,15 +296,15 @@ defaults/outputs.
|
|
|
296
296
|
|
|
297
297
|
Example with custom link elements:
|
|
298
298
|
|
|
299
|
-
```ts
|
|
299
|
+
```ts tangle:export/readme-parse.ts
|
|
300
300
|
import { parse, type TagTransforms } from "@thi.ng/hiccup-markdown";
|
|
301
301
|
|
|
302
302
|
const tags: Partial<TagTransforms> = {
|
|
303
|
-
link: (ctx, href, body) => ["a.link.blue", { href }, ...body]
|
|
303
|
+
link: (ctx, href, title, body) => ["a.link.blue", { href }, ...body]
|
|
304
304
|
};
|
|
305
305
|
|
|
306
306
|
// parse with custom tag transform overrides
|
|
307
|
-
parse("[label](url)", { tags }).result;
|
|
307
|
+
console.log(parse("[label](url)", { tags }).result);
|
|
308
308
|
// [
|
|
309
309
|
// ["p", {}, ["a.link.blue", { href: "url" }, "label"]]
|
|
310
310
|
// ]
|
|
@@ -312,14 +312,14 @@ parse("[label](url)", { tags }).result;
|
|
|
312
312
|
|
|
313
313
|
### Serializing to HTML
|
|
314
314
|
|
|
315
|
-
```ts
|
|
315
|
+
```ts tangle:export/readme-serialize.ts
|
|
316
316
|
import { serialize } from "@thi.ng/hiccup";
|
|
317
317
|
import { parse } from "@thi.ng/hiccup-markdown";
|
|
318
318
|
|
|
319
319
|
const src = `# Hello world\n[This is a _test_](http://example.com) :smile:`;
|
|
320
320
|
|
|
321
321
|
// convert to hiccup tree
|
|
322
|
-
parse(src).result
|
|
322
|
+
console.log(parse(src).result);
|
|
323
323
|
// [
|
|
324
324
|
// [ "h1", { id: "hello-world" }, "Hello world" ],
|
|
325
325
|
// [
|
|
@@ -336,8 +336,8 @@ parse(src).result
|
|
|
336
336
|
// ]
|
|
337
337
|
// ]
|
|
338
338
|
|
|
339
|
-
//
|
|
340
|
-
serialize(parse(src).result);
|
|
339
|
+
// roundtrip, serialize back to HTML
|
|
340
|
+
console.log(serialize(parse(src).result));
|
|
341
341
|
// <h1 id="hello-world">Hello world</h1><p><a href="http://example.com">This is a <em>test</em></a> 😄</p>
|
|
342
342
|
```
|
|
343
343
|
|
|
@@ -387,7 +387,7 @@ See source code for reference.
|
|
|
387
387
|
|
|
388
388
|
### Usage examples
|
|
389
389
|
|
|
390
|
-
```ts
|
|
390
|
+
```ts tangle:export/readme-serialize2.ts
|
|
391
391
|
import { serialize } from "@thi.ng/hiccup-markdown";
|
|
392
392
|
|
|
393
393
|
// list component
|
|
@@ -408,6 +408,7 @@ const thingLink = (_, id, label) =>
|
|
|
408
408
|
|
|
409
409
|
// Note: the same hiccup tree can be serialized to HTML via @thi.ng/hiccup or
|
|
410
410
|
// used interactively in the browser w/ @thi.ng/hdom
|
|
411
|
+
console.log(
|
|
411
412
|
serialize(
|
|
412
413
|
["div",
|
|
413
414
|
["h1", "Hello Markdown"],
|
|
@@ -441,6 +442,7 @@ serialize(
|
|
|
441
442
|
// optional context object passed to all component functions
|
|
442
443
|
{ magic: 42 }
|
|
443
444
|
)
|
|
445
|
+
);
|
|
444
446
|
```
|
|
445
447
|
|
|
446
448
|
Resulting Markdown:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/hiccup-markdown",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.169",
|
|
4
4
|
"description": "Markdown parser & serializer from/to Hiccup format",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -39,17 +39,17 @@
|
|
|
39
39
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@thi.ng/api": "^8.12.
|
|
43
|
-
"@thi.ng/arrays": "^2.13.
|
|
44
|
-
"@thi.ng/checks": "^3.7.
|
|
45
|
-
"@thi.ng/defmulti": "^3.0.
|
|
46
|
-
"@thi.ng/emoji": "^1.0.
|
|
47
|
-
"@thi.ng/errors": "^2.5.
|
|
48
|
-
"@thi.ng/hiccup": "^5.3.
|
|
49
|
-
"@thi.ng/logger": "^3.2.
|
|
50
|
-
"@thi.ng/parse": "^2.6.
|
|
51
|
-
"@thi.ng/strings": "^3.9.
|
|
52
|
-
"@thi.ng/text-canvas": "^3.0.
|
|
42
|
+
"@thi.ng/api": "^8.12.7",
|
|
43
|
+
"@thi.ng/arrays": "^2.13.16",
|
|
44
|
+
"@thi.ng/checks": "^3.7.23",
|
|
45
|
+
"@thi.ng/defmulti": "^3.0.83",
|
|
46
|
+
"@thi.ng/emoji": "^1.0.26",
|
|
47
|
+
"@thi.ng/errors": "^2.5.47",
|
|
48
|
+
"@thi.ng/hiccup": "^5.3.29",
|
|
49
|
+
"@thi.ng/logger": "^3.2.6",
|
|
50
|
+
"@thi.ng/parse": "^2.6.35",
|
|
51
|
+
"@thi.ng/strings": "^3.9.27",
|
|
52
|
+
"@thi.ng/text-canvas": "^3.0.97"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"esbuild": "^0.25.11",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
],
|
|
102
102
|
"year": 2018
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "fc8b300a00eb479497b27467900b13d3152089ad\n"
|
|
105
105
|
}
|
package/serialize.d.ts
CHANGED
|
@@ -5,6 +5,16 @@ export interface SerializeState {
|
|
|
5
5
|
pre?: boolean;
|
|
6
6
|
blockquote?: boolean;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Serializes given hiccup tree to Markdown. The optional provided context `ctx`
|
|
10
|
+
* arg can be used to provide arbitrary state to components/functions embedded
|
|
11
|
+
* in the tree. See [thi.ng/hiccup
|
|
12
|
+
* docs](https://docs.thi.ng/umbrella/hiccup/index.html#user-context-injection)
|
|
13
|
+
* for details.
|
|
14
|
+
*
|
|
15
|
+
* @param tree
|
|
16
|
+
* @param ctx
|
|
17
|
+
*/
|
|
18
|
+
export declare const serialize: (tree: any, ctx?: any) => string;
|
|
9
19
|
export declare const serializeElement: import("@thi.ng/defmulti").MultiFn3<any, any, SerializeState, string>;
|
|
10
20
|
//# sourceMappingURL=serialize.d.ts.map
|