* Parse a line of text to extract Tasks plugin format data.
(line: string)
| 110 | * Parse a line of text to extract Tasks plugin format data. |
| 111 | */ |
| 112 | static parseTaskLine(line: string): TaskLineInfo { |
| 113 | if (typeof line !== "string") { |
| 114 | return { |
| 115 | isTaskLine: false, |
| 116 | originalText: "", |
| 117 | error: "Invalid input: line must be a string", |
| 118 | }; |
| 119 | } |
| 120 | |
| 121 | if (line.length > 2000) { |
| 122 | return { |
| 123 | isTaskLine: false, |
| 124 | originalText: line, |
| 125 | error: "Line too long to process safely", |
| 126 | }; |
| 127 | } |
| 128 | |
| 129 | const trimmedLine = this.stripBlockquoteMarkers(line); |
| 130 | const checkboxMatch = trimmedLine.match(this.CHECKBOX_PATTERN); |
| 131 | if (!checkboxMatch) { |
| 132 | return { |
| 133 | isTaskLine: false, |
| 134 | originalText: line, |
| 135 | }; |
| 136 | } |
| 137 | |
| 138 | try { |
| 139 | const [, , checkState, , taskContent] = checkboxMatch; |
| 140 | if (typeof checkState !== "string" || typeof taskContent !== "string") { |
| 141 | return { |
| 142 | isTaskLine: true, |
| 143 | originalText: line, |
| 144 | error: "Invalid checkbox format", |
| 145 | }; |
| 146 | } |
| 147 | |
| 148 | const isCompleted = checkState.toLowerCase() === "x"; |
| 149 | const parsedData = this.parseTaskContent(taskContent, isCompleted); |
| 150 | |
| 151 | if (!parsedData || !parsedData.title || parsedData.title.trim().length === 0) { |
| 152 | return { |
| 153 | isTaskLine: true, |
| 154 | originalText: line, |
| 155 | error: "Task must have a title", |
| 156 | }; |
| 157 | } |
| 158 | |
| 159 | return { |
| 160 | isTaskLine: true, |
| 161 | originalText: line, |
| 162 | parsedData, |
| 163 | }; |
| 164 | } catch (error) { |
| 165 | return { |
| 166 | isTaskLine: true, |
| 167 | originalText: line, |
| 168 | error: `Failed to parse task: ${error instanceof Error ? error.message : "Unknown error"}`, |
| 169 | }; |
no test coverage detected