pixiv-novel-parser
v0.3.0
Published
pixiv novel parser.
Downloads
42
Readme
pixiv-novel-parser
pixiv novel parser powered by PEG.js.
Getting Started
node.js
Once you installed node.js, install with:
$ npm install pixiv-novel-parser --save
And require it from your project:
var Parser = require('pixiv-novel-parser').Parser;
Parser.parse('[chapter: pixiv[[rb:小説 > しょうせつ]]]');
Web Browser
Download the ZIP Package, or use bower:
$ bower install pixiv-novel-parser --save
And include it from HTML:
<script src="dist/pixiv-novel-parser.min.js"></script>
<script>
var Parser = PixivNovelParser.Parser;
Parser.parse('[chapter:pixiv[[rb:小説>しょうせつ]]]');
</script>
Compatibility
- IE 7+
- Firefox 29+
- Google Chrome 42+
- Opera 21+
- node.js 0.10+
- io.js 3
- PECL V8js 0.1.3
API
JavaScript API
Currently pixiv-novel-parser exports object with only one legal property Parser
. This is JavaScript Class that can be used statically or dynamically.
Static Method
Parser.parse(text)
Parse text into AST (Abstract Syntax Tree).
- text: (
String
) the text to parse - Return: AST Object
console.log(Parser.parse('[chapter:見出し]本文[newpage]'));
Result:
[ { type: 'tag', name: 'chapter', title: [ [Object] ] },
{ type: 'text', val: '本文' },
{ type: 'tag', name: 'newpage' } ]
Dynamic Method / Property
parser.parse(text)
Parse text into AST (Abstract Syntax Tree) and store the result.
- text: (
String
) the text to parse - Return: AST Object
var parser = new Parser();
parser.parse('[chapter:見出し]本文[newpage]');
console.log(parser.tree);
parser.tree
Parsed AST Object
parser.toJSON()
Serialize parsed AST into JSON.
- Return: JSON string that represents AST
AST
No docs here but approximately it's just an array of tokens. See test/test.js.
Contribute
See CONTRIBUTING
Copyright
Mozilla Public License, version 2.0
Copyright 2015 pixiv Inc., All Right Reserved.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
pixiv-novel-editor
pixiv-novel-editor/src/app/index.js
is licensed under GPLv3.
/** * @license GPLv3 ne_Sachirou <[email protected]> */