All Projects → metalsmith → markdown

metalsmith / markdown

Licence: MIT license
A metalsmith plugin to render markdown files to HTML.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to markdown

permalinks
A Metalsmith plugin for permalinks.
Stars: ✭ 61 (+5.17%)
Mutual labels:  metalsmith, metalsmith-plugin
headings
A Metalsmith plugin that extracts headings from HTML files and attaches them to the file's metadata.
Stars: ✭ 22 (-62.07%)
Mutual labels:  metalsmith, metalsmith-plugin
remove
A Metalsmith plugin to remove files from the build
Stars: ✭ 19 (-67.24%)
Mutual labels:  metalsmith, metalsmith-plugin
metalsmith-redirect
🚏 Metalsmith plugin to create HTTP redirections
Stars: ✭ 27 (-53.45%)
Mutual labels:  metalsmith-plugin
streetsupport-web
Helping people facing homelessness across the UK to find services in their area, and connecting people who want to help to where it is needed most.
Stars: ✭ 21 (-63.79%)
Mutual labels:  metalsmith
Gray Matter
Contributing Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Stars: ✭ 2,105 (+3529.31%)
Mutual labels:  metalsmith
directus-metalsmith-snipcart
Lookbook web app with Directus' open source headless CMS, Metalsmith, Vue.js & Snipcart
Stars: ✭ 14 (-75.86%)
Mutual labels:  metalsmith
metalsmith-clean-css
🚿 Metalsmith plugin to minify CSS files
Stars: ✭ 19 (-67.24%)
Mutual labels:  metalsmith-plugin
metalsmith-imagemin
Metalsmith plugin to minify images
Stars: ✭ 17 (-70.69%)
Mutual labels:  metalsmith
metalsmith-babel
A Metalsmith plugin to compile JavaScript with Babel
Stars: ✭ 19 (-67.24%)
Mutual labels:  metalsmith
metalsmith
An extremely simple, pluggable static site generator.
Stars: ✭ 7,721 (+13212.07%)
Mutual labels:  metalsmith
metalsmith-tags
A metalsmith plugin to create dedicated pages for tags in posts or pages.
Stars: ✭ 48 (-17.24%)
Mutual labels:  metalsmith-plugin
metalsmith-code-highlight
Metalsmith plugin for syntax highlighting code with HTML
Stars: ✭ 14 (-75.86%)
Mutual labels:  metalsmith
Staticman
💪 User-generated content for Git-powered websites
Stars: ✭ 2,098 (+3517.24%)
Mutual labels:  metalsmith
metalsmith-jquery
A Metalsmith plugin to manipulate HTML via jQuery syntax
Stars: ✭ 13 (-77.59%)
Mutual labels:  metalsmith
metalsmith-request
Metalsmith plugin to grab content from the web and expose the results to metadata
Stars: ✭ 12 (-79.31%)
Mutual labels:  metalsmith
metalsmith-concat
📎 Metalsmith plugin to concatenate files
Stars: ✭ 16 (-72.41%)
Mutual labels:  metalsmith-plugin
Metalsmith
An extremely simple, pluggable static site generator.
Stars: ✭ 7,692 (+13162.07%)
Mutual labels:  metalsmith
metalsmith-convert
Convert images with imagemagick (via imagemagick-native).
Stars: ✭ 17 (-70.69%)
Mutual labels:  metalsmith
metalsmith-paths
Metalsmith plugin that adds file path values to metadata
Stars: ✭ 19 (-67.24%)
Mutual labels:  metalsmith

@metalsmith/markdown

A Metalsmith plugin to render markdown files to HTML, using Marked.

metalsmith: core plugin npm: version ci: build code coverage license: MIT

Installation

NPM:

npm install @metalsmith/markdown

Yarn:

yarn add @metalsmith/markdown

Usage

const markdown = require('@metalsmith/markdown')

metalsmith.use(
  markdown({
    highlight: function (code) {
      return require('highlight.js').highlightAuto(code).value
    },
    pedantic: false,
    gfm: true,
    tables: true,
    breaks: false,
    sanitize: false,
    smartLists: true,
    smartypants: false,
    xhtml: false
  })
)

Options

@metalsmith/markdown is powered by Marked, and you can pass any of the Marked options to it, including the 'pro' options: renderer, tokenizer, walkTokens and extensions.

You can render markdown to HTML in file metadata keys by specifying the keys option.
The keys option also supports dot-delimited key-paths.

metalsmith.use(
  markdown({
    keys: ['html_desc', 'nested.data']
  })
)

You can even render all keys at a certain path by setting the wildcard option and using a globstar * in the keypaths.
This is especially useful for arrays like the faq below:

metalsmith.use(
  markdown({
    wildcard: true,
    keys: ['html_desc', 'nested.data', 'faq.*.*']
  })
)

A file page.md with front-matter:

---
html_desc: A **markdown-enabled** _description_
nested:
  data: '#metalsmith'
faq:
  - q: '**Question1?**'
    a: _answer1_
  - q: '**Question2?**'
    a: _answer2_
---

would be transformed into:

{
  "html_desc": "A <strong>markdown-enabled</strong> <em>description</em>\n",
  "nested": {
    "data": "<h1 id=\"metalsmith\">metalsmith</h1>\n"
  },
  "faq": [
    { "q": "<p><strong>Question1?</strong></p>\n", "a": "<p><em>answer1</em></p>\n"},
    { "q": "<p><strong>Question2?</strong></p>\n", "a": "<p><em>answer2</em></p>\n"}
  ],

Notes about the wildcard

  • It acts like the single bash globstar. If you specify * this would only match the properties at the first level of the metadata.
  • If a wildcard keypath matches a key whose value is not a string, it will be ignored.
  • It is set to false by default because it can incur some overhead if it is applied too broadly.

Custom markdown rendering

You can use a custom renderer by using marked.Renderer()

const markdown = require('@metalsmith/markdown')
const marked = require('marked')
const markdownRenderer = new marked.Renderer()

markdownRenderer.image = function (href, title, text) {
  return `
  <figure>
    <img src="${href}" alt="${title}" title="${title}" />
    <figcaption>
      <p>${text}</p>
    </figcaption>
  </figure>`
}

metalsmith.use(
  markdown({
    renderer: markdownRenderer,
    pedantic: false,
    gfm: true,
    tables: true,
    breaks: false,
    sanitize: false,
    smartLists: true,
    smartypants: false,
    xhtml: false
  })
)

CLI Usage

Add @metalsmith/markdown key to your metalsmith.json plugins key

{
  "plugins": {
    "@metalsmith/markdown": {
      "pedantic": false,
      "gfm": true,
      "tables": true,
      "breaks": false,
      "sanitize": false,
      "smartLists": true,
      "smartypants": false,
      "xhtml": false
    }
  }
}

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].