text-doc-ir 0.3.1 → 0.4.0

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/dist/index.js CHANGED
@@ -2,7 +2,7 @@ var w = Object.defineProperty;
2
2
  var B = (y, m, t) => m in y ? w(y, m, { enumerable: !0, configurable: !0, writable: !0, value: t }) : y[m] = t;
3
3
  var C = (y, m, t) => B(y, typeof m != "symbol" ? m + "" : m, t);
4
4
  import { NodeVisitor as b } from "document-ir";
5
- function d(y, m, t) {
5
+ function x(y, m, t) {
6
6
  const e = [];
7
7
  if (m == 0)
8
8
  return "";
@@ -396,7 +396,7 @@ class c extends b {
396
396
  g.setState({ ...this.state, numericDepth: 0 }), g.visit({ type: "array", content: p.content });
397
397
  const k = [...g.getLines()];
398
398
  o.push(k);
399
- const L = Math.max(...k.map((x) => x.length), 0);
399
+ const L = Math.max(...k.map((d) => d.length), 0);
400
400
  n[r] = Math.max(n[r], L), g.restoreState(this);
401
401
  }
402
402
  e.push(o), i.push(l);
@@ -450,6 +450,32 @@ class c extends b {
450
450
  this.pushEndOfLineIfAnyContent(), this.lines[Math.max(0, this.lines.length - 1)] = "| " + s;
451
451
  e.restoreState(this), this.pushBlockContentEnd();
452
452
  }
453
+ admonition(t) {
454
+ const e = t.admonitionType;
455
+ if (t.inline) {
456
+ if (t.title) {
457
+ const n = new c(this.width);
458
+ n.setState({ ...this.state, numericDepth: 0 }), n.visit({ type: "array", content: t.title }), n.restoreState(this);
459
+ const i = n.getLines().join(" ");
460
+ this.pushText("[" + i + ": ");
461
+ } else
462
+ this.pushText("[" + e + ": ");
463
+ this.chooseChildren(t.content), this.pushText("]");
464
+ return;
465
+ }
466
+ if (this.pushBlockContentBegin(), t.title) {
467
+ const n = new c(this.width - 4);
468
+ n.setState({ ...this.state, numericDepth: 0 }), n.visit({ type: "array", content: t.title }), n.restoreState(this);
469
+ const i = n.getLines().join(" ");
470
+ this.pushText("!!! " + e + ' "' + i + '"');
471
+ } else
472
+ this.pushText("!!! " + e);
473
+ const s = new c(this.width - 4);
474
+ s.setState({ ...this.state, numericDepth: 0 }), s.visit({ type: "array", content: t.content });
475
+ for (const n of s.getLines())
476
+ this.pushEndOfLineIfAnyContent(), this.lines[Math.max(0, this.lines.length - 1)] = " " + n;
477
+ s.restoreState(this), this.pushBlockContentEnd();
478
+ }
453
479
  highTechAlert(t) {
454
480
  this.pushBlockContentBegin(), this.pushText("/"), this.pushText("-".repeat(this.width - 2)), this.pushText("\\");
455
481
  const e = new c(this.width - 4);
@@ -484,17 +510,18 @@ class c extends b {
484
510
  quote(t) {
485
511
  this.pushBlockContentBegin();
486
512
  const e = new c(this.width - 2);
487
- e.setState({ ...this.state, numericDepth: 0 }), e.visit({
513
+ e.setState({ ...this.state, numericDepth: 0 });
514
+ const s = t.author ? [{ type: "text", text: t.author }, { type: "break" }, { type: "text", text: t.name }, { type: "break" }] : [{ type: "text", text: t.name }, { type: "break" }];
515
+ e.visit({
488
516
  type: "array",
489
517
  content: [
490
- { type: "text", text: t.name },
491
- { type: "break" },
518
+ ...s,
492
519
  { type: "break" },
493
520
  ...t.content
494
521
  ]
495
522
  });
496
- for (const s of e.getLines())
497
- this.pushEndOfLineIfAnyContent(), this.lines[Math.max(0, this.lines.length - 1)] = "> " + s;
523
+ for (const n of e.getLines())
524
+ this.pushEndOfLineIfAnyContent(), this.lines[Math.max(0, this.lines.length - 1)] = "> " + n;
498
525
  e.restoreState(this), this.pushBlockContentEnd();
499
526
  }
500
527
  bubble(t) {
@@ -712,7 +739,7 @@ class c extends b {
712
739
  }
713
740
  counterToDepth(t) {
714
741
  const e = this.state.numericDepth % 3;
715
- return e == 0 ? `${t}` : e == 1 ? d(S, t) : d(T, t);
742
+ return e == 0 ? `${t}` : e == 1 ? x(S, t) : x(T, t);
716
743
  }
717
744
  pushBlockContentBegin() {
718
745
  this.pushLazyLines(), this.lines.length > 0 && this.pushEndOfLineIfAnyContent();
package/dist/main.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AccordionGroupNode, AccordionTabNode, BadgeNode, BlockQuoteNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeBlockNode, CodeGroupNode, CodeNode, ColumnsNode, DateNode, DateTimeNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FootnoteNode, FootnoteDisplayNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, PillNode, QuoteNode, RedactedNode, RegionNode, SecretNode, SocialNode, StandardNode, StickerNode, StrikeThroughNode, SubTextNode, SuperTextNode, TableNode, TableOfContentsNode, TextNode, TimeNode, TimeRangeNode, VideoNode, WarningNode, NodeVisitor } from 'document-ir';
1
+ import { AccordionGroupNode, AccordionTabNode, AdmonitionNode, BadgeNode, BlockQuoteNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeBlockNode, CodeGroupNode, CodeNode, ColumnsNode, DateNode, DateTimeNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FootnoteNode, FootnoteDisplayNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, PillNode, QuoteNode, RedactedNode, RegionNode, SecretNode, SocialNode, StandardNode, StickerNode, StrikeThroughNode, SubTextNode, SuperTextNode, TableNode, TableOfContentsNode, TextNode, TimeNode, TimeRangeNode, VideoNode, WarningNode, NodeVisitor } from 'document-ir';
2
2
  export declare class FixedWidthTextVisitor extends NodeVisitor {
3
3
  private width;
4
4
  private lines;
@@ -56,6 +56,7 @@ export declare class FixedWidthTextVisitor extends NodeVisitor {
56
56
  protected note(node: NoteNode): void;
57
57
  protected center(node: CenterNode): void;
58
58
  protected warning(node: WarningNode): void;
59
+ protected admonition(node: AdmonitionNode): void;
59
60
  protected highTechAlert(node: HighTechAlertNode): void;
60
61
  protected blockQuote(node: BlockQuoteNode): void;
61
62
  protected quote(node: QuoteNode): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "text-doc-ir",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Transforms a document intermediate representation into plain text with formatting",
@@ -44,7 +44,7 @@
44
44
  "to-text": "bun src/to-text.ts"
45
45
  },
46
46
  "dependencies": {
47
- "document-ir": "0.5.0"
47
+ "document-ir": "0.6.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/bun": "latest",