Skip to content

hedgedoc/meta-marked

 
 

Repository files navigation

meta-marked

The marked markdown processor for Node.js with support for YAML metadata

David

CodiMD fork of the outdated meta-marked package. Due to lack of upstream activity forking the project and maintaining it on ourselves seems to be the way to go. Due to CI integration with tests and Greenkeeper the maintenance workload should be minimal to us. Issues, suggestions and improvements are very welcome!

Main goal: Keep things up-to-date and safe without breaking functionality.

Not goal: Extending functionality.


Just a quick extension I needed for processing markdown in Node. Props to Christopher Jeffrey for his excellent markdown processor 'marked'.

The meta-marked function behaves exactly the same as marked, except for the following:

  • Instead of returning a parsed string, meta-marked returns an object with the following properties:
    • meta contains the metadata object or null if metadata isn't found
    • html contains the parsed HTML
    • markdown contains the text of the markdown section of the string
  • metaMarked.noMeta is a reference to the marked function, so it can be used to avoid parsing metadata.

In order to include metadata in a document, insert YAML at the top of the document surrounded by --- and .... Note that if the given string doesn't start with ---, it will not be interpreted as having metadata.

Example

---
Title:   My awesome markdown file
Author:  Me
Scripts:
    - js/doStuff.js
    - js/doMoreStuff.js
...

##Header
Regular text and stuff goes here.

You can also use the approach below, which will result in a very nice data table at the top of your markdown when viewing the file GitHub:

---
Title:   My awesome markdown file
Author:  Me
Scripts:
    - js/doStuff.js
    - js/doMoreStuff.js
---

##Header
Regular text and stuff goes here.

Both of the above will result in the following output:

{
	"meta": {
		"Title": "My awesome markdown file",
		"Author": "Me",
		"Scripts": [
			"js/doStuff.js",
			"js/doMoreStuff.js"
		]
	},
	"html": "<h2>Header</h2>\n<p>Regular text and stuff goes here.</p>\n",
	"markdown": "\n\n##Header\nRegular text and stuff goes here."
}

###Testing

npm test

Licensed under the MIT License. © 2013-2014 j201

About

The 'marked' markdown processor for Node.js with a simple metadata system added on.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%