UNPKG

6.77 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
8 };
9 return function (d, b) {
10 extendStatics(d, b);
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13 };
14})();
15Object.defineProperty(exports, "__esModule", { value: true });
16exports.DocFencedCode = void 0;
17var DocNode_1 = require("./DocNode");
18var DocExcerpt_1 = require("./DocExcerpt");
19/**
20 * Represents CommonMark-style code fence, i.e. a block of program code that
21 * starts and ends with a line comprised of three backticks. The opening delimiter
22 * can also specify a language for a syntax highlighter.
23 */
24var DocFencedCode = /** @class */ (function (_super) {
25 __extends(DocFencedCode, _super);
26 /**
27 * Don't call this directly. Instead use {@link TSDocParser}
28 * @internal
29 */
30 function DocFencedCode(parameters) {
31 var _this = _super.call(this, parameters) || this;
32 if (DocNode_1.DocNode.isParsedParameters(parameters)) {
33 _this._openingFenceExcerpt = new DocExcerpt_1.DocExcerpt({
34 configuration: _this.configuration,
35 excerptKind: DocExcerpt_1.ExcerptKind.FencedCode_OpeningFence,
36 content: parameters.openingFenceExcerpt
37 });
38 if (parameters.spacingAfterOpeningFenceExcerpt) {
39 _this._spacingAfterOpeningFenceExcerpt = new DocExcerpt_1.DocExcerpt({
40 configuration: _this.configuration,
41 excerptKind: DocExcerpt_1.ExcerptKind.Spacing,
42 content: parameters.spacingAfterOpeningFenceExcerpt
43 });
44 }
45 if (parameters.languageExcerpt) {
46 _this._languageExcerpt = new DocExcerpt_1.DocExcerpt({
47 configuration: _this.configuration,
48 excerptKind: DocExcerpt_1.ExcerptKind.FencedCode_Language,
49 content: parameters.languageExcerpt
50 });
51 }
52 if (parameters.spacingAfterLanguageExcerpt) {
53 _this._spacingAfterLanguageExcerpt = new DocExcerpt_1.DocExcerpt({
54 configuration: _this.configuration,
55 excerptKind: DocExcerpt_1.ExcerptKind.Spacing,
56 content: parameters.spacingAfterLanguageExcerpt
57 });
58 }
59 _this._codeExcerpt = new DocExcerpt_1.DocExcerpt({
60 configuration: _this.configuration,
61 excerptKind: DocExcerpt_1.ExcerptKind.FencedCode_Code,
62 content: parameters.codeExcerpt
63 });
64 if (parameters.spacingBeforeClosingFenceExcerpt) {
65 _this._spacingBeforeClosingFenceExcerpt = new DocExcerpt_1.DocExcerpt({
66 configuration: _this.configuration,
67 excerptKind: DocExcerpt_1.ExcerptKind.Spacing,
68 content: parameters.spacingBeforeClosingFenceExcerpt
69 });
70 }
71 _this._closingFenceExcerpt = new DocExcerpt_1.DocExcerpt({
72 configuration: _this.configuration,
73 excerptKind: DocExcerpt_1.ExcerptKind.FencedCode_ClosingFence,
74 content: parameters.closingFenceExcerpt
75 });
76 if (parameters.spacingAfterClosingFenceExcerpt) {
77 _this._spacingAfterClosingFenceExcerpt = new DocExcerpt_1.DocExcerpt({
78 configuration: _this.configuration,
79 excerptKind: DocExcerpt_1.ExcerptKind.Spacing,
80 content: parameters.spacingAfterClosingFenceExcerpt
81 });
82 }
83 }
84 else {
85 _this._code = parameters.code;
86 _this._language = parameters.language;
87 }
88 return _this;
89 }
90 Object.defineProperty(DocFencedCode.prototype, "kind", {
91 /** @override */
92 get: function () {
93 return DocNode_1.DocNodeKind.FencedCode;
94 },
95 enumerable: false,
96 configurable: true
97 });
98 Object.defineProperty(DocFencedCode.prototype, "language", {
99 /**
100 * A name that can optionally be included after the opening code fence delimiter,
101 * on the same line as the three backticks. This name indicates the programming language
102 * for the code, which a syntax highlighter may use to style the code block.
103 *
104 * @remarks
105 * The TSDoc standard requires that the language "ts" should be interpreted to mean TypeScript.
106 * Other languages names may be supported, but this is implementation dependent.
107 *
108 * CommonMark refers to this field as the "info string".
109 *
110 * @privateRemarks
111 * Examples of language strings supported by GitHub flavored markdown:
112 * https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml
113 */
114 get: function () {
115 if (this._language === undefined) {
116 if (this._languageExcerpt !== undefined) {
117 this._language = this._languageExcerpt.content.toString();
118 }
119 else {
120 this._language = '';
121 }
122 }
123 return this._language;
124 },
125 enumerable: false,
126 configurable: true
127 });
128 Object.defineProperty(DocFencedCode.prototype, "code", {
129 /**
130 * The text that should be rendered as code.
131 */
132 get: function () {
133 if (this._code === undefined) {
134 if (this._codeExcerpt !== undefined) {
135 this._code = this._codeExcerpt.content.toString();
136 }
137 }
138 return this._code;
139 },
140 enumerable: false,
141 configurable: true
142 });
143 /** @override */
144 DocFencedCode.prototype.onGetChildNodes = function () {
145 return [
146 this._openingFenceExcerpt,
147 this._spacingAfterOpeningFenceExcerpt,
148 this._languageExcerpt,
149 this._spacingAfterLanguageExcerpt,
150 this._codeExcerpt,
151 this._spacingBeforeClosingFenceExcerpt,
152 this._closingFenceExcerpt,
153 this._spacingAfterClosingFenceExcerpt
154 ];
155 };
156 return DocFencedCode;
157}(DocNode_1.DocNode));
158exports.DocFencedCode = DocFencedCode;
159//# sourceMappingURL=DocFencedCode.js.map
\No newline at end of file