GithubHelp home page GithubHelp logo

orsobruno96 / remark-containers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nevenall/remark-containers

0.0 0.0 0.0 40 KB

add custom containers to markdown

License: MIT License

JavaScript 100.00%

remark-containers's Introduction

remark-containers

This remark plugin provides parsing for ::: delimited containers to wrap markdown blocks in arbitrary html.

Default Syntax

The first word after the ::: is the HTML element name. The rest of line is optional but, if present, will become the element's class attribute.

::: aside class-one class-two
# Header One

With container contents. 
::: 

results in:

<aside class="class-one class-two">
  <h1>Header One</h1>
  <p>With container contents.</p>
</aside>

Installation

npm install remark-containers

Usage

const unified = require('unified')
const parse = require('remark-parse')
const containers = require('remark-containers')
const stringify = require('rehype-stringify')
const remark2rehype = require('remark-rehype')

unified()
  .use(parse)
  .use(containers)
  .use(remark2rehype)
  .use(stringify)

Options

Using the options for this plugin allows for control over the resulting mdast.

.use(containers, {
  default: true, 
  custom: [{
    type: 'callout',
    element: 'article',
    transform: function(node, config, tokenize) {
      node.data.hProperties = {
          className: config || 'left'
      }
    }
    }, {
        type: 'quote',
        element: 'aside',
        transform: function(node, config, tokenize) {
          var words = tokenizeWords.parse(config)

          node.data.hProperties = {
              className: `quoted ${words.shift()}`
          }
          node.children.push({
              type: 'footer',
              data: {
                hName: 'footer'
              },
              children: tokenize(words.join(' '))
          })
        }
    }
  ]
})

default

When true the default syntax will be enabled.

custom

An array of custom container configurations.

type

A single word string identifying the type of this container. Any markdown of the form ::: {type} will match this container.

element

The html element name to use for the container. Default 'div'.

transform(node, config, tokenize)

A function to manipulate the mdast node.

node

The mdast node for this container.

config

The markdown string from after ::: type until the end of the line.

tokenize

A function(value): mdastNode you can use to tokenize an inline markdown string, if needed.

Feedback

Bugs & feedback.

License

MIT © Dan Behlings

remark-containers's People

Contributors

nevenall avatar orsobruno96 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.