1.4.0 • Published 2 years ago

markado v1.4.0

Weekly downloads
-
License
bsd-2-clause
Repository
github
Last release
2 years ago

Markado

Fast HTML to Markdown transformer with support for frontmatter which runs in the browser.

Installation

npm

npm install markado

Yarn

yarn install markado

Usage

ES Modules / ES6

import {html2markdown} from 'markado'

const html = '<h1>Hello World!</h1>'
const md = html2markdown(html)
process.stdout.write(md)

UMD

var {html2markdown} = require('markado')

var html = '<h1>Hello World!</h1>'
var md = html2markdown(html)
process.stdout.write(md)

Options

Options can be passed as a second parameter:

const md = html2markdown(html, {removeElements:['head']})
OptionDescriptionValuesDefault
removeElementstag including children and conten is ignoredany tag, e.g. head, section'script','style','head'
frontmatter optionalscrape values from tags and attributes and create a yaml frontmatter{} deactivated

frontmatter

const md = html2markdown(html, {frontmatter: {
    props: [source, title, description,lang],
    bookmarks: false,
    defaults: {
        source: 'https://www.website.test'
    }
}})

given the following website code:

<html lang="en">
  <head>
    <title>Title | Website</title>
    <meta property="og:title" content="Title OG" />
    <meta name="twitter:title" content="Title Twitter" />
    <link rel="canonical" href="https://www.canonical.test" />
    <meta name="description" content="Description" />
  </head>
</html>

will result in

---
source: https://www.canonical.test
title: Title OG
description: Description
lang: en
---

frontmatter:

OptionDescriptionValuesDefault
propsthe attributes used to create the frontmatter yamlstring[] - list of names[]
defaults optionaldefault values for props. If not listed in props, the value is still used!{}
bookmarkscreate markdown content after frontmatter with Headline, tags and descriptiontrue / falsefalse

built in predefined parses for props

propertyparsed tags priority
langhtml:lang
titlemeta:og:title, meta:twitter:title, title
descriptionmeta:og:description, meta:twitter:description, meta:description
sourcelink:rel:canonical
<any_name><meta name="<any_name>" content="<result>" />

Roadmap

  • better support for nested markup - e.g. blockquote
  • api to extend render function
  • api to extend frontmatter parser
  • option to detect main content and strip unrelevant content blocks

Contribution

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Built With

License

Distributed under the "bsd-2-clause" License. See LICENSE.txt for more information.

1.2.0

2 years ago

1.1.1

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.1.0

3 years ago

1.0.1-alpha.0

3 years ago

1.0.3-alpha.0

3 years ago

1.0.2-alpha.0

3 years ago

1.0.0-alpha.0

3 years ago

0.1.0

3 years ago

0.0.2-alpha.0

3 years ago

0.0.1-alpha.0

3 years ago