@paperclover/markodown 1.0.0-rc.8 → 1.0.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.
- package/README.md +14 -14
- package/_dist/mod.d.ts +75 -30
- package/_dist/mod.d.ts.map +1 -1
- package/bindgen/wasm_bytes.js +1 -1
- package/mod.js +44 -1
- package/mod.js.map +1 -1
- package/mod.ts +138 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
# Markodown
|
|
2
2
|
|
|
3
|
-
> STATUS: Markodown is not yet in use at paperclover.net. However, the API is
|
|
4
|
-
> complete and the library is functional. Give it a try!
|
|
5
|
-
|
|
6
3
|
This is a weird markup language that combines features of [Markdown] and
|
|
7
4
|
[Marko]. You can think of this as an alternative universe to MDX. Since Marko
|
|
8
5
|
components are really easy to write, it makes this a great tool for writing
|
|
9
6
|
interactive blog posts. Markdown is compiled directly into `.marko` syntax,
|
|
10
7
|
leveraging the existing ecosystem.
|
|
11
8
|
|
|
9
|
+
Markodown is used in production for
|
|
10
|
+
[my blog posts on paperclover.net](https://paperclover.net), where I ported my
|
|
11
|
+
posts from MDX to it.
|
|
12
|
+
|
|
12
13
|
[Markdown]: https://en.wikipedia.org/wiki/Markdown
|
|
13
14
|
[Marko]: https://markojs.com/
|
|
14
15
|
|
|
15
|
-
> **CONTENTS**:
|
|
16
|
-
>
|
|
17
16
|
> - [Usage](#usage)
|
|
18
17
|
> - [Components](#components)
|
|
19
18
|
> - [Outline / Table of Contents](#outline-table-of-contents)
|
|
@@ -24,7 +23,7 @@ leveraging the existing ecosystem.
|
|
|
24
23
|
> - [Config](#config)
|
|
25
24
|
> - [Frontmatter Layout Configuration](#frontmatter-layout-configuration)
|
|
26
25
|
|
|
27
|
-
Here's a glance at how things look. Complete example documents in
|
|
26
|
+
Here's a glance at how things look. Complete example documents in `examples`.
|
|
28
27
|
|
|
29
28
|
````
|
|
30
29
|
---
|
|
@@ -271,21 +270,22 @@ import { Heading } from "@clo/markodown";
|
|
|
271
270
|
|
|
272
271
|
export interface Input {
|
|
273
272
|
content: Marko.Body;
|
|
274
|
-
|
|
275
|
-
/** Markdown scans for headings (h1..h6) */
|
|
273
|
+
// Markdown scans for headings (h1..h6)
|
|
276
274
|
outline: Heading[];
|
|
277
|
-
|
|
278
|
-
|
|
275
|
+
// This is the namespace import of the main document.
|
|
276
|
+
// You can reflect frontmatter, or do whatever with this.
|
|
279
277
|
module: Record<string, unknown>;
|
|
280
278
|
}
|
|
281
279
|
|
|
282
280
|
<main>
|
|
283
281
|
<h1>${input.module.title ?? "Blog Post"}</h1>
|
|
284
282
|
<aside>
|
|
285
|
-
<
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
283
|
+
<ul>
|
|
284
|
+
<for|heading| of=input.outline>
|
|
285
|
+
// heading content includes formatting, even custom tags.
|
|
286
|
+
<li><a href=`#${heading.id}`><${heading.content}/></a></li>
|
|
287
|
+
</for>
|
|
288
|
+
</ul>
|
|
289
289
|
</aside>
|
|
290
290
|
|
|
291
291
|
<${input.content} />
|
package/_dist/mod.d.ts
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
type Transformed = Success | Failure;
|
|
2
|
-
export
|
|
3
|
-
|
|
1
|
+
/** The result of a Markodown transform */ export type Transformed = Success | Failure;
|
|
2
|
+
/** Convert Markodown (`.mdo`) source code into Marko source code (`.marko`) */ export declare function transform(options: TransformOptions): Transformed;
|
|
3
|
+
/**
|
|
4
|
+
* Converts a flat document outline into a nested tree. You can consume this
|
|
5
|
+
* tree with a recursive Marko component:
|
|
6
|
+
|
|
7
|
+
* ```marko
|
|
8
|
+
* <define/Recurse|input: HeadingTree|>
|
|
9
|
+
* <a href=`#${input.id}`><${input.content} /></a>
|
|
10
|
+
|
|
11
|
+
* <if=input.children.length>
|
|
12
|
+
* <ul><for|item| of=input.children>
|
|
13
|
+
* <li><Recurse ...item /></li>
|
|
14
|
+
* </></ul>
|
|
15
|
+
* </>
|
|
16
|
+
* </>
|
|
17
|
+
*
|
|
18
|
+
* <div#toc>
|
|
19
|
+
* <h2>Contents:</h2>
|
|
20
|
+
* <for|item| of=groups>
|
|
21
|
+
* <li><Recurse ...item /></li>
|
|
22
|
+
* </>
|
|
23
|
+
* </div>
|
|
24
|
+
* ```
|
|
25
|
+
*/ export declare function outlineToTree(outline: Heading[]): HeadingTree[];
|
|
26
|
+
/** Options for {@linkcode transform}. */ export interface TransformOptions {
|
|
27
|
+
/** The Markodown source code to be transformed */ source: string;
|
|
4
28
|
/**
|
|
5
29
|
* Specify the allowed output formats. For simplicity, pass `marko`. By
|
|
6
30
|
* including `html`, you can opt into a faster codepath where plain HTML is
|
|
@@ -18,13 +42,14 @@ export interface TransformOptions {
|
|
|
18
42
|
*/ markdownOnly?: boolean;
|
|
19
43
|
/**
|
|
20
44
|
* These extensions are special-cased so that Clover can re-use this on
|
|
21
|
-
* her website without
|
|
45
|
+
* her website without maintaining a second markdown parser. I promise
|
|
46
|
+
* we are not wasting your bundle size on my features.
|
|
22
47
|
*/ cloverExtensions?: CloverQuestionExtensions;
|
|
23
48
|
}
|
|
24
49
|
/** Replace Built In Elements */ export interface ComponentImports {
|
|
25
50
|
/** Replace (h1-h6) with this import. Receives attribute `level: number`. */ heading?: string;
|
|
26
51
|
/** Replace `pre > code` with this import. */ codeBlock?: string;
|
|
27
|
-
/** Replace
|
|
52
|
+
/** Replace links with this import. */ link?: string;
|
|
28
53
|
/** Replace images with this import. */ image?: string;
|
|
29
54
|
/** Replace blockquotes with this import. */ blockquote?: string;
|
|
30
55
|
}
|
|
@@ -36,6 +61,8 @@ export interface TransformOptions {
|
|
|
36
61
|
* emit custom HTML elements instead of imported components.
|
|
37
62
|
*
|
|
38
63
|
* Also includes `@html <raw>` block syntax for raw HTML passthrough.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
39
66
|
*/ export interface CloverQuestionExtensions {
|
|
40
67
|
/**
|
|
41
68
|
* Element name for question blocks. Not an import path.
|
|
@@ -59,36 +86,54 @@ export interface TransformOptions {
|
|
|
59
86
|
* `#name#` -> `<labelledRedaction>name</labelledRedaction>`
|
|
60
87
|
*/ labelledRedaction: string;
|
|
61
88
|
}
|
|
62
|
-
export type OutputFormat = "marko" | "html";
|
|
63
|
-
export interface Success {
|
|
64
|
-
success: true;
|
|
65
|
-
text: string;
|
|
66
|
-
|
|
67
|
-
|
|
89
|
+
/** The transformer currently supports two output formats. */ export type OutputFormat = "marko" | "html";
|
|
90
|
+
/** The transform is a success when `success: true` or there are no errors. */ export interface Success {
|
|
91
|
+
/** Easy boolean to discriminate {@linkcode TransformResult} */ success: true;
|
|
92
|
+
/** The transformed text. Format is determined by `format` */ text: string;
|
|
93
|
+
/** The resolved output format of `text` */ format: OutputFormat;
|
|
94
|
+
/** List of errors, if any */ errors: [];
|
|
68
95
|
}
|
|
69
|
-
export interface Failure {
|
|
70
|
-
success: false;
|
|
71
|
-
text: null;
|
|
72
|
-
|
|
73
|
-
|
|
96
|
+
/** The transform is a success when `success: false` or there is at least one error. */ export interface Failure {
|
|
97
|
+
/** Easy boolean to discriminate {@linkcode TransformResult} */ success: false;
|
|
98
|
+
/** The transformed text. Format is determined by `format` */ text: null;
|
|
99
|
+
/** The resolved output format of `text` */ format: null;
|
|
100
|
+
/** List of errors, if any */ errors: [TransformError, ...TransformError[]];
|
|
74
101
|
}
|
|
75
|
-
export interface
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
102
|
+
/** This is passed to Markodown layouts */ export interface LayoutInput {
|
|
103
|
+
/**
|
|
104
|
+
* Scanned from heading tags, the document outline is provided flat here. You
|
|
105
|
+
* can convert it into a nested tree with {@linkcode outlineToTree}
|
|
106
|
+
*/ outline: Heading[];
|
|
107
|
+
/**
|
|
108
|
+
* A copy of the Module Namespace object of the page. Use this to reflect
|
|
109
|
+
* frontmatter or other customizable exports. Don't render `module.default` as
|
|
110
|
+
* a component, since that will recursively call this layout.
|
|
111
|
+
*/ module: Record<string, unknown>;
|
|
112
|
+
/** The rendered document */ // @ts-ignore fails if marko types not chilling
|
|
79
113
|
content: Marko.Body;
|
|
80
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Scanned from heading tags, this represents one heading in the document. You
|
|
117
|
+
* can convert it into a nested tree with {@linkcode outlineToTree}
|
|
118
|
+
*/ export interface Heading {
|
|
119
|
+
/** Which header element this corresponds to. */ level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
120
|
+
/** The link ID. Derived from the `id` attribute of the heading, or generated for you otherwise. */ id: string;
|
|
121
|
+
/** The rendered heading name */ // @ts-ignore fails if marko types not chilling
|
|
122
|
+
content: Marko.Body;
|
|
123
|
+
}
|
|
124
|
+
/** Generated by {@linkcode outlineToTree} */ export interface HeadingTree extends Heading {
|
|
125
|
+
/** Sub-headings */ children: HeadingTree[];
|
|
126
|
+
}
|
|
81
127
|
export interface TransformError {
|
|
82
|
-
message: string;
|
|
83
|
-
|
|
84
|
-
line: number;
|
|
85
|
-
column: number;
|
|
128
|
+
/** What went wrong? */ message: string;
|
|
129
|
+
/** Additional notes for the failure */ notes: TransformNote[];
|
|
130
|
+
/** One-based line */ line: number;
|
|
131
|
+
/** One-based column, byte offset */ column: number;
|
|
86
132
|
}
|
|
87
|
-
export interface
|
|
88
|
-
message
|
|
89
|
-
line: number;
|
|
90
|
-
column: number;
|
|
91
|
-
width: number;
|
|
133
|
+
export interface TransformNote {
|
|
134
|
+
/** What this span is communicating */ message?: string | null;
|
|
135
|
+
/** One-based line */ line: number;
|
|
136
|
+
/** One-based column, byte offset */ column: number;
|
|
137
|
+
/** Byte length */ width: number;
|
|
92
138
|
}
|
|
93
|
-
export declare function transform(options: TransformOptions): Transformed;
|
|
94
139
|
//# sourceMappingURL=mod.d.ts.map
|
package/_dist/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":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