diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-06-07 12:31:21 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-06-07 12:31:21 +0200 |
commit | ca70c934d6a92f12e0f826cd3f6f32d562f66b2f (patch) | |
tree | d28e83efdca7983d128a59b603aee47314243c1b /lib/parse/parsePageFromString.js | |
parent | 1cc48fa314782312883af00cf64a56929b62f057 (diff) | |
download | gitbook-ca70c934d6a92f12e0f826cd3f6f32d562f66b2f.zip gitbook-ca70c934d6a92f12e0f826cd3f6f32d562f66b2f.tar.gz gitbook-ca70c934d6a92f12e0f826cd3f6f32d562f66b2f.tar.bz2 |
Split page parsing into parsePageFromString and parsePage
Add tests for parsePageFromString
Diffstat (limited to 'lib/parse/parsePageFromString.js')
-rw-r--r-- | lib/parse/parsePageFromString.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/parse/parsePageFromString.js b/lib/parse/parsePageFromString.js new file mode 100644 index 0000000..80c147b --- /dev/null +++ b/lib/parse/parsePageFromString.js @@ -0,0 +1,22 @@ +var Immutable = require('immutable'); +var fm = require('front-matter'); +var direction = require('direction'); + +/** + * Parse a page, its content and the YAMl header + * + * @param {Page} page + * @return {Page} + */ +function parsePageFromString(page, content) { + var parsed = fm(content); + + return page.merge({ + content: parsed.body, + attributes: Immutable.fromJS(parsed.attributes), + dir: direction(parsed.body) + }); +} + + +module.exports = parsePageFromString; |