1 | "use strict";
|
2 |
|
3 |
|
4 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
5 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
6 | };
|
7 | Object.defineProperty(exports, "__esModule", { value: true });
|
8 | exports.CustomMarkdownEmitter = void 0;
|
9 | const colors_1 = __importDefault(require("colors"));
|
10 | const MarkdownEmitter_1 = require("./MarkdownEmitter");
|
11 | class CustomMarkdownEmitter extends MarkdownEmitter_1.MarkdownEmitter {
|
12 | constructor(apiModel) {
|
13 | super();
|
14 | this._apiModel = apiModel;
|
15 | }
|
16 | emit(stringBuilder, docNode, options) {
|
17 | return super.emit(stringBuilder, docNode, options);
|
18 | }
|
19 |
|
20 | writeNode(docNode, context, docNodeSiblings) {
|
21 | const writer = context.writer;
|
22 | switch (docNode.kind) {
|
23 | case "Heading" : {
|
24 | const docHeading = docNode;
|
25 | writer.ensureSkippedLine();
|
26 | let prefix;
|
27 | switch (docHeading.level) {
|
28 | case 1:
|
29 | prefix = '##';
|
30 | break;
|
31 | case 2:
|
32 | prefix = '###';
|
33 | break;
|
34 | case 3:
|
35 | prefix = '###';
|
36 | break;
|
37 | default:
|
38 | prefix = '####';
|
39 | }
|
40 | writer.writeLine(prefix + ' ' + this.getEscapedText(docHeading.title));
|
41 | writer.writeLine();
|
42 | break;
|
43 | }
|
44 | case "NoteBox" : {
|
45 | const docNoteBox = docNode;
|
46 | writer.ensureNewLine();
|
47 | writer.increaseIndent('> ');
|
48 | this.writeNode(docNoteBox.content, context, false);
|
49 | writer.ensureNewLine();
|
50 | writer.decreaseIndent();
|
51 | writer.writeLine();
|
52 | break;
|
53 | }
|
54 | case "Table" : {
|
55 | const docTable = docNode;
|
56 |
|
57 |
|
58 | writer.ensureSkippedLine();
|
59 | context.insideTable = true;
|
60 |
|
61 | let columnCount = 0;
|
62 | if (docTable.header) {
|
63 | columnCount = docTable.header.cells.length;
|
64 | }
|
65 | for (const row of docTable.rows) {
|
66 | if (row.cells.length > columnCount) {
|
67 | columnCount = row.cells.length;
|
68 | }
|
69 | }
|
70 |
|
71 | writer.write('| ');
|
72 | for (let i = 0; i < columnCount; ++i) {
|
73 | writer.write(' ');
|
74 | if (docTable.header) {
|
75 | const cell = docTable.header.cells[i];
|
76 | if (cell) {
|
77 | this.writeNode(cell.content, context, false);
|
78 | }
|
79 | }
|
80 | writer.write(' |');
|
81 | }
|
82 | writer.writeLine();
|
83 |
|
84 | writer.write('| ');
|
85 | for (let i = 0; i < columnCount; ++i) {
|
86 | writer.write(' --- |');
|
87 | }
|
88 | writer.writeLine();
|
89 | for (const row of docTable.rows) {
|
90 | writer.write('| ');
|
91 | for (const cell of row.cells) {
|
92 | writer.write(' ');
|
93 | this.writeNode(cell.content, context, false);
|
94 | writer.write(' |');
|
95 | }
|
96 | writer.writeLine();
|
97 | }
|
98 | writer.writeLine();
|
99 | context.insideTable = false;
|
100 | break;
|
101 | }
|
102 | case "EmphasisSpan" : {
|
103 | const docEmphasisSpan = docNode;
|
104 | const oldBold = context.boldRequested;
|
105 | const oldItalic = context.italicRequested;
|
106 | context.boldRequested = docEmphasisSpan.bold;
|
107 | context.italicRequested = docEmphasisSpan.italic;
|
108 | this.writeNodes(docEmphasisSpan.nodes, context);
|
109 | context.boldRequested = oldBold;
|
110 | context.italicRequested = oldItalic;
|
111 | break;
|
112 | }
|
113 | default:
|
114 | super.writeNode(docNode, context, docNodeSiblings);
|
115 | }
|
116 | }
|
117 |
|
118 | writeLinkTagWithCodeDestination(docLinkTag, context) {
|
119 | const options = context.options;
|
120 | const result = this._apiModel.resolveDeclarationReference(docLinkTag.codeDestination, options.contextApiItem);
|
121 | if (result.resolvedApiItem) {
|
122 | const filename = options.onGetFilenameForApiItem(result.resolvedApiItem);
|
123 | if (filename) {
|
124 | let linkText = docLinkTag.linkText || '';
|
125 | if (linkText.length === 0) {
|
126 |
|
127 | linkText = result.resolvedApiItem.getScopedNameWithinPackage();
|
128 | }
|
129 | if (linkText.length > 0) {
|
130 | const encodedLinkText = this.getEscapedText(linkText.replace(/\s+/g, ' '));
|
131 | context.writer.write('[');
|
132 | context.writer.write(encodedLinkText);
|
133 | context.writer.write(`](${filename})`);
|
134 | }
|
135 | else {
|
136 | console.log(colors_1.default.yellow('WARNING: Unable to determine link text'));
|
137 | }
|
138 | }
|
139 | }
|
140 | else if (result.errorMessage) {
|
141 | console.log(colors_1.default.yellow(`WARNING: Unable to resolve reference "${docLinkTag.codeDestination.emitAsTsdoc()}": ` +
|
142 | result.errorMessage));
|
143 | }
|
144 | }
|
145 | }
|
146 | exports.CustomMarkdownEmitter = CustomMarkdownEmitter;
|
147 |
|
\ | No newline at end of file |