Giter Site home page Giter Site logo

md's Introduction

md

NPM version NPM downloads Build Status codecov donate

This is a fork of marked

Why?

  • Actively maintained
  • Rewrote in ES6 and bundled with Rollup for smaller size (15KB)
  • Support more GFM extras like task lists

Install

yarn add md

You can find a CDN version at https://unpkg.com/md/

Usage

const md = require('md')

const html = md(`## hello world

A modern **markdown** parser!

- [ ] todo
- [x] done
`)

You can preview the HTML result here: https://egoist.moe/md2html/ (source)

API

md(src, [options])

src

Type: string
Required: true

Input markdown string.

options

All marked options plus:

taskLists

Type: boolean
Default: true

Enable GFM task lists, this will only work if options.gfm is true.

linksInNewTab

Type: boolean | (href: string) => boolean
Default: undefined

Open links in a new window/tab.

dataLine

Type: boolean
Default: true

Add data-line attribute to <pre> tag for code fences, it's useful with the line-highlight plugin in PrismJS.

```js{1}
console.log('hi')
```

This will yield:

<pre data-line="1"><code class="lang-js">console.log('hi')</code></pre>

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Development

# lint and unit test
yarn test

# lint only
yarn lint

# fix lint issues
yarn lint -- --fix

Author

md © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

egoist.moe · GitHub @egoist · Twitter @_egoistlily

md's People

Contributors

egoist avatar jozanza avatar steambap avatar styfle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

md's Issues

Plugin API

Take an emoji plugin as example:

module.exports = function (md) {
  md.renderer.emoji = theFunctionToRenderEmojiToHtml
  md.inlineLexer.rules.add('emoji', replaceEmoji)
}
const md = require('md')
const emoji = require('md-emoji')

md.use(emoji)

Keeping anchors with ID hrefs in the same tab

While the linksInNewTab option is awesome, I'd like it to only affect non-id hrefs. Opening a new tab with the same page but in a different scroll position doesn't make for a great experience imho. I created a PR to fix this by checking the leading character of a link's href attribute. Please let me know if this is something you are into @egoist or if there are changes you'd like me to make 👍

cannot run tests on windows

yarn test v0.27.5
$ npm run lint && BABEL_ENV=test ava

> [email protected] lint E:\Documents\marked3
> xo src/*.js

'BABEL_ENV' is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 1.

Support custom elements

This would be similar to what MDX does but for custom elements, and it's pretty simple.
The idea would be to modify only the Lexer class, and reuse the Parser and Rendere for html. I've already made it for a personal component, but I had to copy and paste the whole lex function.
Api would be something like

const md = require('md')

const html = md(`## hello world

<custom-button>Fancy button!</custom-button>

- [ ] todo
- [x] done
`, { customElements: ['custom-button'] })

If you agree I could send a PR

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.