UNPKG

1.85 kBJavaScriptView Raw
1import { TrimSpacesTransform } from './TrimSpacesTransform';
2/**
3 * Helper functions that transform DocNode trees.
4 */
5var DocNodeTransforms = /** @class */ (function () {
6 function DocNodeTransforms() {
7 }
8 /**
9 * trimSpacesInParagraphNodes() collapses extra spacing characters from plain text nodes.
10 *
11 * @remarks
12 * This is useful when emitting HTML, where any number of spaces are equivalent
13 * to a single space. It's also useful when emitting Markdown, where spaces
14 * can be misinterpreted as an indented code block.
15 *
16 * For example, we might transform this:
17 *
18 * ```
19 * nodes: [
20 * { kind: PlainText, text: " Here are some " },
21 * { kind: SoftBreak }
22 * { kind: PlainText, text: " words" },
23 * { kind: SoftBreak }
24 * { kind: InlineTag, text: "{\@inheritDoc}" },
25 * { kind: PlainText, text: "to process." },
26 * { kind: PlainText, text: " " },
27 * { kind: PlainText, text: " " }
28 * ]
29 * ```
30 *
31 * ...to this:
32 *
33 * ```
34 * nodes: [
35 * { kind: PlainText, text: "Here are some " },
36 * { kind: PlainText, text: "words " },
37 * { kind: InlineTag, text: "{\@inheritDoc}" },
38 * { kind: PlainText, text: "to process." }
39 * ]
40 * ```
41 *
42 * Note that in this example, `"words "` is not merged with the preceding node because
43 * its DocPlainText.excerpt cannot span multiple lines.
44 *
45 * @param docParagraph - a DocParagraph containing nodes to be transformed
46 * @returns The transformed child nodes.
47 */
48 DocNodeTransforms.trimSpacesInParagraph = function (docParagraph) {
49 return TrimSpacesTransform.transform(docParagraph);
50 };
51 return DocNodeTransforms;
52}());
53export { DocNodeTransforms };
54//# sourceMappingURL=DocNodeTransforms.js.map
\No newline at end of file