(body: CaptureRequest)
| 310 | } |
| 311 | |
| 312 | function createNoteContent(body: CaptureRequest): string { |
| 313 | const text = trimToValue(body.text) |
| 314 | const markdown = trimToValue(body.markdown) |
| 315 | const title |
| 316 | = trimToValue(body.sourceTitle) |
| 317 | ?? trimToValue(body.source?.title) |
| 318 | ?? trimToValue(body.pageTitle) |
| 319 | const url |
| 320 | = trimToValue(body.sourceUrl) |
| 321 | ?? trimToValue(body.source?.url) |
| 322 | ?? trimToValue(body.url) |
| 323 | const lines: string[] = [] |
| 324 | const sourceLines: string[] = [] |
| 325 | |
| 326 | if (markdown) { |
| 327 | lines.push(markdown, '') |
| 328 | } |
| 329 | else if (text) { |
| 330 | const language = getMarkdownFenceLanguage(body) |
| 331 | |
| 332 | if (language) { |
| 333 | const fence = getCodeFence(text) |
| 334 | |
| 335 | lines.push(`${fence}${language}`, text, fence, '') |
| 336 | } |
| 337 | else { |
| 338 | lines.push(text, '') |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if (url) { |
| 343 | if (title) { |
| 344 | sourceLines.push(`Source: ${title}`) |
| 345 | sourceLines.push(`URL: ${url}`) |
| 346 | } |
| 347 | else { |
| 348 | sourceLines.push(`Source: ${url}`) |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | const contextLabel = trimToValue(body.contextLabel) |
| 353 | if (contextLabel) { |
| 354 | sourceLines.push(`Context: ${contextLabel}`) |
| 355 | } |
| 356 | |
| 357 | sourceLines.push(`Captured: ${resolveCapturedAt(body)}`) |
| 358 | lines.push(...sourceLines.map(line => `> ${line}`)) |
| 359 | |
| 360 | return lines.join('\n') |
| 361 | } |
| 362 | |
| 363 | function getCaptureValidationMessage(body: CaptureRequest): string | null { |
| 364 | if (body.target === 'code' && !trimToValue(body.text)) { |
no test coverage detected