UNPKG

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