fix
This commit is contained in:
2
book/node_modules/front-matter/.npmignore
generated
vendored
Normal file
2
book/node_modules/front-matter/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
coverage
|
||||
20
book/node_modules/front-matter/.travis.yml
generated
vendored
Normal file
20
book/node_modules/front-matter/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- stable
|
||||
- 4
|
||||
before_install:
|
||||
- npm install -g npm
|
||||
env:
|
||||
global:
|
||||
- secure: he3kGOmSy6s97OdYRUq+k13w2WfIxzKfuDVysMfjOEV1U7YCq6tVeA6rm37yuyyaN3776he/fvPcK1Jd+FNfm8hzJMEu6QHqSd+Ri+q/32P+aXcEq2MEPMdsDAUpFqjT2p7BDPqH4a8DcJ0p48iXP+H2K3+HBaXNrneNLnU+6I8=
|
||||
- secure: HHxNmsHXJ3p9MBDXHmlSUYWaNX4KEq+VVpK4tlK1g67mGwPdlG9eFB4QFPTitYhqSTexCWSc9QwvPWVTWXzWemvwu6wBATxvKED8CKjTIlO2mOpwigV5KT7op7LU3f8WXvU+n5wV0ftHKU1nuDUu0ZgZEU4V9cAy9hMxNRmwpk8=
|
||||
- secure: jvL8J6LnjpPwrrGqHu3bUAxdZByq9pMITkhRrxCbYMFcQQRFynqEdbY/c1dldei03HKx4sA76UtlbGPe78wWepSE2zBPuq8XpyRR2oCgmJsYfdNuv6op6Pmx20TJwBCXp1nlAOS+Fm3JLv72N3LZS63YhB1aRi+XEmhm7SbQ3gk=
|
||||
matrix:
|
||||
- TEST=node
|
||||
- TEST=browser
|
||||
script: make travis
|
||||
matrix:
|
||||
exclude:
|
||||
- node_js: 4
|
||||
env: TEST=browser
|
||||
18
book/node_modules/front-matter/.zuul.yml
generated
vendored
Normal file
18
book/node_modules/front-matter/.zuul.yml
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
ui: tape
|
||||
browserify:
|
||||
- transform: brfs
|
||||
browsers:
|
||||
- name: chrome
|
||||
version: latest
|
||||
- name: firefox
|
||||
version: latest
|
||||
- name: ie
|
||||
version: 9..latest
|
||||
- name: iphone
|
||||
version: latest
|
||||
- name: safari
|
||||
version: latest
|
||||
- name: android
|
||||
version: latest
|
||||
- name: microsoftedge
|
||||
version: latest
|
||||
9
book/node_modules/front-matter/LICENSE
generated
vendored
Normal file
9
book/node_modules/front-matter/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# The MIT License (MIT)
|
||||
|
||||
Copyright (c) Jason Campbell ("Author")
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
70
book/node_modules/front-matter/Makefile
generated
vendored
Normal file
70
book/node_modules/front-matter/Makefile
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
MAKEFLAGS += --warn-undefined-variables
|
||||
PATH := node_modules/.bin:$(PATH)
|
||||
SHELL := /bin/bash
|
||||
|
||||
.SHELLFLAGS := -eu -o pipefail -c
|
||||
.DEFAULT_GOAL := all
|
||||
.DELETE_ON_ERROR:
|
||||
.SUFFIXES:
|
||||
|
||||
TEST ?= node
|
||||
version ?= patch
|
||||
|
||||
node_modules: package.json
|
||||
@npm prune
|
||||
@npm install
|
||||
@touch node_modules
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@$(RM) -fr node_modules
|
||||
@$(RM) -fr npm-debug.log
|
||||
@$(RM) -fr coverage
|
||||
|
||||
.PHONY: fmt
|
||||
fmt: node_modules
|
||||
@standard-format -w
|
||||
|
||||
.PHONY: lint
|
||||
lint: node_modules
|
||||
@standard
|
||||
|
||||
.PHONY: test
|
||||
test: lint
|
||||
@if [ "$(TEST)" = "browser" ]; \
|
||||
then make test-browser; \
|
||||
else make test-node; \
|
||||
fi
|
||||
|
||||
.PHONY: test-node
|
||||
test-node: node_modules
|
||||
tape test/index.js
|
||||
|
||||
.PHONY: test-browser
|
||||
test-browser: node_modules
|
||||
ifeq ($(TRAVIS_PULL_REQUEST),true)
|
||||
zuul -- test/index.js
|
||||
endif
|
||||
|
||||
.PHONY: zuul
|
||||
zuul: node_modules
|
||||
zuul --local 8080 --ui tape -- test/index.js
|
||||
|
||||
.PHONY: release
|
||||
release: test
|
||||
npm version $(version)
|
||||
git push && git push --tags
|
||||
npm publish
|
||||
|
||||
.PHONY: coverage
|
||||
coverage: node_modules index.js test/index.js node_modules
|
||||
@istanbul cover --report html --print detail ./test/index.js
|
||||
@touch coverage
|
||||
|
||||
.PHONY: coveralls
|
||||
coveralls: node_modules coverage
|
||||
@istanbul report lcov
|
||||
(cat coverage/lcov.info | coveralls) || exit 0
|
||||
|
||||
.PHONY: travis
|
||||
travis: test coveralls
|
||||
151
book/node_modules/front-matter/README.md
generated
vendored
Normal file
151
book/node_modules/front-matter/README.md
generated
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
# front-matter
|
||||
[![build][build-img]][build-url]
|
||||
[![coverage][coverage-img]][coverage-url]
|
||||
[![npm][npm-img]][npm-url]
|
||||
[![github][github-img]][github-url]
|
||||
|
||||
[](https://saucelabs.com/u/front-matter)
|
||||
|
||||
> Extract meta data (front-matter) from documents.
|
||||
|
||||
This modules does not do any IO (file loading or reading), only extracting and
|
||||
parsing front matter from strings.
|
||||
|
||||
This concept that was originally introduced to me through the [jeykll][jeykll] blogging system and is pretty useful where you want to be able to easily add meta-data to content without the need for a database. YAML is extracted from the the top of a file between matching separators of "---" or "= yaml =". It will also extract YAML between a separator and "...".
|
||||
|
||||
<!-- This is part of a long running project I have been working on where I am splitting out internals of [haiku][haiku] into to separate, more useful and shareable modules. If your in need of a static site generator [check it out][haiku]. -->
|
||||
|
||||
# Install
|
||||
|
||||
With [npm][npm] do:
|
||||
|
||||
npm install front-matter
|
||||
|
||||
# Example
|
||||
|
||||
So you have a file `example.md`:
|
||||
|
||||
```yaml
|
||||
---
|
||||
title: Just hack'n
|
||||
description: Nothing to see here
|
||||
---
|
||||
|
||||
This is some text about some stuff that happened sometime ago
|
||||
```
|
||||
|
||||
**NOTE:** As of `front-matter@2.0.0` valid front matter is considered to have
|
||||
the starting separator on the first line.
|
||||
|
||||
Then you can do this:
|
||||
|
||||
```javascript
|
||||
var fs = require('fs')
|
||||
, fm = require('front-matter')
|
||||
|
||||
fs.readFile('./example.md', 'utf8', function(err, data){
|
||||
if (err) throw err
|
||||
|
||||
var content = fm(data)
|
||||
|
||||
console.log(content)
|
||||
})
|
||||
```
|
||||
|
||||
And end up with an object like this:
|
||||
|
||||
```javascript
|
||||
{
|
||||
attributes: {
|
||||
title: 'Just hack\'n',
|
||||
description: 'Nothing to see here'
|
||||
},
|
||||
body: '\nThis is some text about some stuff that happened sometime ago',
|
||||
frontmatter: 'title: Just hack\'n\ndescription: Nothing to see here'
|
||||
}
|
||||
```
|
||||
|
||||
# Methods
|
||||
|
||||
```javascript
|
||||
var fm = require('front-matter')
|
||||
```
|
||||
|
||||
## fm(string)
|
||||
|
||||
Return a `content` object with two properties:
|
||||
|
||||
* `content.attributes` contains the extracted yaml attributes in json form
|
||||
* `content.body` contains the string contents below the yaml separators
|
||||
* `content.frontmatter` contains the original yaml string contents
|
||||
|
||||
# fm.test(string)
|
||||
|
||||
Check if a string contains a front matter header of "---" or "= yaml =". Primarily used internally but is useful outside of the module.
|
||||
|
||||
Returns `true` or `false`
|
||||
|
||||
```javascript
|
||||
fm.test(string) #=> true || false
|
||||
```
|
||||
|
||||
# Contributing
|
||||
|
||||
front-matter is an OPEN Source Project so please help out by [reporting bugs](http://github.com/jxson/front-matter/issues) or [forking and opening pull](https://github.com/jxson/front-matter) requests when possible.
|
||||
|
||||
![standard][standard-img]
|
||||
|
||||
All code is linted/formatted using [standard][standard-url] style, any non-conforming code can be automatically formatted using the the fmt make task: `make fmt`.
|
||||
|
||||
## Maintainers
|
||||
|
||||
- [Adrian Gimenez](https://github.com/axdg)
|
||||
- [Jason Campbell](https://github.com/jxson) - [@jxson](https://twitter.com/jxson)
|
||||
|
||||
## Contributors
|
||||
|
||||
This module is awesome because of all the folks who submitted pull requests:
|
||||
|
||||
- [Jordan Santell](https://github.com/jsantell) - [@jsantell](https://twitter.com/jsantell)
|
||||
- [Jean-Philippe Monette](https://github.com/jpmonette) - [@jpmonette](https://twitter.com/jpmonette)
|
||||
- [Kai Davenport](https://github.com/binocarlos)
|
||||
- [Marc-André Arseneault](https://github.com/arsnl) - [@im_arsnl](https://twitter.com/im_arsnl)
|
||||
- [Bret Comnes](https://github.com/bcomnes) - http://bret.io
|
||||
- [Shinnosuke Watanabe](https://github.com/shinnn)
|
||||
- [Matt Dickens](https://github.com/mpd106)
|
||||
- [Rod Knowlton](https://github.com/codelahoma)
|
||||
- [Rich DeLauder](https://github.com/FMJaguar)
|
||||
- [Sean Lang](https://github.com/slang800) - http://slang.cx
|
||||
- [Benjamin Tan](https://github.com/d10) - https://d10.github.io/
|
||||
- [Kenneth Lim](https://github.com/kenlimmj) - https://kenlimmj.com
|
||||
- [Cameron Moy](https://github.com/camoy)
|
||||
- [Fernando Montoya](https://github.com/montogeek) - https://montogeek.com
|
||||
- [Martin Heidegger](https://github.com/martinheidegger)
|
||||
- [Leo Liang](https://github.com/aleung)
|
||||
- [Kasper Pedersen](https://github.com/kasperpedersen)
|
||||
|
||||
# LICENSE (MIT)
|
||||
|
||||
Copyright (c) Jason Campbell ("Author")
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
[yaml]: http://en.wikipedia.org/wiki/YAML
|
||||
[haiku]: http://haiku.io
|
||||
[npm]: http://npmjs.org
|
||||
[jeykll]: https://github.com/mojombo/jekyll
|
||||
[coverage-img]: https://img.shields.io/coveralls/jxson/front-matter.svg
|
||||
[coverage-url]: https://coveralls.io/r/jxson/front-matter?branch=master
|
||||
[build-img]: https://img.shields.io/travis/jxson/front-matter/master.svg
|
||||
[build-url]: http://travis-ci.org/jxson/front-matter
|
||||
[npm-img]: https://img.shields.io/npm/dm/front-matter.svg
|
||||
[npm-url]: https://npmjs.org/package/standard
|
||||
[github-img]: https://img.shields.io/github/stars/jxson/front-matter.svg?style=social&label=Star
|
||||
[github-url]: https://github.com/jxson/front-matter/
|
||||
[standard-img]: https://cdn.rawgit.com/feross/standard/master/badge.svg
|
||||
[standard-url]: http://npmjs.com/package/standard
|
||||
3
book/node_modules/front-matter/examples/bom.md
generated
vendored
Normal file
3
book/node_modules/front-matter/examples/bom.md
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
title: Relax guy, I'm not hiding any BOMs
|
||||
---
|
||||
22
book/node_modules/front-matter/examples/complex-yaml.md
generated
vendored
Normal file
22
book/node_modules/front-matter/examples/complex-yaml.md
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
|
||||
title: This is a title!
|
||||
|
||||
name: Derek Worthen
|
||||
age: young
|
||||
contact:
|
||||
email: email@domain.com
|
||||
address: some location
|
||||
pets:
|
||||
- cat
|
||||
- dog
|
||||
- bat
|
||||
match: !!js/regexp /pattern/gim
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
- item
|
||||
- item
|
||||
- item
|
||||
14
book/node_modules/front-matter/examples/dashes-seperator.md
generated
vendored
Normal file
14
book/node_modules/front-matter/examples/dashes-seperator.md
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
title: Three dashes marks the spot
|
||||
tags:
|
||||
- yaml
|
||||
- front-matter
|
||||
- dashes
|
||||
expaned-description: with some --- crazy stuff in it
|
||||
---
|
||||
|
||||
don't break
|
||||
|
||||
---
|
||||
|
||||
Also this shouldn't be a problem
|
||||
6
book/node_modules/front-matter/examples/dots-ending.md
generated
vendored
Normal file
6
book/node_modules/front-matter/examples/dots-ending.md
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
title: Example with dots document ending
|
||||
description: Just an example of using `...`
|
||||
...
|
||||
|
||||
It shouldn't break with ...
|
||||
8
book/node_modules/front-matter/examples/missing-body.md
generated
vendored
Normal file
8
book/node_modules/front-matter/examples/missing-body.md
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
title: Three dashes marks the spot
|
||||
tags:
|
||||
- yaml
|
||||
- front-matter
|
||||
- dashes
|
||||
expaned-description: with some --- crazy stuff in it
|
||||
---
|
||||
11
book/node_modules/front-matter/examples/no-front-matter.md
generated
vendored
Normal file
11
book/node_modules/front-matter/examples/no-front-matter.md
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Hello World
|
||||
|
||||
This is a markdown document.
|
||||
|
||||
---
|
||||
|
||||
Some text here that is definitely not front matter.
|
||||
|
||||
---
|
||||
|
||||
More text here.
|
||||
21
book/node_modules/front-matter/examples/wrapped-text.md
generated
vendored
Normal file
21
book/node_modules/front-matter/examples/wrapped-text.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
title: Complex yaml example
|
||||
description: You can use the front-matter module to convert this
|
||||
tags: [example, yaml, node]
|
||||
folded-text: |
|
||||
There once was a man from Darjeeling
|
||||
Who got on a bus bound for Ealing
|
||||
It said on the door
|
||||
"Please don't spit on the floor"
|
||||
So he carefully spat on the ceiling
|
||||
wrapped-text: >
|
||||
Wrapped text
|
||||
will be folded
|
||||
into a single
|
||||
paragraph
|
||||
|
||||
Blank lines denote
|
||||
paragraph breaks
|
||||
---
|
||||
|
||||
Some crazy stuff going on up there ^^
|
||||
6
book/node_modules/front-matter/examples/yaml-seperator.md
generated
vendored
Normal file
6
book/node_modules/front-matter/examples/yaml-seperator.md
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
= yaml =
|
||||
title: I couldn't think of a better name
|
||||
description: Just an example of using `= yaml =`
|
||||
= yaml =
|
||||
|
||||
Plays nice with markdown syntax highlighting
|
||||
13
book/node_modules/front-matter/index.d.ts
generated
vendored
Normal file
13
book/node_modules/front-matter/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
interface FrontMatterResult<T> {
|
||||
readonly attributes: T
|
||||
readonly body: string
|
||||
readonly frontmatter: string
|
||||
}
|
||||
|
||||
interface FM {
|
||||
<T>(file: string): FrontMatterResult<T>
|
||||
test(file: string): boolean
|
||||
}
|
||||
|
||||
declare const fm: FM
|
||||
export = fm
|
||||
50
book/node_modules/front-matter/index.js
generated
vendored
Normal file
50
book/node_modules/front-matter/index.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
var parser = require('js-yaml')
|
||||
var optionalByteOrderMark = '\\ufeff?'
|
||||
var pattern = '^(' +
|
||||
optionalByteOrderMark +
|
||||
'(= yaml =|---)' +
|
||||
'$([\\s\\S]*?)' +
|
||||
'^(?:\\2|\\.\\.\\.)' +
|
||||
'$' +
|
||||
(process.platform === 'win32' ? '\\r?' : '') +
|
||||
'(?:\\n)?)'
|
||||
// NOTE: If this pattern uses the 'g' flag the `regex` variable definition will
|
||||
// need to be moved down into the functions that use it.
|
||||
var regex = new RegExp(pattern, 'm')
|
||||
|
||||
module.exports = extractor
|
||||
module.exports.test = test
|
||||
|
||||
function extractor (string) {
|
||||
string = string || ''
|
||||
|
||||
var lines = string.split(/(\r?\n)/)
|
||||
if (lines[0] && /= yaml =|---/.test(lines[0])) {
|
||||
return parse(string)
|
||||
} else {
|
||||
return { attributes: {}, body: string }
|
||||
}
|
||||
}
|
||||
|
||||
function parse (string) {
|
||||
var match = regex.exec(string)
|
||||
|
||||
if (!match) {
|
||||
return {
|
||||
attributes: {},
|
||||
body: string
|
||||
}
|
||||
}
|
||||
|
||||
var yaml = match[match.length - 1].replace(/^\s+|\s+$/g, '')
|
||||
var attributes = parser.load(yaml) || {}
|
||||
var body = string.replace(match[0], '')
|
||||
|
||||
return { attributes: attributes, body: body, frontmatter: yaml }
|
||||
}
|
||||
|
||||
function test (string) {
|
||||
string = string || ''
|
||||
|
||||
return regex.test(string)
|
||||
}
|
||||
53
book/node_modules/front-matter/notes.md
generated
vendored
Normal file
53
book/node_modules/front-matter/notes.md
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
* [ ] benchmarks
|
||||
* [ ] browser tests
|
||||
* [ ] streaming support
|
||||
* [ ] custom parsers
|
||||
* [ ] rename attributes?
|
||||
* [ ] sauce labs browser badge
|
||||
* [ ] should the yaml parser be separate?
|
||||
* [ ] Add benchmark results to the README
|
||||
* [ ] Add a note about size to the README
|
||||
* [ ] Add standard
|
||||
|
||||
* [ ] Add notes for collaborators about publishing
|
||||
|
||||
Should we create an org for static site authors?
|
||||
|
||||
https://github.com/juliangruber/balanced-match/blob/master/index.js
|
||||
|
||||
* [ ] streaming support?
|
||||
* [ ] Since the name of this package is very generic, it would be nice to be able to specify a separators and parsers. For example, parse front-matter as CSON when a *** separator is used:
|
||||
|
||||
***
|
||||
title: 'Hello'
|
||||
greatDocumentaries: [
|
||||
'earthlings.com'
|
||||
'forksoverknives.com'
|
||||
'cowspiracy.com'
|
||||
]
|
||||
***
|
||||
|
||||
* [ ] Something like below will break front-matter. It thinks the content between the horizontal lines is metadata.
|
||||
|
||||
# hello world
|
||||
|
||||
this is a markdown document
|
||||
|
||||
---
|
||||
|
||||
some text here
|
||||
|
||||
---
|
||||
|
||||
foo
|
||||
This can be avoided by declaring an empty metadata, but maybe a proper fix is to only look for metadata in the beginning of the file.
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
etc
|
||||
|
||||
* [ ] browser tests
|
||||
|
||||
# Hello world!
|
||||
42
book/node_modules/front-matter/package.json
generated
vendored
Normal file
42
book/node_modules/front-matter/package.json
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"author": "Jason Campbell <jason@js.la> (http://twitter.com/jxson)",
|
||||
"name": "front-matter",
|
||||
"description": "Extract YAML front matter from a string",
|
||||
"keywords": [
|
||||
"yaml",
|
||||
"front matter",
|
||||
"meta data"
|
||||
],
|
||||
"license": "MIT",
|
||||
"version": "2.3.0",
|
||||
"homepage": "https://github.com/jxson/front-matter",
|
||||
"bugs": "https://github.com/jxson/front-matter/issues",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/jxson/front-matter.git"
|
||||
},
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"js-yaml": "^3.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"brfs": "^1.4.3",
|
||||
"coveralls": "^2.11.6",
|
||||
"istanbul": "^0.3.6",
|
||||
"standard": "^6.0.4",
|
||||
"standard-format": "^2.1.0",
|
||||
"tape": "^4.4.0",
|
||||
"zuul": "^3.10.1"
|
||||
},
|
||||
"contributors": [
|
||||
"Jason Campbell <jason@js.la> (http://twitter.com/jxson)",
|
||||
"Jordan Santell <jsantell@gmail.com> (https://github.com/jsantell)",
|
||||
"Kai Davenport <kaiyadavenport@gmail.com> (https://github.com/binocarlos)",
|
||||
"Jean-Philippe Monette <contact@jpmonette.net> (https://github.com/jpmonette)",
|
||||
"Marc-André Arseneault <marc-andre@arsnl.ca> (https://github.com/arsnl)",
|
||||
"Bret Comnes <bcomnes@gmail.com> (http://bret.io)"
|
||||
]
|
||||
}
|
||||
227
book/node_modules/front-matter/test/index.js
generated
vendored
Normal file
227
book/node_modules/front-matter/test/index.js
generated
vendored
Normal file
@@ -0,0 +1,227 @@
|
||||
var fm = require('../')
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
var test = require('tape')
|
||||
|
||||
test('var fm = require("front-matter")', function (t) {
|
||||
t.equal(typeof fm, 'function')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('fm(string) - parse yaml delinetead by `---`', function (t) {
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, '../examples/dashes-seperator.md'),
|
||||
'utf8',
|
||||
function (err, data) {
|
||||
t.error(err, 'read(...) should not error')
|
||||
|
||||
var content = fm(data)
|
||||
|
||||
t.ok(content.attributes, 'should have `attributes` key')
|
||||
t.equal(content.attributes.title, 'Three dashes marks the spot')
|
||||
t.equal(content.attributes.tags.length, 3)
|
||||
|
||||
t.ok(content.body, 'should have a `body` key')
|
||||
t.ok(content.body.match("don't break"), 'should match body')
|
||||
t.ok(content.body.match('---'), 'should match body')
|
||||
t.ok(content.body.match("Also this shouldn't be a problem"),
|
||||
'should match body')
|
||||
|
||||
t.ok(content.frontmatter, 'should have a `frontmatter` key')
|
||||
t.ok(content.frontmatter.match('title: Three dashes marks the spot'), 'should match frontmatter')
|
||||
t.ok(content.frontmatter.match('expaned-description: with some --- crazy stuff in it'), 'should match frontmatter')
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('fm(string) - parse yaml delinetead by `= yaml =`', function (t) {
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, '../examples/yaml-seperator.md'),
|
||||
'utf8',
|
||||
function (err, data) {
|
||||
t.error(err, 'read(...) should not error')
|
||||
|
||||
var content = fm(data)
|
||||
var meta = content.attributes
|
||||
var body = content.body
|
||||
|
||||
t.equal(meta.title, "I couldn't think of a better name")
|
||||
t.equal(meta.description, 'Just an example of using `= yaml =`')
|
||||
t.ok(body.match('Plays nice with markdown syntax highlighting'),
|
||||
'should match body')
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('fm(string) - parse yaml ended by `...`', function (t) {
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, '../examples/dots-ending.md'),
|
||||
'utf8',
|
||||
function (err, data) {
|
||||
t.error(err, 'read(...) should not error')
|
||||
|
||||
var content = fm(data)
|
||||
var meta = content.attributes
|
||||
var body = content.body
|
||||
|
||||
t.equal(meta.title, 'Example with dots document ending')
|
||||
t.equal(meta.description, 'Just an example of using `...`')
|
||||
t.ok(body.match("It shouldn't break with ..."),
|
||||
'should match body')
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('fm(string) - string missing front-matter', function (t) {
|
||||
var content = fm('No front matter here')
|
||||
|
||||
t.equal(content.body, 'No front matter here')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('fm(string) - string missing body', function (t) {
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, '../examples/missing-body.md'),
|
||||
'utf8',
|
||||
function (err, data) {
|
||||
t.error(err, 'read(...) should not error')
|
||||
|
||||
var content = fm(data)
|
||||
|
||||
t.equal(content.attributes.title, 'Three dashes marks the spot')
|
||||
t.equal(content.attributes.tags.length, 3)
|
||||
t.equal(content.body, '')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('fm(string) - wrapped test in yaml', function (t) {
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, '../examples/wrapped-text.md'),
|
||||
'utf8',
|
||||
function (err, data) {
|
||||
t.error(err, 'read(...) should not error')
|
||||
|
||||
var content = fm(data)
|
||||
var folded = [
|
||||
'There once was a man from Darjeeling',
|
||||
'Who got on a bus bound for Ealing',
|
||||
' It said on the door',
|
||||
' "Please don\'t spit on the floor"',
|
||||
'So he carefully spat on the ceiling\n'
|
||||
].join('\n')
|
||||
|
||||
t.equal(content.attributes['folded-text'], folded)
|
||||
t.ok(content.body.match('Some crazy stuff going on up there'),
|
||||
'should match body')
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('fm(string) - strings with byte order mark', function (t) {
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, '../examples/bom.md'),
|
||||
'utf8',
|
||||
function (err, data) {
|
||||
t.error(err, 'read(...) should not error')
|
||||
|
||||
var content = fm(data)
|
||||
|
||||
t.equal(content.attributes.title, "Relax guy, I'm not hiding any BOMs")
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('fm(string) - no front matter, markdown with hr', function (t) {
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, '../examples/no-front-matter.md'),
|
||||
'utf8',
|
||||
function (err, data) {
|
||||
t.error(err, 'read should not error')
|
||||
|
||||
var content = fm(data)
|
||||
t.equal(content.body, data)
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('fm(string) - complex yaml', function (t) {
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, '../examples/complex-yaml.md'),
|
||||
'utf8',
|
||||
function (err, data) {
|
||||
t.error(err, 'read(...) should not error')
|
||||
var content = fm(data)
|
||||
t.ok(content.attributes, 'should have `attributes` key')
|
||||
t.equal(content.attributes.title, 'This is a title!')
|
||||
t.equal(content.attributes.contact, null)
|
||||
t.equal(content.attributes.match.toString(), '/pattern/gim')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('fm.test(string) - yaml seperator', function (t) {
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, '../examples/yaml-seperator.md'),
|
||||
'utf8',
|
||||
function (err, data) {
|
||||
t.error(err, 'read(...) should not error')
|
||||
t.equal(fm.test(data), true)
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('fm.test(string) - dashes seperator', function (t) {
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, '../examples/dashes-seperator.md'),
|
||||
'utf8',
|
||||
function (err, data) {
|
||||
t.error(err, 'read(...) should not error')
|
||||
t.equal(fm.test(data), true)
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('fm.test(string) - no front-matter', function (t) {
|
||||
t.equal(fm.test('no front matter here'), false)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Supports live updating', function (t) {
|
||||
var seperator = '---'
|
||||
var string = ''
|
||||
for (var i = 0; i < seperator.length; i++) {
|
||||
string += seperator[i]
|
||||
|
||||
try {
|
||||
fm(string)
|
||||
} catch (e) {
|
||||
t.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
string += '\n'
|
||||
string += 'foo: bar'
|
||||
|
||||
var content = fm(string)
|
||||
|
||||
t.same(content, {
|
||||
attributes: {},
|
||||
body: string
|
||||
})
|
||||
|
||||
string += '\n---\n'
|
||||
content = fm(string)
|
||||
t.same(content, {
|
||||
attributes: { foo: 'bar' },
|
||||
body: '',
|
||||
frontmatter: 'foo: bar'
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
Reference in New Issue
Block a user