(line)
| 81 | } |
| 82 | |
| 83 | parseLine(line) { |
| 84 | // Strip trailing whitespace |
| 85 | line = line.trimRight(); |
| 86 | |
| 87 | // Detect block separator |
| 88 | if (/^\s*(=|"){3,}\s*$/.test(line)) { |
| 89 | this.flushParagraph(); |
| 90 | this.resetBlock(!this.blockIsLicenseBlock); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | // Strip comments around block |
| 95 | if (this.blockIsLicenseBlock) { |
| 96 | this.blockHasCStyleComment ||= /^\s*(\/\*)/.test(line); |
| 97 | if (this.blockHasCStyleComment) { |
| 98 | const prev = line; |
| 99 | line = line.replace(/^(\s*?)(?:\s?\*\/|\/\*\s|\s\*\s?)/, '$1'); |
| 100 | if (prev === line) |
| 101 | line = line.replace(/^\s{2}/, ''); |
| 102 | if (/\*\//.test(prev)) |
| 103 | this.blockHasCStyleComment = false; |
| 104 | } else { |
| 105 | // Strip C++ and perl style comments. |
| 106 | line = line.replace(/^(\s*)(?:\/\/\s?|#\s?)/, '$1'); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // Detect blank line (paragraph separator) |
| 111 | if (!/\S/.test(line)) { |
| 112 | this.flushParagraph(); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | // Detect separator "lines" within a block. These mark a paragraph break |
| 117 | // and are stripped from the output. |
| 118 | if (/^\s*[=*-]{5,}\s*$/.test(line)) { |
| 119 | this.flushParagraph(); |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | // Find out indentation level and the start of a lied or numbered list; |
| 124 | const result = /^(\s*)(\d+\.|\*|-)?\s*/.exec(line); |
| 125 | assert.ok(result); |
| 126 | // The number of characters that will be stripped from the beginning of |
| 127 | // the line. |
| 128 | const lineStripLength = result[0].length; |
| 129 | // The indentation size that will be used to detect indentation jumps. |
| 130 | // Fudge by 1 space. |
| 131 | const lineIndent = Math.floor(lineStripLength / 2) * 2; |
| 132 | // The indentation level that will be exported |
| 133 | const level = Math.floor(result[1].length / 2); |
| 134 | // The list indicator that precedes the actual content, if any. |
| 135 | const lineLi = result[2]; |
| 136 | |
| 137 | // Flush the paragraph when there is a li or an indentation jump |
| 138 | if (lineLi || (lineIndent !== this.paragraphLineIndent && |
| 139 | this.paragraphLineIndent !== -1)) { |
| 140 | this.flushParagraph(); |
no test coverage detected