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4CAAgB","sourcesContent":["import {\r\n DocNode,\r\n DocNodeKind,\r\n DocPlainText,\r\n DocFencedCode,\r\n DocCodeSpan,\r\n DocLinkTag,\r\n DocEscapedText\r\n} from '../nodes';\r\n\r\n/**\r\n * Renders a DocNode tree as plain text, without any rich text formatting or markup.\r\n */\r\nexport class PlainTextEmitter {\r\n /**\r\n * Returns true if the specified node contains any text content.\r\n *\r\n * @remarks\r\n * A documentation tool can use this test to report warnings when a developer neglected to write a code comment\r\n * for a declaration.\r\n *\r\n * @param node - this node and all its children will be considered\r\n * @param requiredCharacters - The test returns true if at least this many non-spacing characters are found.\r\n * The default value is 1.\r\n */\r\n public static hasAnyTextContent(node: DocNode, requiredCharacters?: number): boolean;\r\n\r\n /**\r\n * Returns true if the specified collection of nodes contains any text content.\r\n *\r\n * @remarks\r\n * A documentation tool can use this test to report warnings when a developer neglected to write a code comment\r\n * for a declaration.\r\n *\r\n * @param nodes - the collection of nodes to be tested\r\n * @param requiredCharacters - The test returns true if at least this many non-spacing characters are found.\r\n * The default value is 1.\r\n */\r\n public static hasAnyTextContent(nodes: ReadonlyArray<DocNode>, requiredCharacters?: number): boolean;\r\n public static hasAnyTextContent(\r\n nodeOrNodes: DocNode | ReadonlyArray<DocNode>,\r\n requiredCharacters?: number\r\n ): boolean {\r\n if (requiredCharacters === undefined || requiredCharacters < 1) {\r\n requiredCharacters = 1; // default\r\n }\r\n\r\n let nodes: ReadonlyArray<DocNode>;\r\n if (nodeOrNodes instanceof DocNode) {\r\n nodes = [nodeOrNodes];\r\n } else {\r\n nodes = nodeOrNodes;\r\n }\r\n\r\n const foundCharacters: number = PlainTextEmitter._scanTextContent(nodes, requiredCharacters, 0);\r\n\r\n return foundCharacters >= requiredCharacters;\r\n }\r\n\r\n private static _scanTextContent(\r\n nodes: ReadonlyArray<DocNode>,\r\n requiredCharacters: number,\r\n foundCharacters: number\r\n ): number {\r\n for (const node of nodes) {\r\n switch (node.kind) {\r\n case DocNodeKind.FencedCode:\r\n const docFencedCode: DocFencedCode = node as DocFencedCode;\r\n foundCharacters += PlainTextEmitter._countNonSpaceCharacters(docFencedCode.code);\r\n break;\r\n\r\n case DocNodeKind.CodeSpan:\r\n const docCodeSpan: DocCodeSpan = node as DocCodeSpan;\r\n foundCharacters += PlainTextEmitter._countNonSpaceCharacters(docCodeSpan.code);\r\n break;\r\n case DocNodeKind.EscapedText:\r\n const docEscapedText: DocEscapedText = node as DocEscapedText;\r\n foundCharacters += PlainTextEmitter._countNonSpaceCharacters(docEscapedText.decodedText);\r\n break;\r\n\r\n case DocNodeKind.LinkTag:\r\n const docLinkTag: DocLinkTag = node as DocLinkTag;\r\n foundCharacters += PlainTextEmitter._countNonSpaceCharacters(docLinkTag.linkText || '');\r\n break;\r\n\r\n case DocNodeKind.PlainText:\r\n const docPlainText: DocPlainText = node as DocPlainText;\r\n foundCharacters += PlainTextEmitter._countNonSpaceCharacters(docPlainText.text);\r\n break;\r\n }\r\n\r\n if (foundCharacters >= requiredCharacters) {\r\n break;\r\n }\r\n\r\n foundCharacters += PlainTextEmitter._scanTextContent(\r\n node.getChildNodes(),\r\n requiredCharacters,\r\n foundCharacters\r\n );\r\n\r\n if (foundCharacters >= requiredCharacters) {\r\n break;\r\n }\r\n }\r\n\r\n return foundCharacters;\r\n }\r\n\r\n private static _countNonSpaceCharacters(s: string): number {\r\n let count: number = 0;\r\n const length: number = s.length;\r\n let i: number = 0;\r\n while (i < length) {\r\n switch (s.charCodeAt(i)) {\r\n case 32: // space\r\n case 9: // tab\r\n case 13: // CR\r\n case 10: // LF\r\n break;\r\n default:\r\n ++count;\r\n }\r\n ++i;\r\n }\r\n return count;\r\n }\r\n}\r\n"]}
\No newline at end of file