textlint-util-to-string
Convert Paragraph
Node to plain text with SourceMap.
This library is for textlint and textstat.
Installation
npm install textlint-util-to-string
Usage
import assert from "power-assert"
import {parse} from "markdown-to-ast";
import StringSource from "textlint-util-to-string";
let originalText = "This is [Example!?](http://example.com/)";
let AST = parse(originalText);
let source = new StringSource(AST);
let result = source.toString();
assert.equal(result, "This is Example!?");
let index1 = result.indexOf("Example");
assert.equal(index1, 8);
assert.equal(source.originalPositionFor(index1), 9);
let index2 = result.indexOf("!?");
assert.equal(index2, 15);
assert.equal(source.originalPositionFor(index2), 16);
Tests
npm test
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT