text-doc-ir 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/deps.d.ts +1 -1
- package/esm/main.d.ts +3 -1
- package/esm/main.js +99 -2
- package/package.json +2 -2
- package/script/deps.d.ts +1 -1
- package/script/main.d.ts +3 -1
- package/script/main.js +99 -2
package/esm/deps.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { NodeVisitor } from "document-ir";
|
|
2
|
-
export type { BlockQuoteNode, BreakNode, BubbleNode, CardNode, CenterNode, ColumnsNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureImageNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, StickerNode, StrikeThroughNode, TextNode, VideoNode, WarningNode, } from "document-ir";
|
|
2
|
+
export type { BlockQuoteNode, BreakNode, BubbleNode, CardNode, CenterNode, ColumnsNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureImageNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, StickerNode, StrikeThroughNode, TableOfContentsNode, TextNode, VideoNode, WarningNode, } from "document-ir";
|
package/esm/main.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockQuoteNode, BreakNode, BubbleNode, CardNode, CenterNode, ColumnsNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureImageNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, LinkNode, ListNode, NodeVisitor, NoteNode, ParagraphNode, QuoteNode, StickerNode, StrikeThroughNode, TextNode, VideoNode, WarningNode } from "./deps.js";
|
|
1
|
+
import { BlockQuoteNode, BreakNode, BubbleNode, CardNode, CenterNode, ColumnsNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureImageNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, LinkNode, ListNode, NodeVisitor, NoteNode, ParagraphNode, QuoteNode, StickerNode, StrikeThroughNode, TableOfContentsNode, TextNode, VideoNode, WarningNode } from "./deps.js";
|
|
2
2
|
export declare class FixedWidthTextVisitor extends NodeVisitor {
|
|
3
3
|
private width;
|
|
4
4
|
private lines;
|
|
@@ -10,6 +10,7 @@ export declare class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
10
10
|
private state;
|
|
11
11
|
constructor(width: number);
|
|
12
12
|
private setState;
|
|
13
|
+
private restoreState;
|
|
13
14
|
protected text(node: TextNode): void;
|
|
14
15
|
protected formattedText(node: FormattedTextNode): void;
|
|
15
16
|
protected horizontalRule(node: HorizontalRuleNode): void;
|
|
@@ -36,6 +37,7 @@ export declare class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
36
37
|
protected card(node: CardNode): void;
|
|
37
38
|
protected definitionReference(node: DefinitionReferenceNode): void;
|
|
38
39
|
protected definition(node: DefinitionNode): void;
|
|
40
|
+
protected toc(node: TableOfContentsNode): void;
|
|
39
41
|
protected document(node: DocumentNode): void;
|
|
40
42
|
private counterToDepth;
|
|
41
43
|
private pushBlockContentBegin;
|
package/esm/main.js
CHANGED
|
@@ -66,11 +66,16 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
66
66
|
linksReverse: new Map(),
|
|
67
67
|
linkCount: 0,
|
|
68
68
|
numericDepth: 0,
|
|
69
|
+
tocDepth: 0,
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
72
|
setState(state) {
|
|
72
73
|
this.state = state;
|
|
73
74
|
}
|
|
75
|
+
restoreState(parent) {
|
|
76
|
+
parent.state.imageCount = this.state.imageCount;
|
|
77
|
+
parent.state.linkCount = this.state.linkCount;
|
|
78
|
+
}
|
|
74
79
|
text(node) {
|
|
75
80
|
this.pushText(node.text);
|
|
76
81
|
}
|
|
@@ -133,6 +138,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
140
|
}
|
|
141
|
+
visitor.restoreState(this);
|
|
136
142
|
}
|
|
137
143
|
}
|
|
138
144
|
else {
|
|
@@ -149,6 +155,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
149
155
|
this.lines.push(" " + lines[i]);
|
|
150
156
|
}
|
|
151
157
|
}
|
|
158
|
+
visitor.restoreState(this);
|
|
152
159
|
}
|
|
153
160
|
}
|
|
154
161
|
this.pushBlockContentEnd();
|
|
@@ -175,6 +182,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
175
182
|
columns.push(lines);
|
|
176
183
|
maxLines = Math.max(maxLines, lines.length);
|
|
177
184
|
consumedWidth += width;
|
|
185
|
+
visitor.restoreState(this);
|
|
178
186
|
}
|
|
179
187
|
this.pushBlockContentBegin();
|
|
180
188
|
for (let i = 0; i < maxLines; i++) {
|
|
@@ -338,6 +346,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
338
346
|
this.lines[Math.max(0, this.lines.length - 1)] =
|
|
339
347
|
" ".repeat(Math.floor((this.width - line.length) / 2)) + line;
|
|
340
348
|
}
|
|
349
|
+
visitor.restoreState(this);
|
|
341
350
|
this.pushBlockContentEnd();
|
|
342
351
|
}
|
|
343
352
|
warning(node) {
|
|
@@ -352,6 +361,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
352
361
|
this.pushEndOfLineIfAnyContent();
|
|
353
362
|
this.lines[Math.max(0, this.lines.length - 1)] = "| " + line;
|
|
354
363
|
}
|
|
364
|
+
visitor.restoreState(this);
|
|
355
365
|
this.pushBlockContentEnd();
|
|
356
366
|
}
|
|
357
367
|
highTechAlert(node) {
|
|
@@ -376,6 +386,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
376
386
|
this.pushLine();
|
|
377
387
|
this.pushText("|" + "-".repeat(this.width - 2) + "|");
|
|
378
388
|
}
|
|
389
|
+
centerVisitor.restoreState(this);
|
|
379
390
|
const contentVisitor = new FixedWidthTextVisitor(this.width - 4);
|
|
380
391
|
contentVisitor.setState({ ...this.state, numericDepth: 0 });
|
|
381
392
|
contentVisitor.visit({
|
|
@@ -391,6 +402,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
391
402
|
this.pushText("\\");
|
|
392
403
|
this.pushText("-".repeat(this.width - 2));
|
|
393
404
|
this.pushText("/");
|
|
405
|
+
contentVisitor.restoreState(this);
|
|
394
406
|
this.pushBlockContentEnd();
|
|
395
407
|
}
|
|
396
408
|
blockQuote(node) {
|
|
@@ -405,6 +417,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
405
417
|
this.pushEndOfLineIfAnyContent();
|
|
406
418
|
this.lines[Math.max(0, this.lines.length - 1)] = "> " + line;
|
|
407
419
|
}
|
|
420
|
+
visitor.restoreState(this);
|
|
408
421
|
this.pushBlockContentEnd();
|
|
409
422
|
}
|
|
410
423
|
quote(node) {
|
|
@@ -424,6 +437,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
424
437
|
this.pushEndOfLineIfAnyContent();
|
|
425
438
|
this.lines[Math.max(0, this.lines.length - 1)] = "> " + line;
|
|
426
439
|
}
|
|
440
|
+
visitor.restoreState(this);
|
|
427
441
|
this.pushBlockContentEnd();
|
|
428
442
|
}
|
|
429
443
|
bubble(node) {
|
|
@@ -446,6 +460,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
446
460
|
" ".repeat(this.width - 2 - line.length) + line + " |";
|
|
447
461
|
}
|
|
448
462
|
}
|
|
463
|
+
visitor.restoreState(this);
|
|
449
464
|
this.pushBlockContentEnd();
|
|
450
465
|
}
|
|
451
466
|
sticker(node) {
|
|
@@ -497,6 +512,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
497
512
|
this.pushText("\\");
|
|
498
513
|
this.pushText("-".repeat(this.width - 2));
|
|
499
514
|
this.pushText("/");
|
|
515
|
+
visitor.restoreState(this);
|
|
500
516
|
this.pushBlockContentEnd();
|
|
501
517
|
}
|
|
502
518
|
card(node) {
|
|
@@ -534,6 +550,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
534
550
|
this.pushLine();
|
|
535
551
|
this.pushText("|" + "-".repeat(this.width - 2) + "|");
|
|
536
552
|
}
|
|
553
|
+
centerVisitor.restoreState(this);
|
|
537
554
|
}
|
|
538
555
|
const contentVisitor = new FixedWidthTextVisitor(this.width - 4);
|
|
539
556
|
contentVisitor.setState({ ...this.state, numericDepth: 0 });
|
|
@@ -585,6 +602,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
585
602
|
this.pushText("\\");
|
|
586
603
|
this.pushText("-".repeat(this.width - 2));
|
|
587
604
|
this.pushText("/");
|
|
605
|
+
contentVisitor.restoreState(this);
|
|
588
606
|
this.pushBlockContentEnd();
|
|
589
607
|
}
|
|
590
608
|
definitionReference(node) {
|
|
@@ -612,8 +630,86 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
612
630
|
this.pushEndOfLineIfAnyContent();
|
|
613
631
|
this.lines[Math.max(0, this.lines.length - 1)] = " " + line;
|
|
614
632
|
}
|
|
633
|
+
visitor.restoreState(this);
|
|
615
634
|
this.pushBlockContentEnd();
|
|
616
635
|
}
|
|
636
|
+
toc(node) {
|
|
637
|
+
if (this.state.tocDepth > 0) {
|
|
638
|
+
const visitor = new FixedWidthTextVisitor(this.width - 3);
|
|
639
|
+
visitor.setState({ ...this.state, tocDepth: this.state.tocDepth + 1 });
|
|
640
|
+
if (node.date) {
|
|
641
|
+
visitor.choose(node.date);
|
|
642
|
+
visitor.pushText(" ");
|
|
643
|
+
}
|
|
644
|
+
visitor.chooseChildren(node.content);
|
|
645
|
+
if (node.href && !node.href.startsWith("#")) {
|
|
646
|
+
visitor.link({
|
|
647
|
+
type: "link",
|
|
648
|
+
url: node.href,
|
|
649
|
+
content: [],
|
|
650
|
+
});
|
|
651
|
+
visitor.spaceLazy = true;
|
|
652
|
+
}
|
|
653
|
+
visitor.restoreState(this);
|
|
654
|
+
visitor.visit({
|
|
655
|
+
type: "array",
|
|
656
|
+
content: node.children,
|
|
657
|
+
});
|
|
658
|
+
let counter = 0;
|
|
659
|
+
for (const line of visitor.getLines()) {
|
|
660
|
+
this.pushEndOfLineIfAnyContent();
|
|
661
|
+
// First line gets a bullet point
|
|
662
|
+
if (counter == 0) {
|
|
663
|
+
this.lines[Math.max(0, this.lines.length - 1)] = "* " + line;
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
this.lines[Math.max(0, this.lines.length - 1)] = " " + line;
|
|
667
|
+
}
|
|
668
|
+
counter++;
|
|
669
|
+
}
|
|
670
|
+
visitor.restoreState(this);
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
const visitor = new FixedWidthTextVisitor(this.width - 4);
|
|
674
|
+
visitor.setState({ ...this.state, tocDepth: this.state.tocDepth + 1 });
|
|
675
|
+
if (node.date) {
|
|
676
|
+
visitor.choose(node.date);
|
|
677
|
+
visitor.pushText(" ");
|
|
678
|
+
}
|
|
679
|
+
visitor.chooseChildren(node.content);
|
|
680
|
+
if (node.href && !node.href.startsWith("#")) {
|
|
681
|
+
visitor.link({
|
|
682
|
+
type: "link",
|
|
683
|
+
url: node.href,
|
|
684
|
+
content: [],
|
|
685
|
+
});
|
|
686
|
+
visitor.spaceLazy = true;
|
|
687
|
+
}
|
|
688
|
+
visitor.pushLine();
|
|
689
|
+
visitor.visit({
|
|
690
|
+
type: "array",
|
|
691
|
+
content: node.children,
|
|
692
|
+
});
|
|
693
|
+
const tocLen = " Table of contents ".length;
|
|
694
|
+
const lines = visitor.getLines();
|
|
695
|
+
const maxLength = lines.reduce((prev, next) => Math.max(prev, next.length + 1), tocLen + 2);
|
|
696
|
+
const left = Math.floor((maxLength - tocLen) / 2) + 1;
|
|
697
|
+
const right = maxLength - tocLen - left + 1;
|
|
698
|
+
this.pushBlockContentBegin();
|
|
699
|
+
this.lines[Math.max(0, this.lines.length - 1)] = "/" + "-".repeat(left) +
|
|
700
|
+
" Table of contents " + "-".repeat(right) + "\\";
|
|
701
|
+
for (const line of lines) {
|
|
702
|
+
this.pushEndOfLineIfAnyContent();
|
|
703
|
+
this.lines[Math.max(0, this.lines.length - 1)] = "| " + line +
|
|
704
|
+
" ".repeat(maxLength - line.length) + "|";
|
|
705
|
+
}
|
|
706
|
+
this.pushEndOfLineIfAnyContent();
|
|
707
|
+
this.lines[Math.max(0, this.lines.length - 1)] = "\\" +
|
|
708
|
+
"-".repeat(maxLength + 1) + "/";
|
|
709
|
+
visitor.restoreState(this);
|
|
710
|
+
this.pushBlockContentEnd();
|
|
711
|
+
}
|
|
712
|
+
}
|
|
617
713
|
document(node) {
|
|
618
714
|
this.pushBlockContentBegin();
|
|
619
715
|
let date;
|
|
@@ -642,8 +738,9 @@ export class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
642
738
|
super.document(node);
|
|
643
739
|
this.horizontalRule({ type: "horizontal-rule" });
|
|
644
740
|
if (this.state.linkCount > 0) {
|
|
645
|
-
const
|
|
646
|
-
|
|
741
|
+
const max = this.state.linkCount;
|
|
742
|
+
const length = Math.max(7, `[L${max}]: `.length);
|
|
743
|
+
for (let i = 1; i <= max; i++) {
|
|
647
744
|
const label = `[L${i}]: `;
|
|
648
745
|
const visitor = new FixedWidthTextVisitor(this.width - length);
|
|
649
746
|
visitor.text({
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"module": "./esm/main.js",
|
|
3
3
|
"main": "./script/main.js",
|
|
4
4
|
"name": "text-doc-ir",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.13",
|
|
6
6
|
"description": "Transforms a document intermediate representation into plain text with formatting",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"document-ir": "0.0.
|
|
22
|
+
"document-ir": "0.0.15"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^18.11.9"
|
package/script/deps.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { NodeVisitor } from "document-ir";
|
|
2
|
-
export type { BlockQuoteNode, BreakNode, BubbleNode, CardNode, CenterNode, ColumnsNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureImageNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, StickerNode, StrikeThroughNode, TextNode, VideoNode, WarningNode, } from "document-ir";
|
|
2
|
+
export type { BlockQuoteNode, BreakNode, BubbleNode, CardNode, CenterNode, ColumnsNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureImageNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, StickerNode, StrikeThroughNode, TableOfContentsNode, TextNode, VideoNode, WarningNode, } from "document-ir";
|
package/script/main.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockQuoteNode, BreakNode, BubbleNode, CardNode, CenterNode, ColumnsNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureImageNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, LinkNode, ListNode, NodeVisitor, NoteNode, ParagraphNode, QuoteNode, StickerNode, StrikeThroughNode, TextNode, VideoNode, WarningNode } from "./deps.js";
|
|
1
|
+
import { BlockQuoteNode, BreakNode, BubbleNode, CardNode, CenterNode, ColumnsNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureImageNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, LinkNode, ListNode, NodeVisitor, NoteNode, ParagraphNode, QuoteNode, StickerNode, StrikeThroughNode, TableOfContentsNode, TextNode, VideoNode, WarningNode } from "./deps.js";
|
|
2
2
|
export declare class FixedWidthTextVisitor extends NodeVisitor {
|
|
3
3
|
private width;
|
|
4
4
|
private lines;
|
|
@@ -10,6 +10,7 @@ export declare class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
10
10
|
private state;
|
|
11
11
|
constructor(width: number);
|
|
12
12
|
private setState;
|
|
13
|
+
private restoreState;
|
|
13
14
|
protected text(node: TextNode): void;
|
|
14
15
|
protected formattedText(node: FormattedTextNode): void;
|
|
15
16
|
protected horizontalRule(node: HorizontalRuleNode): void;
|
|
@@ -36,6 +37,7 @@ export declare class FixedWidthTextVisitor extends NodeVisitor {
|
|
|
36
37
|
protected card(node: CardNode): void;
|
|
37
38
|
protected definitionReference(node: DefinitionReferenceNode): void;
|
|
38
39
|
protected definition(node: DefinitionNode): void;
|
|
40
|
+
protected toc(node: TableOfContentsNode): void;
|
|
39
41
|
protected document(node: DocumentNode): void;
|
|
40
42
|
private counterToDepth;
|
|
41
43
|
private pushBlockContentBegin;
|
package/script/main.js
CHANGED
|
@@ -69,11 +69,16 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
69
69
|
linksReverse: new Map(),
|
|
70
70
|
linkCount: 0,
|
|
71
71
|
numericDepth: 0,
|
|
72
|
+
tocDepth: 0,
|
|
72
73
|
};
|
|
73
74
|
}
|
|
74
75
|
setState(state) {
|
|
75
76
|
this.state = state;
|
|
76
77
|
}
|
|
78
|
+
restoreState(parent) {
|
|
79
|
+
parent.state.imageCount = this.state.imageCount;
|
|
80
|
+
parent.state.linkCount = this.state.linkCount;
|
|
81
|
+
}
|
|
77
82
|
text(node) {
|
|
78
83
|
this.pushText(node.text);
|
|
79
84
|
}
|
|
@@ -136,6 +141,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
}
|
|
144
|
+
visitor.restoreState(this);
|
|
139
145
|
}
|
|
140
146
|
}
|
|
141
147
|
else {
|
|
@@ -152,6 +158,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
152
158
|
this.lines.push(" " + lines[i]);
|
|
153
159
|
}
|
|
154
160
|
}
|
|
161
|
+
visitor.restoreState(this);
|
|
155
162
|
}
|
|
156
163
|
}
|
|
157
164
|
this.pushBlockContentEnd();
|
|
@@ -178,6 +185,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
178
185
|
columns.push(lines);
|
|
179
186
|
maxLines = Math.max(maxLines, lines.length);
|
|
180
187
|
consumedWidth += width;
|
|
188
|
+
visitor.restoreState(this);
|
|
181
189
|
}
|
|
182
190
|
this.pushBlockContentBegin();
|
|
183
191
|
for (let i = 0; i < maxLines; i++) {
|
|
@@ -341,6 +349,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
341
349
|
this.lines[Math.max(0, this.lines.length - 1)] =
|
|
342
350
|
" ".repeat(Math.floor((this.width - line.length) / 2)) + line;
|
|
343
351
|
}
|
|
352
|
+
visitor.restoreState(this);
|
|
344
353
|
this.pushBlockContentEnd();
|
|
345
354
|
}
|
|
346
355
|
warning(node) {
|
|
@@ -355,6 +364,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
355
364
|
this.pushEndOfLineIfAnyContent();
|
|
356
365
|
this.lines[Math.max(0, this.lines.length - 1)] = "| " + line;
|
|
357
366
|
}
|
|
367
|
+
visitor.restoreState(this);
|
|
358
368
|
this.pushBlockContentEnd();
|
|
359
369
|
}
|
|
360
370
|
highTechAlert(node) {
|
|
@@ -379,6 +389,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
379
389
|
this.pushLine();
|
|
380
390
|
this.pushText("|" + "-".repeat(this.width - 2) + "|");
|
|
381
391
|
}
|
|
392
|
+
centerVisitor.restoreState(this);
|
|
382
393
|
const contentVisitor = new FixedWidthTextVisitor(this.width - 4);
|
|
383
394
|
contentVisitor.setState({ ...this.state, numericDepth: 0 });
|
|
384
395
|
contentVisitor.visit({
|
|
@@ -394,6 +405,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
394
405
|
this.pushText("\\");
|
|
395
406
|
this.pushText("-".repeat(this.width - 2));
|
|
396
407
|
this.pushText("/");
|
|
408
|
+
contentVisitor.restoreState(this);
|
|
397
409
|
this.pushBlockContentEnd();
|
|
398
410
|
}
|
|
399
411
|
blockQuote(node) {
|
|
@@ -408,6 +420,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
408
420
|
this.pushEndOfLineIfAnyContent();
|
|
409
421
|
this.lines[Math.max(0, this.lines.length - 1)] = "> " + line;
|
|
410
422
|
}
|
|
423
|
+
visitor.restoreState(this);
|
|
411
424
|
this.pushBlockContentEnd();
|
|
412
425
|
}
|
|
413
426
|
quote(node) {
|
|
@@ -427,6 +440,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
427
440
|
this.pushEndOfLineIfAnyContent();
|
|
428
441
|
this.lines[Math.max(0, this.lines.length - 1)] = "> " + line;
|
|
429
442
|
}
|
|
443
|
+
visitor.restoreState(this);
|
|
430
444
|
this.pushBlockContentEnd();
|
|
431
445
|
}
|
|
432
446
|
bubble(node) {
|
|
@@ -449,6 +463,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
449
463
|
" ".repeat(this.width - 2 - line.length) + line + " |";
|
|
450
464
|
}
|
|
451
465
|
}
|
|
466
|
+
visitor.restoreState(this);
|
|
452
467
|
this.pushBlockContentEnd();
|
|
453
468
|
}
|
|
454
469
|
sticker(node) {
|
|
@@ -500,6 +515,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
500
515
|
this.pushText("\\");
|
|
501
516
|
this.pushText("-".repeat(this.width - 2));
|
|
502
517
|
this.pushText("/");
|
|
518
|
+
visitor.restoreState(this);
|
|
503
519
|
this.pushBlockContentEnd();
|
|
504
520
|
}
|
|
505
521
|
card(node) {
|
|
@@ -537,6 +553,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
537
553
|
this.pushLine();
|
|
538
554
|
this.pushText("|" + "-".repeat(this.width - 2) + "|");
|
|
539
555
|
}
|
|
556
|
+
centerVisitor.restoreState(this);
|
|
540
557
|
}
|
|
541
558
|
const contentVisitor = new FixedWidthTextVisitor(this.width - 4);
|
|
542
559
|
contentVisitor.setState({ ...this.state, numericDepth: 0 });
|
|
@@ -588,6 +605,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
588
605
|
this.pushText("\\");
|
|
589
606
|
this.pushText("-".repeat(this.width - 2));
|
|
590
607
|
this.pushText("/");
|
|
608
|
+
contentVisitor.restoreState(this);
|
|
591
609
|
this.pushBlockContentEnd();
|
|
592
610
|
}
|
|
593
611
|
definitionReference(node) {
|
|
@@ -615,8 +633,86 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
615
633
|
this.pushEndOfLineIfAnyContent();
|
|
616
634
|
this.lines[Math.max(0, this.lines.length - 1)] = " " + line;
|
|
617
635
|
}
|
|
636
|
+
visitor.restoreState(this);
|
|
618
637
|
this.pushBlockContentEnd();
|
|
619
638
|
}
|
|
639
|
+
toc(node) {
|
|
640
|
+
if (this.state.tocDepth > 0) {
|
|
641
|
+
const visitor = new FixedWidthTextVisitor(this.width - 3);
|
|
642
|
+
visitor.setState({ ...this.state, tocDepth: this.state.tocDepth + 1 });
|
|
643
|
+
if (node.date) {
|
|
644
|
+
visitor.choose(node.date);
|
|
645
|
+
visitor.pushText(" ");
|
|
646
|
+
}
|
|
647
|
+
visitor.chooseChildren(node.content);
|
|
648
|
+
if (node.href && !node.href.startsWith("#")) {
|
|
649
|
+
visitor.link({
|
|
650
|
+
type: "link",
|
|
651
|
+
url: node.href,
|
|
652
|
+
content: [],
|
|
653
|
+
});
|
|
654
|
+
visitor.spaceLazy = true;
|
|
655
|
+
}
|
|
656
|
+
visitor.restoreState(this);
|
|
657
|
+
visitor.visit({
|
|
658
|
+
type: "array",
|
|
659
|
+
content: node.children,
|
|
660
|
+
});
|
|
661
|
+
let counter = 0;
|
|
662
|
+
for (const line of visitor.getLines()) {
|
|
663
|
+
this.pushEndOfLineIfAnyContent();
|
|
664
|
+
// First line gets a bullet point
|
|
665
|
+
if (counter == 0) {
|
|
666
|
+
this.lines[Math.max(0, this.lines.length - 1)] = "* " + line;
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
this.lines[Math.max(0, this.lines.length - 1)] = " " + line;
|
|
670
|
+
}
|
|
671
|
+
counter++;
|
|
672
|
+
}
|
|
673
|
+
visitor.restoreState(this);
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
const visitor = new FixedWidthTextVisitor(this.width - 4);
|
|
677
|
+
visitor.setState({ ...this.state, tocDepth: this.state.tocDepth + 1 });
|
|
678
|
+
if (node.date) {
|
|
679
|
+
visitor.choose(node.date);
|
|
680
|
+
visitor.pushText(" ");
|
|
681
|
+
}
|
|
682
|
+
visitor.chooseChildren(node.content);
|
|
683
|
+
if (node.href && !node.href.startsWith("#")) {
|
|
684
|
+
visitor.link({
|
|
685
|
+
type: "link",
|
|
686
|
+
url: node.href,
|
|
687
|
+
content: [],
|
|
688
|
+
});
|
|
689
|
+
visitor.spaceLazy = true;
|
|
690
|
+
}
|
|
691
|
+
visitor.pushLine();
|
|
692
|
+
visitor.visit({
|
|
693
|
+
type: "array",
|
|
694
|
+
content: node.children,
|
|
695
|
+
});
|
|
696
|
+
const tocLen = " Table of contents ".length;
|
|
697
|
+
const lines = visitor.getLines();
|
|
698
|
+
const maxLength = lines.reduce((prev, next) => Math.max(prev, next.length + 1), tocLen + 2);
|
|
699
|
+
const left = Math.floor((maxLength - tocLen) / 2) + 1;
|
|
700
|
+
const right = maxLength - tocLen - left + 1;
|
|
701
|
+
this.pushBlockContentBegin();
|
|
702
|
+
this.lines[Math.max(0, this.lines.length - 1)] = "/" + "-".repeat(left) +
|
|
703
|
+
" Table of contents " + "-".repeat(right) + "\\";
|
|
704
|
+
for (const line of lines) {
|
|
705
|
+
this.pushEndOfLineIfAnyContent();
|
|
706
|
+
this.lines[Math.max(0, this.lines.length - 1)] = "| " + line +
|
|
707
|
+
" ".repeat(maxLength - line.length) + "|";
|
|
708
|
+
}
|
|
709
|
+
this.pushEndOfLineIfAnyContent();
|
|
710
|
+
this.lines[Math.max(0, this.lines.length - 1)] = "\\" +
|
|
711
|
+
"-".repeat(maxLength + 1) + "/";
|
|
712
|
+
visitor.restoreState(this);
|
|
713
|
+
this.pushBlockContentEnd();
|
|
714
|
+
}
|
|
715
|
+
}
|
|
620
716
|
document(node) {
|
|
621
717
|
this.pushBlockContentBegin();
|
|
622
718
|
let date;
|
|
@@ -645,8 +741,9 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
|
|
|
645
741
|
super.document(node);
|
|
646
742
|
this.horizontalRule({ type: "horizontal-rule" });
|
|
647
743
|
if (this.state.linkCount > 0) {
|
|
648
|
-
const
|
|
649
|
-
|
|
744
|
+
const max = this.state.linkCount;
|
|
745
|
+
const length = Math.max(7, `[L${max}]: `.length);
|
|
746
|
+
for (let i = 1; i <= max; i++) {
|
|
650
747
|
const label = `[L${i}]: `;
|
|
651
748
|
const visitor = new FixedWidthTextVisitor(this.width - length);
|
|
652
749
|
visitor.text({
|