Giter Club home page Giter Club logo

pimd's Introduction

PIMD

Build status (Travis CI) Dependency status (Greenkeeper) JavaScript Style Guide

Processing Instructions for MarkDown.

PIMD will be the base for the JavaScript version of LivingStyleGuide – an API to extend Markdown by DOM manipulations as known from the browsers.

Main targets

  • Easy to use in JavaScript projects – in build tools and within the browser
  • Focus on extendibility: The DOM tree known from the browser will be the main API
  • Compliance with the CommonMark specs – Markdown files will render perfectly on GitHub; all additional commands will be CommanMark compliant and won’t leave ugly artifacts when used in README.md files on GitHub

RailsGirls Summer of Code

This project is as part of LivingStyleGuide chosen for the RailsGirls Summer of Code 2018: Our team is @artnerdnet and @dianavile


Setup

npm install --save pimd

Usage

Render inline

const { Document } = require("pimd")
const markdown = "# Headline"
const doc = new Document(markdown)
console.log(doc.render())

Result:

<h1>Headline</h1>

Render document

const { Document } = require("pimd")
const markdown = "# Headline"
const doc = new Document(markdown)
doc.renderDocument().then(html => {
  console.log(html)
})

Result:

<html>
  <head>
    <title>Headline</title>
  </head>
  <body>
    <h1>Headline</h1>
  </body>
</html>

Plugins

Plugins unleash the full power of PIMD. The official plugins offer functionality to create living style guides and to improve code documentation in general.

  • Classes: Add classes to code blocks or other elements for easy additional styling
  • ID: Add an ID to code blocks or other elements for easily accessing elements in the HTML preview via JavaScript to bring code examples to live
  • Preview: Add an HTML preview to code blocks for pattern libraries/living style guides
  • Highlight: Visually highlight important parts of code blocks in different background colors
  • Showmore: Hide less important parts of code blocks
  • HTML injector: a plugin to create new plugins that manipulate the code blocks (already used by Highlight and Showmore)

Extending

Output generated data with JavaScript

PIMD extends Markdown with Processing Instructions known from XML. This is complient with the CommonMark specs.

const { Document } = require("pimd")
const Config = require("pimd/lib/config")
const markdown = "# Year <?year?>"

const config = new Config()
config.commands["year"] = () => new Date().getFullYear()

const doc = new Document(markdown, config)
console.log(doc.render())

Result:

<h1>Year 2018</h1>

Accessing the DOM

PIMD uses the DOM internally to provide a well-known API to its users.

const { Document } = require("pimd")
const Config = require("pimd/lib/config")
const markdown = "# Headline <?important?>"

const config = new Config()
config.commands["date"] = context => {
  context.element.style.background = "yellow"
}

const doc = new Document(markdown, config)
console.log(doc.render())

Result:

<h1 style="background: yellow">Headline</h1>

Writing plugins

const { Document } = require("pimd")
const Config = require("pimd/lib/config")

const markdown = `
~~~ html info="Hello world!"
<p>Test</p>
~~~
`

const myPlugin = function(config) {
  config.addInfoStringParser(/info="(.+?)"/, function(match, string) {
    const element = this.renderer.dom.window.document.createElement("div")
    element.textContent = string
    this.element.appendChild(element)
  })
}

const config = new Config()
config.use(myPlugin)

const doc = new Document(markdown, config)
console.log(doc.render())

Result:

<div class="pimd-example">
  <div class="pimd-code">
    <pre>
      <code class="lang-html">
        &lt;p&gt;Test&lt;/p&gt;
      </code>
    </pre>
  </div>
  <div>Hello world!</div>
</div>

Tip: Check out the source code of PIMD’s official plugins for further inspiration.


Coding style

PIMD uses the Prettier style for all supported documents. To save the environment, semicolons are not required.


Copyright

Copyright 2018++ Nico Hagenburger. See MIT-LICENSE for details. Get in touch with @hagenburger on Twitter or open an issue.

pimd's People

Contributors

hagenburger avatar greenkeeper[bot] avatar benevbright avatar violetadev avatar

Watchers

James Cloos avatar Alexis Duarte 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.