@textlint/text-to-ast
Advanced tools
Comparing version 12.0.0-beta.0 to 12.0.0-beta.1
@@ -5,6 +5,6 @@ // LICENSE : MIT | ||
exports.Syntax = exports.parse = void 0; | ||
var plaintext_parser_1 = require("./plaintext-parser"); | ||
const plaintext_parser_1 = require("./plaintext-parser"); | ||
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return plaintext_parser_1.parse; } }); | ||
var plaintext_syntax_1 = require("./plaintext-syntax"); | ||
const plaintext_syntax_1 = require("./plaintext-syntax"); | ||
Object.defineProperty(exports, "Syntax", { enumerable: true, get: function () { return plaintext_syntax_1.Syntax; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,3 @@ // LICENSE : MIT | ||
exports.parse = void 0; | ||
var plaintext_syntax_1 = require("./plaintext-syntax"); | ||
const plaintext_syntax_1 = require("./plaintext-syntax"); | ||
function parseLine(lineText, lineNumber, startIndex) { | ||
@@ -32,4 +32,3 @@ // Inline Node have `value`. It it not part of TxtNode. | ||
*/ | ||
function createEndedBRNode(_a) { | ||
var prevNode = _a.prevNode, lineBreakText = _a.lineBreakText; | ||
function createEndedBRNode({ prevNode, lineBreakText }) { | ||
return { | ||
@@ -54,4 +53,3 @@ type: plaintext_syntax_1.Syntax.Break, | ||
*/ | ||
function createBRNode(_a) { | ||
var lineBreak = _a.lineBreak, lineNumber = _a.lineNumber, startIndex = _a.startIndex; | ||
function createBRNode({ lineBreak, lineNumber, startIndex }) { | ||
return { | ||
@@ -79,4 +77,4 @@ type: plaintext_syntax_1.Syntax.Break, | ||
function createParagraph(nodes) { | ||
var firstNode = nodes[0]; | ||
var lastNode = nodes[nodes.length - 1]; | ||
const firstNode = nodes[0]; | ||
const lastNode = nodes[nodes.length - 1]; | ||
return { | ||
@@ -104,8 +102,8 @@ type: plaintext_syntax_1.Syntax.Paragraph, | ||
function splitTextByLine(text) { | ||
var LINEBREAK_MARK_PATTERN = /\r?\n/g; | ||
var results = []; | ||
var match = null; | ||
var prevMatchIndex = 0; | ||
const LINEBREAK_MARK_PATTERN = /\r?\n/g; | ||
const results = []; | ||
let match = null; | ||
let prevMatchIndex = 0; | ||
while ((match = LINEBREAK_MARK_PATTERN.exec(text)) !== null) { | ||
var slicedText = text.slice(prevMatchIndex, match.index); | ||
const slicedText = text.slice(prevMatchIndex, match.index); | ||
results.push({ | ||
@@ -131,14 +129,14 @@ text: prevMatchIndex === match.index ? "" : slicedText, | ||
function parse(text) { | ||
var textLineByLine = splitTextByLine(text); | ||
const textLineByLine = splitTextByLine(text); | ||
// it should be alternately Str and Break | ||
var startIndex = 0; | ||
var lastLineIndex = textLineByLine.length - 1; | ||
var isLastEmptyLine = function (line, index) { | ||
let startIndex = 0; | ||
const lastLineIndex = textLineByLine.length - 1; | ||
const isLastEmptyLine = (line, index) => { | ||
return index === lastLineIndex && line.text === ""; | ||
}; | ||
var isEmptyLine = function (line, index) { | ||
const isEmptyLine = (line, index) => { | ||
return index !== lastLineIndex && line.text === ""; | ||
}; | ||
var children = textLineByLine.reduce(function (result, currentLine, index) { | ||
var lineNumber = index + 1; | ||
const children = textLineByLine.reduce(function (result, currentLine, index) { | ||
const lineNumber = index + 1; | ||
if (isLastEmptyLine(currentLine, index)) { | ||
@@ -149,6 +147,6 @@ return result; | ||
if (isEmptyLine(currentLine, index)) { | ||
var emptyBreakNode = createBRNode({ | ||
const emptyBreakNode = createBRNode({ | ||
lineBreak: currentLine.lineBreak, | ||
lineNumber: lineNumber, | ||
startIndex: startIndex | ||
lineNumber, | ||
startIndex | ||
}); | ||
@@ -160,4 +158,4 @@ startIndex += emptyBreakNode.raw.length; | ||
// (Paragraph > Str) -> Br? | ||
var strNode = parseLine(currentLine.text, lineNumber, startIndex); | ||
var paragraph = createParagraph([strNode]); | ||
const strNode = parseLine(currentLine.text, lineNumber, startIndex); | ||
const paragraph = createParagraph([strNode]); | ||
startIndex += paragraph.raw.length; | ||
@@ -169,3 +167,3 @@ result.push(paragraph); | ||
if (currentLine.lineBreak !== null) { | ||
var breakNode = createEndedBRNode({ prevNode: paragraph, lineBreakText: currentLine.lineBreak }); | ||
const breakNode = createEndedBRNode({ prevNode: paragraph, lineBreakText: currentLine.lineBreak }); | ||
startIndex += breakNode.raw.length; | ||
@@ -176,3 +174,3 @@ result.push(breakNode); | ||
}, []); | ||
var lastLine = textLineByLine[textLineByLine.length - 1]; | ||
const lastLine = textLineByLine[textLineByLine.length - 1]; | ||
if (lastLine === undefined) { | ||
@@ -193,3 +191,3 @@ return { | ||
}, | ||
children: children | ||
children | ||
}; | ||
@@ -218,3 +216,3 @@ } | ||
}, | ||
children: children | ||
children | ||
}; | ||
@@ -221,0 +219,0 @@ } |
@@ -5,3 +5,3 @@ // LICENSE : MIT | ||
exports.Syntax = void 0; | ||
var ast_node_types_1 = require("@textlint/ast-node-types"); | ||
const ast_node_types_1 = require("@textlint/ast-node-types"); | ||
exports.Syntax = { | ||
@@ -8,0 +8,0 @@ Document: ast_node_types_1.ASTNodeTypes.Document, |
@@ -29,4 +29,3 @@ // LICENSE : MIT | ||
*/ | ||
function createEndedBRNode(_a) { | ||
var prevNode = _a.prevNode, lineBreakText = _a.lineBreakText; | ||
function createEndedBRNode({ prevNode, lineBreakText }) { | ||
return { | ||
@@ -51,4 +50,3 @@ type: Syntax.Break, | ||
*/ | ||
function createBRNode(_a) { | ||
var lineBreak = _a.lineBreak, lineNumber = _a.lineNumber, startIndex = _a.startIndex; | ||
function createBRNode({ lineBreak, lineNumber, startIndex }) { | ||
return { | ||
@@ -76,4 +74,4 @@ type: Syntax.Break, | ||
function createParagraph(nodes) { | ||
var firstNode = nodes[0]; | ||
var lastNode = nodes[nodes.length - 1]; | ||
const firstNode = nodes[0]; | ||
const lastNode = nodes[nodes.length - 1]; | ||
return { | ||
@@ -101,8 +99,8 @@ type: Syntax.Paragraph, | ||
function splitTextByLine(text) { | ||
var LINEBREAK_MARK_PATTERN = /\r?\n/g; | ||
var results = []; | ||
var match = null; | ||
var prevMatchIndex = 0; | ||
const LINEBREAK_MARK_PATTERN = /\r?\n/g; | ||
const results = []; | ||
let match = null; | ||
let prevMatchIndex = 0; | ||
while ((match = LINEBREAK_MARK_PATTERN.exec(text)) !== null) { | ||
var slicedText = text.slice(prevMatchIndex, match.index); | ||
const slicedText = text.slice(prevMatchIndex, match.index); | ||
results.push({ | ||
@@ -128,14 +126,14 @@ text: prevMatchIndex === match.index ? "" : slicedText, | ||
export function parse(text) { | ||
var textLineByLine = splitTextByLine(text); | ||
const textLineByLine = splitTextByLine(text); | ||
// it should be alternately Str and Break | ||
var startIndex = 0; | ||
var lastLineIndex = textLineByLine.length - 1; | ||
var isLastEmptyLine = function (line, index) { | ||
let startIndex = 0; | ||
const lastLineIndex = textLineByLine.length - 1; | ||
const isLastEmptyLine = (line, index) => { | ||
return index === lastLineIndex && line.text === ""; | ||
}; | ||
var isEmptyLine = function (line, index) { | ||
const isEmptyLine = (line, index) => { | ||
return index !== lastLineIndex && line.text === ""; | ||
}; | ||
var children = textLineByLine.reduce(function (result, currentLine, index) { | ||
var lineNumber = index + 1; | ||
const children = textLineByLine.reduce(function (result, currentLine, index) { | ||
const lineNumber = index + 1; | ||
if (isLastEmptyLine(currentLine, index)) { | ||
@@ -146,6 +144,6 @@ return result; | ||
if (isEmptyLine(currentLine, index)) { | ||
var emptyBreakNode = createBRNode({ | ||
const emptyBreakNode = createBRNode({ | ||
lineBreak: currentLine.lineBreak, | ||
lineNumber: lineNumber, | ||
startIndex: startIndex | ||
lineNumber, | ||
startIndex | ||
}); | ||
@@ -157,4 +155,4 @@ startIndex += emptyBreakNode.raw.length; | ||
// (Paragraph > Str) -> Br? | ||
var strNode = parseLine(currentLine.text, lineNumber, startIndex); | ||
var paragraph = createParagraph([strNode]); | ||
const strNode = parseLine(currentLine.text, lineNumber, startIndex); | ||
const paragraph = createParagraph([strNode]); | ||
startIndex += paragraph.raw.length; | ||
@@ -166,3 +164,3 @@ result.push(paragraph); | ||
if (currentLine.lineBreak !== null) { | ||
var breakNode = createEndedBRNode({ prevNode: paragraph, lineBreakText: currentLine.lineBreak }); | ||
const breakNode = createEndedBRNode({ prevNode: paragraph, lineBreakText: currentLine.lineBreak }); | ||
startIndex += breakNode.raw.length; | ||
@@ -173,3 +171,3 @@ result.push(breakNode); | ||
}, []); | ||
var lastLine = textLineByLine[textLineByLine.length - 1]; | ||
const lastLine = textLineByLine[textLineByLine.length - 1]; | ||
if (lastLine === undefined) { | ||
@@ -190,3 +188,3 @@ return { | ||
}, | ||
children: children | ||
children | ||
}; | ||
@@ -215,5 +213,5 @@ } | ||
}, | ||
children: children | ||
children | ||
}; | ||
} | ||
//# sourceMappingURL=plaintext-parser.js.map |
// LICENSE : MIT | ||
"use strict"; | ||
import { ASTNodeTypes } from "@textlint/ast-node-types"; | ||
export var Syntax = { | ||
export const Syntax = { | ||
Document: ASTNodeTypes.Document, | ||
@@ -6,0 +6,0 @@ Paragraph: ASTNodeTypes.Paragraph, |
{ | ||
"name": "@textlint/text-to-ast", | ||
"version": "12.0.0-beta.0", | ||
"version": "12.0.0-beta.1", | ||
"description": "Parse plain text to AST with location info.", | ||
@@ -44,6 +44,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@textlint/ast-node-types": "^12.0.0-beta.0" | ||
"@textlint/ast-node-types": "^12.0.0-beta.1" | ||
}, | ||
"devDependencies": { | ||
"@textlint/ast-tester": "^12.0.0-beta.0", | ||
"@textlint/ast-tester": "^12.0.0-beta.1", | ||
"cross-env": "^7.0.3", | ||
@@ -60,3 +60,3 @@ "eol-converter-cli": "^1.0.8", | ||
}, | ||
"gitHead": "1e0d0d7f628be0bfce04b6cd36fcc8390ca43096" | ||
"gitHead": "2856b387cfb0a151655a809e8253b242e7b90725" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
153418
714