Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
textlint-util-to-string
Advanced tools
Convert Paragraph
Node to plain text with SourceMap.
SourceMap mean that could revert position
in plain text to position
in Node.
This library is for textlint and textstat.
npm install textlint-util-to-string
Constructor(rootNode): source
Return instance of Source.
originalIndexFromIndex(generatedIndex): number
get original index from generated index value
originalPositionFromPosition(position): original
get original position from generated position
originalIndexFromPosition(generatedPosition): number
get original index from generated position
originalPositionFromIndex(generatedIndex): Position
get original position from generated index
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);
// 8 -> 9
// originalText[9];// "E"
assert.equal(source.originalIndexFor(index1), 9);
assert.deepEqual(source.originalPositionFor({
line: 1,
column:8
}), {
line: 1,
column: 9
);
let index2 = result.indexOf("!?");
assert.equal(index2, 15);
// 15 -> 16
// originalText[16];// "!"
assert.equal(source.originalIndexFor(index2), 16);
let AST = ....
let rootNode = AST.children[10];
let source = new StringSource(rootNode);
source.originalIndexFor(0); // should be 0
To return relative position easy to compute position(We think).
One space has a single absolute position, The other should be relative position.
npm test
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT
FAQs
textlint utility that convert Paragraph Node to text with SourceMap.
We found that textlint-util-to-string demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.