feat: improve task note markdown editor
ci / gitleaks (push) Successful in 7s
ci / docker (push) Successful in 5m44s

This commit is contained in:
2026-09-11 17:37:53 +08:00
parent 9ec9d60633
commit 7caa78f318
5 changed files with 156 additions and 17 deletions
+14 -3
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { buildTaskRecurrencePayload, buildTaskRrule, classifyTaskForToday, defaultTaskDueAt, filterTasks, groupTaskTree, isSameTaskSortTier, moveItemWithinScope, parseTaskRecurrence, parseTaskRrule, renderMarkdown, toDateTimeLocal } from './task-utils'
import { applyMarkdownFormat, buildTaskRecurrencePayload, buildTaskRrule, classifyTaskForToday, defaultTaskDueAt, filterTasks, groupTaskTree, isSameTaskSortTier, moveItemWithinScope, parseTaskRecurrence, parseTaskRrule, renderMarkdown, toDateTimeLocal } from './task-utils'
type SearchTask = {
id: string
@@ -86,14 +86,25 @@ describe('task utilities', () => {
expect(buildTaskRecurrencePayload('none', { afterCompletionDays: '1' })).toEqual({})
})
it('renders safe basic markdown and strips unsafe html', () => {
const html = renderMarkdown('# Plan\n**bold** [link](https://example.com)\n<script>alert(1)</script>')
it('renders safe practical markdown and strips unsafe html', () => {
const html = renderMarkdown('# Plan\n> Note\n1. first\n- [x] done\n\n```js\nconst x = 1\n```\n**bold** [link](https://example.com)\n<script>alert(1)</script>')
expect(html).toContain('<h1>Plan</h1>')
expect(html).toContain('<blockquote>Note</blockquote>')
expect(html).toContain('<ol><li>first</li></ol>')
expect(html).toContain('type="checkbox" disabled checked')
expect(html).toContain('<pre><code class="language-js">const x = 1</code></pre>')
expect(html).toContain('<strong>bold</strong>')
expect(html).toContain('rel="noopener noreferrer"')
expect(html).not.toContain('<script>')
})
it('inserts markdown around selections and prefixes selected lines', () => {
expect(applyMarkdownFormat('hello', 0, 5, 'bold')).toEqual({ value: '**hello**', start: 2, end: 7 })
expect(applyMarkdownFormat('one\ntwo', 0, 7, 'bullet')).toEqual({ value: '- one\n- two', start: 2, end: 11 })
expect(applyMarkdownFormat('', 0, 0, 'link')).toEqual({ value: '[链接文字](https://)', start: 1, end: 5 })
expect(applyMarkdownFormat('work', 0, 4, 'task')).toEqual({ value: '- [ ] work', start: 6, end: 10 })
})
it('filters titles, descriptions, and list names', () => {
const searchable: SearchTask[] = [
...tasks,