You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-9Lines changed: 20 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ A Metalsmith plugin to render markdown files to HTML, using [Marked](https://git
11
11
## Features
12
12
13
13
- Compiles `.md` and `.markdown` files in `metalsmith.source()` to HTML.
14
-
- Enables rendering file metadata keys to HTML through the [keys option](#rendering-file-metadata)
14
+
- Enables rendering file or metalsmith metadata keys to HTML through the [keys option](#rendering-metadata)
15
15
- Define a dictionary of markdown globalRefs (for links, images) available to all render targets
16
16
- Supports using the markdown library of your choice through the [render option](#using-another-markdown-library)
17
17
@@ -75,17 +75,28 @@ metalsmith.use(
75
75
-`render` - Specify a custom render function with the signature `(source, engineOptions, context) => string`. `context` is an object with the signature `{ path:string, key:string }` where the `path` key contains the current file path, and `key` contains the target metadata key.
76
76
-`engineOptions` Options to pass to the markdown engine (default [marked](https://github.com/markedjs/marked))
77
77
78
-
### Rendering file metadata
78
+
### Rendering metadata
79
79
80
-
You can render markdown to HTML in file metadata keys by specifying the `keys` option.
81
-
The `keys` option also supports dot-delimited key-paths.
80
+
You can render markdown to HTML in file or metalsmith metadata keys by specifying the `keys` option.
81
+
The `keys` option also supports dot-delimited key-paths. You can also use [globalRefs within them](#defining-a-dictionary-of-markdown-globalrefs)
82
82
83
83
```js
84
-
metalsmith.use(
85
-
markdown({
86
-
keys: ['html_desc', 'nested.data']
84
+
metalsmith
85
+
.metadata({
86
+
from_metalsmith_metadata:'I _shall_ become **markdown** and can even use a [globalref][globalref_link]',
87
+
markdownRefs: {
88
+
globalref_link:'https://johndoe.com'
89
+
}
87
90
})
88
-
)
91
+
.use(
92
+
markdown({
93
+
keys: {
94
+
files: ['html_desc', 'nested.data'],
95
+
global: ['from_metalsmith_metadata']
96
+
},
97
+
globalRefs:'markdownRefs'
98
+
})
99
+
)
89
100
```
90
101
91
102
You can even render all keys at a certain path by setting the `wildcard` option and using a globstar `*` in the keypaths.
@@ -170,7 +181,7 @@ metalsith
170
181
// eg in a markdown file: [My Twitter profile][twitter]
171
182
.use(markdown({ globalRefs:'global.links' }))
172
183
// eg in a handlebars layout: {{ global.links.twitter }}
* - Key names of file metadata to render to HTML - can be nested
13
+
* - Array of file metadata key names or object with arrays of key names of file or global metadata key names to render to HTML - can be nested keypaths
Copy file name to clipboardExpand all lines: src/index.js
+31-16Lines changed: 31 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ function refsObjectToMarkdown(refsObject) {
23
23
24
24
/**
25
25
* @typedef Options
26
-
* @property {string[]} [keys] - Key names of file metadata to render to HTML - can be nested
26
+
* @property {string[]|{files: string[], global: string[]}} [keys] - Key names of file metadata to render to HTML - can be nested
27
27
* @property {boolean} [wildcard=false] - Expand `*` wildcards in keypaths
28
28
* @property {string|Object<string, string>} [globalRefs] An object of `{ refname: 'link' }` pairs that will be made available for all markdown files and keys,
29
29
* or a `metalsmith.metadata()` keypath containing such object
@@ -33,7 +33,7 @@ function refsObjectToMarkdown(refsObject) {
33
33
**/
34
34
35
35
constdefaultOptions={
36
-
keys: [],
36
+
keys: {},
37
37
wildcard: false,
38
38
render: defaultRender,
39
39
engineOptions: {},
@@ -52,10 +52,31 @@ function markdown(options = defaultOptions) {
0 commit comments