1.1.1 • Published 7 years ago

noddity-template-parser v1.1.1

Weekly downloads
8
License
WTFPL
Repository
github
Last release
7 years ago

Build Status

Turns Noddity post objects into basic abstract syntax trees.

Example

var parser = require('noddity-template-parser')
var Linkify = require('linkify')

var linkify = Linkify('#/prefix')

var ast = parser(post, linkify)

var full = ast.reduce(function (full, piece) {
	if (piece.type === 'string') full += piece.value
	if (piece.type === 'template') full += 'TEMPLATE GOES HERE'
	return full
}, '')

API

var parser = require('noddity-template-parser')

var ast = parser(post, linkify, [options])

  • post: a Noddity post object (from a Noddity Butler)
  • linkify: a Noddity Linkifier
  • options: an optional object of options - convertToHtml: convert posts from markdown to HTML. Defaults to true. (If markdown: false is on the post's metadata, it will not be converted, even when this is set to true.)
var ast = parser(post, linkify, { convertToHtml: false })

ast

An array of objects returned from parser(). Each object has a type property which can be string, or template.

  • string type properties: - value string with html or markdown
  • template type properties: - filename string, e.g. 'my-post.md' - arguments object, e.g. { 1: 'hello', key: 'value' }

The AST for this post...

---
prop: val
---

::child|arg|key=value::

I see you like {{prop}} templates

...would look like:

[{
	type: 'string',
	value: '<p>'
}, {
	type: 'template',
	filename: 'child',
	arguments: {
		1: 'arg',
		key: 'value'
	}
}, {
	type: 'string',
	value: '</p>\n<p>I see you like {{prop}} templates</p>\n'
}]

License

WTFPL

1.1.1

7 years ago

1.1.0

8 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago