Elder.js Plugin: Markdown
An extensible markdown parser for Elder.js powered by remark.
Use it to create a blog, or site, just configure and it'll parse your markdown and make it available in your Svelte templates.
Install
npm install --save @elderjs/plugin-markdown
Config
Once installed, open your elder.config.js
and configure the plugin by adding @elderjs/plugin-markdown
to your plugin object.
plugins: {
'@elderjs/plugin-markdown': {
routes: [],
}
}
Customizing the Defaults
Below are the default settings of the plugin. You can adjust them to your needs.
plugins: {
'@elderjs/plugin-markdown': {
routes: [],
remarkPlugins: [
frontmatter,
[extractFrontmatter, { name: 'frontmatter', yaml: yaml }],
remarkHtml,
],
useElderJsPluginImages: true,
},
}
Getting all Markdown For a Route:
An object representing all of the markdown the plugin parsed from the defined routes
is available at data.markdown
.
If you are looking to get an array of the markdown for a specific route such as blog
you can access it data.markdown.blog
.
helpers.markdownParser
:
In addition to parsing the markdown in the given routes, this plugin makes available the configured remark parser at helpers.markdownParser
during the bootstrap
hook.
This means you can use the same markdown parser to parse markdown from other sources if needed.
For full documentation please review remark's docs. That said, the default plugin config can be used to parse markdown like so: helpers.markdownParser.processSync(mdText)
If you need to customize the remark plugins that are used here are some notes:
- The
remarkPlugins
array are added to remark
in the order they are given. - If you add a single plugin in your
elder.config.js
, you must specify a full remark
pipeline. - If a plugin such as
remark-extract-frontmatter
needs an array of options, you can pass in an array like so: remarkPlugins: [[extractFrontmatter, { name: 'frontmatter', yaml: yaml }]]
Notes:
- By default, if there is a
date
field in your frontmatter it will sort all of the markdown for that route by it. - If there is a
slug
field in your frontmatter it will use that for the slug, if not it falls back to the filename.