1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.parse = exports.Syntax = void 0;
|
7 | const markdown_syntax_map_1 = require("./mapping/markdown-syntax-map");
|
8 | const ast_node_types_1 = require("@textlint/ast-node-types");
|
9 | Object.defineProperty(exports, "Syntax", { enumerable: true, get: function () { return ast_node_types_1.ASTNodeTypes; } });
|
10 | const traverse_1 = __importDefault(require("traverse"));
|
11 | const debug_1 = __importDefault(require("debug"));
|
12 | const parse_markdown_1 = require("./parse-markdown");
|
13 | const debug = debug_1.default("@textlint/markdown-to-ast");
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function parse(text) {
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | const hasBOM = text.charCodeAt(0) === 0xfeff;
|
27 | const textWithoutBOM = hasBOM ? text.slice(1) : text;
|
28 | const ast = parse_markdown_1.parseMarkdown(textWithoutBOM);
|
29 | traverse_1.default(ast).forEach(function (node) {
|
30 |
|
31 | if (this.notLeaf) {
|
32 | if (node.type) {
|
33 | const replacedType = markdown_syntax_map_1.SyntaxMap[node.type];
|
34 | if (!replacedType) {
|
35 | debug(`replacedType : ${replacedType} , node.type: ${node.type}`);
|
36 | }
|
37 | else {
|
38 | node.type = replacedType;
|
39 | }
|
40 | }
|
41 |
|
42 | if (node.position) {
|
43 | const position = node.position;
|
44 | const positionCompensated = {
|
45 | start: { line: position.start.line, column: Math.max(position.start.column - 1, 0) },
|
46 | end: { line: position.end.line, column: Math.max(position.end.column - 1, 0) }
|
47 | };
|
48 | const range = [position.start.offset, position.end.offset];
|
49 | node.loc = positionCompensated;
|
50 | node.range = range;
|
51 | node.raw = textWithoutBOM.slice(range[0], range[1]);
|
52 |
|
53 | Object.defineProperty(node, "position", {
|
54 | enumerable: false,
|
55 | configurable: false,
|
56 | writable: false,
|
57 | value: position
|
58 | });
|
59 | }
|
60 | }
|
61 | });
|
62 | return ast;
|
63 | }
|
64 | exports.parse = parse;
|
65 |
|
\ | No newline at end of file |