Skip to content

Open source CapCut alternative.

TypeScript

feat(site): note bodies as line-per-block Markdown [rebuild]

David Lec869455f630f
diff --git a/site/package-lock.json b/site/package-lock.json
index b330aa30..a50097aa 100644
--- a/site/package-lock.json
+++ b/site/package-lock.json
@@ -63,6 +63,12 @@
"@supabase/supabase-js": "^2.105.4",
"@tailwindcss/typography": "^0.5.19",
"@tanstack/react-query": "^5.101.0",
+ "@tiptap/core": "3.31.4",
+ "@tiptap/extension-list": "3.31.4",
+ "@tiptap/extensions": "3.31.4",
+ "@tiptap/pm": "3.31.4",
+ "@tiptap/react": "3.31.4",
+ "@tiptap/starter-kit": "3.31.4",
"@types/mdx": "^2.0.13",
"@typesafe-ai/sdk": "0.6.0",
"@vercel/functions": "^3.9.9",
@@ -6725,6 +6731,436 @@
"react": "^18 || ^19"
}
},
+ "node_modules/@tiptap/core": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/core/-/core-3.31.4.tgz",
+ "integrity": "sha512-cIVUQYBycighzsk6GbmCef8ZiEDVxoT5EuAe4xg2q9dNkDqCXVqI4YGr9aavCQEiAS4uHiRwqvcsPqJHipFDfg==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/pm": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-blockquote": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-blockquote/-/extension-blockquote-3.31.4.tgz",
+ "integrity": "sha512-FHnbvCIW0eDKgUUFjmvEB0ax9YUBW7/Unm+38qpuQROvU872yRqhnDtycKT9IKk46jNdjM4A4fAGUbge10CrAA==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4",
+ "@tiptap/pm": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-bold": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-bold/-/extension-bold-3.31.4.tgz",
+ "integrity": "sha512-QX1xoXvO0gz6uVsoLegumqQ4MJXL7lcUDQZ4J7la7LBqiIh4efrCmp2EXbhpr37M/YQL7w8q3g7H/VovSh7xIg==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-bubble-menu": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-bubble-menu/-/extension-bubble-menu-3.31.4.tgz",
+ "integrity": "sha512-Ml/yswuys+3QkOMajfXyAGlUKCxEbT3dMyF8vHwQ5mDk9MDm+dqp10It5CrDBkUT/KkVTa6AJI3kb0TXZJZiAA==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@floating-ui/dom": "^1.0.0"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4",
+ "@tiptap/pm": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-bullet-list": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-bullet-list/-/extension-bullet-list-3.31.4.tgz",
+ "integrity": "sha512-gHn1RDR4olCnmKpH+G9x+f8R+iKPNVdLlvbFkIpR/stjabZi7fB4Rr5GiHWsulbtxAjdQrNjnVeNdGM4rBxApw==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/extension-list": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-code": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-code/-/extension-code-3.31.4.tgz",
+ "integrity": "sha512-pzi8GNDs5J1DEoO1HNYiJ5WZpgOZzlc/2VIa77mMpEuD4hZxuK0BQzlF/O6Ps/O5P1lGJT4xS0Yowpzb9mD9RA==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-code-block": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-code-block/-/extension-code-block-3.31.4.tgz",
+ "integrity": "sha512-su/B/cfQ1HpiHl6JfJ6wa+RVEptiYsV4dCntE8XQNj2dUcII4y6w6PQbbswOoDrU79uXHsAvpy44215rghG4LA==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4",
+ "@tiptap/pm": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-document": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-document/-/extension-document-3.31.4.tgz",
+ "integrity": "sha512-vT20u62RWR+BLIyNJ54e24MPUY4zm8VF7tcgJnxQXi7BgVJWcNMtMWWDIkPJ4JNXwfoIznKh3jzYsaYmbCJgQQ==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-dropcursor": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-dropcursor/-/extension-dropcursor-3.31.4.tgz",
+ "integrity": "sha512-5TbCPCC4RL+QT1NYHjXCYDBHBtVqYOFvFEnk3v98lvXCM2PNL13ofXUfJPuykAVy1OdTAx4DlZOQAD9WKy/IdQ==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/extensions": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-floating-menu": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-floating-menu/-/extension-floating-menu-3.31.4.tgz",
+ "integrity": "sha512-pKzulkDmolpVt7IP9FSPsC5pKbXQ5pyeqkaAYr8cyOVW+KUObpPRIzAuXvEso8PCjWgwJ1f2qyishOEMw8MbfQ==",
+ "license": "MIT",
+ "optional": true,
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@floating-ui/dom": "^1.0.0",
+ "@tiptap/core": "3.31.4",
+ "@tiptap/pm": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-gapcursor": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-gapcursor/-/extension-gapcursor-3.31.4.tgz",
+ "integrity": "sha512-hBogUAepQH6IQUhaePhPWzQ1Oeu+yqlJVMKO06Eue5m36uRy1PZZAQ780pCGT0SC4R5MH2td1N8EUQ7bupQdDA==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/extensions": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-hard-break": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-hard-break/-/extension-hard-break-3.31.4.tgz",
+ "integrity": "sha512-oLNajLyUvRMg1qtzFgKGduygTlpaHFB9PU+M+pUWdA4sa1bRnxS2Y++Ao4lHYopJ7nxatLndrYoCIHkotqkPDQ==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-heading": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-heading/-/extension-heading-3.31.4.tgz",
+ "integrity": "sha512-KqlSeLathpdxCc3kVHBCA/RkHvb+V7u5vgiSEu1Cv3L70r7F19COMGODav/k1AGYBgEXKL6lM9cy8cloE5/28g==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-horizontal-rule": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-horizontal-rule/-/extension-horizontal-rule-3.31.4.tgz",
+ "integrity": "sha512-ws0Kh8kfHL7ESILSXj0HJAXs8G10ewlW1sedXKm8dm0op9L8il+xl8bEJVoqG/jMf77900Fc2CaQldcCGRpF1g==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4",
+ "@tiptap/pm": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-italic": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-italic/-/extension-italic-3.31.4.tgz",
+ "integrity": "sha512-pftTQBPYZocNDAj/u6OyDIp7YxmN0+N895cQPogJQ6qMHdLiRhzgawiEewJkniyN1w8k3Wx/Etp8pTKrxaOOBQ==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-link": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-link/-/extension-link-3.31.4.tgz",
+ "integrity": "sha512-LLxW3qfeL9gvDdMPVdxYFYZ0zZSjsoIDhOqjJ5U2UfaK3U2iwkKTBgV2qT+FWf3uUHmBRjBZ08q3dRPmWBAD5g==",
+ "license": "MIT",
+ "dependencies": {
+ "linkifyjs": "^4.3.3"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4",
+ "@tiptap/pm": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-list": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-list/-/extension-list-3.31.4.tgz",
+ "integrity": "sha512-Wd4YRYxOdf+TtF33/QsRo1RK1CecVxjYGjUBIKNGHAywfh8tghgV4YOUCiV1iJqYt2IBs+RWlIqTmdIPzBrd4A==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4",
+ "@tiptap/pm": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-list-item": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-list-item/-/extension-list-item-3.31.4.tgz",
+ "integrity": "sha512-ao8XAPvhOrtGFILs+fKtOM91omDSpUC8X19m44gbaq5xJDVpIMZ0rP+NAVUS72G7LskhcHa0bu/Pm022bUVjVw==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/extension-list": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-list-keymap": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-list-keymap/-/extension-list-keymap-3.31.4.tgz",
+ "integrity": "sha512-etdkl/YnYfwtALDxecJ+4WYgJAez1fn1vzzZqJklZBpgqiZtny3NxpvWS7/JhsltNG84Wo/oovpfJgVmzhddrw==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/extension-list": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-ordered-list": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-ordered-list/-/extension-ordered-list-3.31.4.tgz",
+ "integrity": "sha512-UNWyF+Dhm08znszIMnT8Y2kJ1lvtiCvUGs1aG7m9cPHxDa7VycWnOqdtXWkc+6xRLNiC0zgWCFWgLLHduV8pRQ==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/extension-list": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-paragraph": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-paragraph/-/extension-paragraph-3.31.4.tgz",
+ "integrity": "sha512-WZlBgw+XVKXerRlmEsoQ7x1PwSU+dh3X+b70+ViZsLebdfsmmYBIaNDrvIGwG9UQr5eLnddJnZplMSTI2YKs+g==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-strike": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-strike/-/extension-strike-3.31.4.tgz",
+ "integrity": "sha512-4MBr63TJIMqxCjE+gAPdlY1IdELgvbAP516K3Ntn/BkcpEbEoPMEYVz+XTxULyHQEuARDO6jsXPPxRXpA74jaw==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-text": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-text/-/extension-text-3.31.4.tgz",
+ "integrity": "sha512-WL2ZRpFksgQcXJN05/UQH09YCH9LlhdLrSEcviASvEH/aAfsKiJlDrouN8PET+YAWK/F5xFc5/Q1z0xj+I23jw==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extension-underline": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-underline/-/extension-underline-3.31.4.tgz",
+ "integrity": "sha512-0iFGPIqmqGkCrOFh1OPo7Dzv5s86dVN3bZaugsz0jK04otkb8bn04ZDKP2/6Wq+lcK0M9DfJ0QqfW5hC2nBZxQ==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/extensions": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/extensions/-/extensions-3.31.4.tgz",
+ "integrity": "sha512-nIupIne/sHpV2Kw1M4MOmr4+G454KI8BXM5+LWKOU2EpzfALZWVSy7koF9lVRna4Zp5Gv8hfg5Z8kvmrYQvhkw==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4",
+ "@tiptap/pm": "3.31.4"
+ }
+ },
+ "node_modules/@tiptap/pm": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/pm/-/pm-3.31.4.tgz",
+ "integrity": "sha512-x7dwth79cQp4QGae66/RJqMDJQv0+n7b7dD7cyFQBWqzPFLJxN/4paHY4qbWedZjNLhRyIOAD9a5q4AYM1zmPA==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-changeset": "^2.4.1",
+ "prosemirror-commands": "^1.7.1",
+ "prosemirror-dropcursor": "^1.8.2",
+ "prosemirror-gapcursor": "^1.4.1",
+ "prosemirror-history": "^1.5.0",
+ "prosemirror-inputrules": "^1.5.1",
+ "prosemirror-keymap": "^1.2.3",
+ "prosemirror-model": "^1.25.11",
+ "prosemirror-schema-list": "^1.5.1",
+ "prosemirror-state": "^1.4.4",
+ "prosemirror-tables": "^1.8.5",
+ "prosemirror-transform": "^1.12.0",
+ "prosemirror-view": "^1.42.3"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ }
+ },
+ "node_modules/@tiptap/react": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/react/-/react-3.31.4.tgz",
+ "integrity": "sha512-mBvvXgdPhMinT1NPfwHvFK1dFdMXHVWMSeNn0IPj7/zV0XBmOnASkEOwoIvl8NluKYEtpZBE1yA+6pN2enLa5g==",
+ "license": "MIT",
+ "dependencies": {
+ "@types/use-sync-external-store": "^0.0.6",
+ "fast-equals": "^5.3.3",
+ "use-sync-external-store": "^1.4.0"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "optionalDependencies": {
+ "@tiptap/extension-bubble-menu": "3.31.4",
+ "@tiptap/extension-floating-menu": "3.31.4"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "3.31.4",
+ "@tiptap/pm": "3.31.4",
+ "@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0",
+ "@types/react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0",
+ "react": "^17.0.0 || ^18.0.0 || ^19.0.0",
+ "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
+ }
+ },
+ "node_modules/@tiptap/starter-kit": {
+ "version": "3.31.4",
+ "resolved": "https://registry.npmjs.org/@tiptap/starter-kit/-/starter-kit-3.31.4.tgz",
+ "integrity": "sha512-u7HIJ9vK6kFe4S4J2CIcDLrhRZzoTMSyU0XxjQ6lUNF7pWW3rMi//pvi8RcsZmxGjyb8CpXAqYgNl7f9WyaUeA==",
+ "license": "MIT",
+ "dependencies": {
+ "@tiptap/core": "3.31.4",
+ "@tiptap/extension-blockquote": "3.31.4",
+ "@tiptap/extension-bold": "3.31.4",
+ "@tiptap/extension-bullet-list": "3.31.4",
+ "@tiptap/extension-code": "3.31.4",
+ "@tiptap/extension-code-block": "3.31.4",
+ "@tiptap/extension-document": "3.31.4",
+ "@tiptap/extension-dropcursor": "3.31.4",
+ "@tiptap/extension-gapcursor": "3.31.4",
+ "@tiptap/extension-hard-break": "3.31.4",
+ "@tiptap/extension-heading": "3.31.4",
+ "@tiptap/extension-horizontal-rule": "3.31.4",
+ "@tiptap/extension-italic": "3.31.4",
+ "@tiptap/extension-link": "3.31.4",
+ "@tiptap/extension-list": "3.31.4",
+ "@tiptap/extension-list-item": "3.31.4",
+ "@tiptap/extension-list-keymap": "3.31.4",
+ "@tiptap/extension-ordered-list": "3.31.4",
+ "@tiptap/extension-paragraph": "3.31.4",
+ "@tiptap/extension-strike": "3.31.4",
+ "@tiptap/extension-text": "3.31.4",
+ "@tiptap/extension-underline": "3.31.4",
+ "@tiptap/extensions": "3.31.4",
+ "@tiptap/pm": "3.31.4"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ }
+ },
"node_modules/@ts-morph/common": {
"version": "0.27.0",
"resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.27.0.tgz",
@@ -6936,7 +7372,6 @@
"version": "19.2.3",
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-19.2.3.tgz",
"integrity": "sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==",
- "devOptional": true,
"license": "MIT",
"peerDependencies": {
"@types/react": "^19.2.0"
@@ -6976,6 +7411,12 @@
"integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==",
"license": "MIT"
},
+ "node_modules/@types/use-sync-external-store": {
+ "version": "0.0.6",
+ "resolved": "https://registry.npmjs.org/@types/use-sync-external-store/-/use-sync-external-store-0.0.6.tgz",
+ "integrity": "sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg==",
+ "license": "MIT"
+ },
"node_modules/@types/validate-npm-package-name": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/@types/validate-npm-package-name/-/validate-npm-package-name-4.0.2.tgz",
@@ -11031,6 +11472,15 @@
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
"license": "MIT"
},
+ "node_modules/fast-equals": {
+ "version": "5.4.3",
+ "resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-5.4.3.tgz",
+ "integrity": "sha512-8unmvA0qrfpFWBYUate9BTGtQdKHWBYt+KdAIkag7Vvxe7wz8Q2nJg7fLMC0bJqe0bjP31kca7Ckaawrs4Istg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=6.0.0"
+ }
+ },
"node_modules/fast-glob": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz",
@@ -13552,6 +14002,12 @@
}
}
},
+ "node_modules/linkifyjs": {
+ "version": "4.3.3",
+ "resolved": "https://registry.npmjs.org/linkifyjs/-/linkifyjs-4.3.3.tgz",
+ "integrity": "sha512-P8aEP5U/D1/IlTY2OeYsErdwh9bGuLE30NcXtKEjgdHcahveQoQwM2yZNsioQHsWFz0P7KKudisbrzCgR0sDHg==",
+ "license": "MIT"
+ },
"node_modules/locate-path": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",
@@ -15674,6 +16130,12 @@
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
+ "node_modules/orderedmap": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/orderedmap/-/orderedmap-2.1.1.tgz",
+ "integrity": "sha512-TvAWxi0nDe1j/rtMcWcIj94+Ffe6n7zhow33h40SKxmsmozs6dz/e+EajymfoFcHd7sxNn8yHM8839uixMOV6g==",
+ "license": "MIT"
+ },
"node_modules/os-paths": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/os-paths/-/os-paths-4.4.0.tgz",
@@ -16548,6 +17010,145 @@
"url": "https://github.com/sponsors/wooorm"
}
},
+ "node_modules/prosemirror-changeset": {
+ "version": "2.4.4",
+ "resolved": "https://registry.npmjs.org/prosemirror-changeset/-/prosemirror-changeset-2.4.4.tgz",
+ "integrity": "sha512-Gyuz9jYdrAeA9I7AholyOes9KUmv/lEwsC5O9s5xF5VB3EgTPsXMGUxz4+H1B+wKVPdZbvRcg1Cp3x8qX+8ofA==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-transform": "^1.0.0"
+ }
+ },
+ "node_modules/prosemirror-commands": {
+ "version": "1.7.2",
+ "resolved": "https://registry.npmjs.org/prosemirror-commands/-/prosemirror-commands-1.7.2.tgz",
+ "integrity": "sha512-q6Q6szxqdu9Xd6EcdKsqXghu5nQdZTpB4Q9yd04WRc7/jt763e/rT60Owh0L1GYY+T46o5rD+9lEN36dZS43tw==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-model": "^1.0.0",
+ "prosemirror-state": "^1.0.0",
+ "prosemirror-transform": "^1.10.2"
+ }
+ },
+ "node_modules/prosemirror-dropcursor": {
+ "version": "1.8.4",
+ "resolved": "https://registry.npmjs.org/prosemirror-dropcursor/-/prosemirror-dropcursor-1.8.4.tgz",
+ "integrity": "sha512-VmKxhcA6a+h5oPSYmfF1ZNeQqPbyYaIxqZsKqeYCyTlPtrjUgNaHL3P8vVaO19oqAV0zuaM/axkowZHrB1P3Tg==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-state": "^1.0.0",
+ "prosemirror-transform": "^1.1.0",
+ "prosemirror-view": "^1.1.0"
+ }
+ },
+ "node_modules/prosemirror-gapcursor": {
+ "version": "1.4.1",
+ "resolved": "https://registry.npmjs.org/prosemirror-gapcursor/-/prosemirror-gapcursor-1.4.1.tgz",
+ "integrity": "sha512-pMdYaEnjNMSwl11yjEGtgTmLkR08m/Vl+Jj443167p9eB3HVQKhYCc4gmHVDsLPODfZfjr/MmirsdyZziXbQKw==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-keymap": "^1.0.0",
+ "prosemirror-model": "^1.0.0",
+ "prosemirror-state": "^1.0.0",
+ "prosemirror-view": "^1.0.0"
+ }
+ },
+ "node_modules/prosemirror-history": {
+ "version": "1.5.1",
+ "resolved": "https://registry.npmjs.org/prosemirror-history/-/prosemirror-history-1.5.1.tgz",
+ "integrity": "sha512-onlwnqKvgtFg6srZOmDOAhlAy1FIHQpOExORybX0S+DvJepE5tPALrB9iGet/2sqqqrelSnB10OoiOJqAvu2DA==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-state": "^1.2.2",
+ "prosemirror-transform": "^1.0.0",
+ "prosemirror-view": "^1.31.0",
+ "rope-sequence": "^1.3.0"
+ }
+ },
+ "node_modules/prosemirror-inputrules": {
+ "version": "1.5.1",
+ "resolved": "https://registry.npmjs.org/prosemirror-inputrules/-/prosemirror-inputrules-1.5.1.tgz",
+ "integrity": "sha512-7wj4uMjKaXWAQ1CDgxNzNtR9AlsuwzHfdFH1ygEHA2KHF2DOEaXl1CJfNPAKCg9qNEh4rum975QLaCiQPyY6Fw==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-state": "^1.0.0",
+ "prosemirror-transform": "^1.0.0"
+ }
+ },
+ "node_modules/prosemirror-keymap": {
+ "version": "1.2.3",
+ "resolved": "https://registry.npmjs.org/prosemirror-keymap/-/prosemirror-keymap-1.2.3.tgz",
+ "integrity": "sha512-4HucRlpiLd1IPQQXNqeo81BGtkY8Ai5smHhKW9jjPKRc2wQIxksg7Hl1tTI2IfT2B/LgX6bfYvXxEpJl7aKYKw==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-state": "^1.0.0",
+ "w3c-keyname": "^2.2.0"
+ }
+ },
+ "node_modules/prosemirror-model": {
+ "version": "1.25.12",
+ "resolved": "https://registry.npmjs.org/prosemirror-model/-/prosemirror-model-1.25.12.tgz",
+ "integrity": "sha512-Ue2gTmXMa7EhpLNhC7J+h4+ykD8ha12K6rrZFFKKJHBForfIStw5gJ6Zrf1mqqAa9NmpmEB4wp9bKmA4eUVjWg==",
+ "license": "MIT",
+ "dependencies": {
+ "orderedmap": "^2.0.0"
+ }
+ },
+ "node_modules/prosemirror-schema-list": {
+ "version": "1.5.1",
+ "resolved": "https://registry.npmjs.org/prosemirror-schema-list/-/prosemirror-schema-list-1.5.1.tgz",
+ "integrity": "sha512-927lFx/uwyQaGwJxLWCZRkjXG0p48KpMj6ueoYiu4JX05GGuGcgzAy62dfiV8eFZftgyBUvLx76RsMe20fJl+Q==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-model": "^1.0.0",
+ "prosemirror-state": "^1.0.0",
+ "prosemirror-transform": "^1.7.3"
+ }
+ },
+ "node_modules/prosemirror-state": {
+ "version": "1.4.4",
+ "resolved": "https://registry.npmjs.org/prosemirror-state/-/prosemirror-state-1.4.4.tgz",
+ "integrity": "sha512-6jiYHH2CIGbCfnxdHbXZ12gySFY/fz/ulZE333G6bPqIZ4F+TXo9ifiR86nAHpWnfoNjOb3o5ESi7J8Uz1jXHw==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-model": "^1.0.0",
+ "prosemirror-transform": "^1.0.0",
+ "prosemirror-view": "^1.27.0"
+ }
+ },
+ "node_modules/prosemirror-tables": {
+ "version": "1.8.5",
+ "resolved": "https://registry.npmjs.org/prosemirror-tables/-/prosemirror-tables-1.8.5.tgz",
+ "integrity": "sha512-V/0cDCsHKHe/tfWkeCmthNUcEp1IVO3p6vwN8XtwE9PZQLAZJigbw3QoraAdfJPir4NKJtNvOB8oYGKRl+t0Dw==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-keymap": "^1.2.3",
+ "prosemirror-model": "^1.25.4",
+ "prosemirror-state": "^1.4.4",
+ "prosemirror-transform": "^1.10.5",
+ "prosemirror-view": "^1.41.4"
+ }
+ },
+ "node_modules/prosemirror-transform": {
+ "version": "1.12.2",
+ "resolved": "https://registry.npmjs.org/prosemirror-transform/-/prosemirror-transform-1.12.2.tgz",
+ "integrity": "sha512-PE/aY0HEY4zczvmqrilgkUK/WautF0chvMqkmM/iN5/aPHvwrCWaQZjS6CIZp+K84YrvPFqrL+YArrfJX8xX7g==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-model": "^1.21.0"
+ }
+ },
+ "node_modules/prosemirror-view": {
+ "version": "1.42.6",
+ "resolved": "https://registry.npmjs.org/prosemirror-view/-/prosemirror-view-1.42.6.tgz",
+ "integrity": "sha512-3g25f6hKV2bBxo3puH3EcYWmmVNSH0iWmNsMVT7sugDSpA025jgpOLarcDWr39SdzPjYMaiYtRdNtXialPSjEQ==",
+ "license": "MIT",
+ "dependencies": {
+ "prosemirror-model": "^1.25.12",
+ "prosemirror-state": "^1.0.0",
+ "prosemirror-transform": "^1.1.0"
+ }
+ },
"node_modules/protobufjs": {
"version": "7.6.1",
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.6.1.tgz",
@@ -17314,6 +17915,12 @@
"node": ">=0.10.0"
}
},
+ "node_modules/rope-sequence": {
+ "version": "1.3.4",
+ "resolved": "https://registry.npmjs.org/rope-sequence/-/rope-sequence-1.3.4.tgz",
+ "integrity": "sha512-UT5EDe2cu2E/6O4igUr5PSFs23nvvukicWHx6GnOPlHAiiYbzNuCRQCuiUdHJQcqKalLKlrYJnjY0ySGsXNQXQ==",
+ "license": "MIT"
+ },
"node_modules/rou3": {
"version": "0.7.12",
"resolved": "https://registry.npmjs.org/rou3/-/rou3-0.7.12.tgz",
@@ -19364,6 +19971,12 @@
"url": "https://opencollective.com/unified"
}
},
+ "node_modules/w3c-keyname": {
+ "version": "2.2.8",
+ "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz",
+ "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==",
+ "license": "MIT"
+ },
"node_modules/web-streams-polyfill": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz",
diff --git a/site/package.json b/site/package.json
index 0fcba3f4..517abd8c 100644
--- a/site/package.json
+++ b/site/package.json
@@ -104,6 +104,12 @@
"@supabase/supabase-js": "^2.105.4",
"@tailwindcss/typography": "^0.5.19",
"@tanstack/react-query": "^5.101.0",
+ "@tiptap/core": "3.31.4",
+ "@tiptap/extension-list": "3.31.4",
+ "@tiptap/extensions": "3.31.4",
+ "@tiptap/pm": "3.31.4",
+ "@tiptap/react": "3.31.4",
+ "@tiptap/starter-kit": "3.31.4",
"@types/mdx": "^2.0.13",
"@typesafe-ai/sdk": "0.6.0",
"@vercel/functions": "^3.9.9",
diff --git a/site/src/cut/lib/noteDoc.ts b/site/src/cut/lib/noteDoc.ts
new file mode 100644
index 00000000..16acbfce
--- /dev/null
+++ b/site/src/cut/lib/noteDoc.ts
@@ -0,0 +1,142 @@
+import { Mark, mergeAttributes, type JSONContent } from "@tiptap/core";
+import {
+ NOTE_LIST_KINDS,
+ NOTE_TEXT_COLORS,
+ type NoteBlock,
+ type NoteBlockKind,
+ type NoteMarks,
+ type NoteRun,
+ type NoteTextColor,
+} from "@/cut/lib/noteMarkdown";
+
+/** The note body's blocks as the rich editor's document, and back. Lines nest
+ * into the editor's lists by their indent; the editor's lists flatten back to
+ * one line per item at its depth. */
+
+const LIST_NODE: Record<string, NoteBlockKind> = { bulletList: "bullet", orderedList: "number", taskList: "todo" };
+const LIST_TYPE: Record<string, string> = { bullet: "bulletList", number: "orderedList", todo: "taskList" };
+
+function runsOf(node: JSONContent | undefined): NoteRun[] {
+ return (node?.content ?? []).flatMap((n) => {
+ if (n.type !== "text" || !n.text) return [];
+ const marks: NoteMarks = {};
+ for (const m of n.marks ?? []) {
+ if (m.type === "bold" || m.type === "italic" || m.type === "underline" || m.type === "strike") marks[m.type] = true;
+ else if (m.type === "textColor" && m.attrs?.color) marks.color = m.attrs.color as NoteTextColor;
+ }
+ return [{ text: n.text, marks }];
+ });
+}
+
+/** The editor's document as the body's blocks: one block per line, lists
+ * flattened to their nesting depth. */
+export function blocksOf(doc: JSONContent): NoteBlock[] {
+ const out: NoteBlock[] = [];
+ const walk = (node: JSONContent, indent: number) => {
+ const kind = node.type ? LIST_NODE[node.type] : undefined;
+ if (kind) {
+ for (const item of node.content ?? []) {
+ for (const child of item.content ?? []) {
+ if (child.type && LIST_NODE[child.type]) walk(child, indent + 1);
+ else out.push({ kind, indent, ...(kind === "todo" ? { checked: !!item.attrs?.checked } : {}), runs: runsOf(child) });
+ }
+ }
+ } else if (node.type === "heading") {
+ out.push({ kind: "heading", level: node.attrs?.level ?? 1, indent: 0, runs: runsOf(node) });
+ } else if (node.type === "blockquote") {
+ for (const child of node.content ?? []) {
+ if (child.type === "paragraph") out.push({ kind: "quote", indent: 0, runs: runsOf(child) });
+ else walk(child, indent);
+ }
+ } else if (node.type === "paragraph") {
+ out.push({ kind: "paragraph", indent: 0, runs: runsOf(node) });
+ } else {
+ for (const child of node.content ?? []) walk(child, indent);
+ }
+ };
+ walk(doc, 0);
+ return out;
+}
+
+function inline(runs: NoteRun[]): JSONContent[] {
+ return runs
+ .filter((r) => r.text)
+ .map((r) => {
+ const marks = [
+ ...(["bold", "italic", "underline", "strike"] as const).filter((m) => r.marks[m]).map((type) => ({ type })),
+ ...(r.marks.color ? [{ type: "textColor", attrs: { color: r.marks.color } }] : []),
+ ];
+ return { type: "text", text: r.text, ...(marks.length ? { marks } : {}) };
+ });
+}
+const paragraph = (runs: NoteRun[]): JSONContent => {
+ const content = inline(runs);
+ return content.length ? { type: "paragraph", content } : { type: "paragraph" };
+};
+const listItem = (b: NoteBlock): JSONContent =>
+ b.kind === "todo"
+ ? { type: "taskItem", attrs: { checked: !!b.checked }, content: [paragraph(b.runs)] }
+ : { type: "listItem", content: [paragraph(b.runs)] };
+
+/** A run of list lines from `i`, at `indent` and deeper, as one list node
+ * with the deeper lines nested under the item above them. */
+function listFrom(blocks: NoteBlock[], i: number, indent: number): [JSONContent, number] {
+ const kind = blocks[i].kind;
+ const items: JSONContent[] = [];
+ while (i < blocks.length) {
+ const b = blocks[i];
+ if (!NOTE_LIST_KINDS.has(b.kind) || b.indent < indent) break;
+ if (b.indent === indent) {
+ if (b.kind !== kind) break;
+ items.push(listItem(b));
+ i++;
+ } else {
+ const [sub, next] = listFrom(blocks, i, b.indent);
+ if (items.length === 0) items.push(listItem({ ...b, runs: [] }));
+ items.at(-1)!.content!.push(sub);
+ i = next;
+ }
+ }
+ return [{ type: LIST_TYPE[kind], content: items }, i];
+}
+
+/** The body's blocks as the editor's document. */
+export function docOf(blocks: NoteBlock[]): JSONContent {
+ const content: JSONContent[] = [];
+ for (let i = 0; i < blocks.length; ) {
+ const b = blocks[i];
+ if (NOTE_LIST_KINDS.has(b.kind)) {
+ const [list, next] = listFrom(blocks, i, b.indent);
+ content.push(list);
+ i = next;
+ } else if (b.kind === "quote") {
+ const lines: JSONContent[] = [];
+ while (i < blocks.length && blocks[i].kind === "quote") lines.push(paragraph(blocks[i++].runs));
+ content.push({ type: "blockquote", content: lines });
+ } else {
+ content.push(b.kind === "heading" ? { type: "heading", attrs: { level: b.level ?? 1 }, content: inline(b.runs) } : paragraph(b.runs));
+ i++;
+ }
+ }
+ return { type: "doc", content };
+}
+
+/** A named text color. The name is what the body stores; the ink is the
+ * paper's. */
+export const TextColor = Mark.create({
+ name: "textColor",
+ addAttributes() {
+ return {
+ color: {
+ default: null,
+ parseHTML: (el) => el.getAttribute("data-color"),
+ renderHTML: (attrs) => ({
+ "data-color": attrs.color,
+ style: `color: ${NOTE_TEXT_COLORS.find((c) => c.id === attrs.color)?.paper ?? "inherit"}`,
+ }),
+ },
+ };
+ },
+ parseHTML: () => [{ tag: "span[data-color]" }],
+ renderHTML: ({ HTMLAttributes }) => ["span", mergeAttributes(HTMLAttributes), 0],
+});
diff --git a/site/src/cut/lib/noteMarkdown.test.ts b/site/src/cut/lib/noteMarkdown.test.ts
new file mode 100644
index 00000000..45e485ae
--- /dev/null
+++ b/site/src/cut/lib/noteMarkdown.test.ts
@@ -0,0 +1,96 @@
+import { describe, expect, test } from "bun:test";
+import { getSchema } from "@tiptap/core";
+import { Node } from "@tiptap/pm/model";
+import StarterKit from "@tiptap/starter-kit";
+import { TaskItem, TaskList } from "@tiptap/extension-list";
+import { noteBodyText, parseInline, parseNoteBody, serializeNoteBody } from "@/cut/lib/noteMarkdown";
+import { blocksOf, docOf, TextColor } from "@/cut/lib/noteDoc";
+
+const roundTrip = (body: string) => serializeNoteBody(parseNoteBody(body));
+
+describe("note markdown", () => {
+ test("a plain-text note reads one paragraph per line", () => {
+ const body = "Template\nfind a template to replicate\n\nCut Demo";
+ expect(parseNoteBody(body).map((b) => b.kind)).toEqual(["paragraph", "paragraph", "paragraph", "paragraph"]);
+ expect(roundTrip(body)).toBe(body);
+ });
+
+ test("block markers, nesting and to-dos round-trip", () => {
+ const body = [
+ "# Title",
+ "## Section",
+ "### Sub",
+ "- one",
+ " - nested",
+ " - deeper",
+ "1. first",
+ "2. second",
+ " - aside",
+ "3. third",
+ "- [ ] open",
+ "- [x] done",
+ "> quoted",
+ "",
+ "plain",
+ ].join("\n");
+ expect(roundTrip(body)).toBe(body);
+ const blocks = parseNoteBody(body);
+ expect(blocks[4]).toMatchObject({ kind: "bullet", indent: 1 });
+ expect(blocks[11]).toMatchObject({ kind: "todo", checked: true });
+ });
+
+ test("numbered runs renumber and other bullets read as bullets", () => {
+ expect(roundTrip("5. a\n9. b\ntext\n3. c")).toBe("1. a\n2. b\ntext\n1. c");
+ expect(roundTrip("* a\n• b")).toBe("- a\n- b");
+ });
+
+ test("inline marks parse and nest across seams", () => {
+ expect(parseInline("**bold *both* bold** <u>under</u> ~~gone~~ <span color=\"red\">red</span>")).toEqual([
+ { text: "bold ", marks: { bold: true } },
+ { text: "both", marks: { bold: true, italic: true } },
+ { text: " bold", marks: { bold: true } },
+ { text: " ", marks: {} },
+ { text: "under", marks: { underline: true } },
+ { text: " ", marks: {} },
+ { text: "gone", marks: { strike: true } },
+ { text: " ", marks: {} },
+ { text: "red", marks: { color: "red" } },
+ ]);
+ for (const body of ["**bold *both* bold**", "<span color=\"blue\"><u>**a**</u></span>b", "*a***b**"]) {
+ expect(serializeNoteBody(parseNoteBody(roundTrip(body)))).toBe(roundTrip(body));
+ expect(parseNoteBody(roundTrip(body))).toEqual(parseNoteBody(body));
+ }
+ });
+
+ test("stray delimiters and unknown tags stay literal", () => {
+ expect(noteBodyText("5 * 3 = 15")).toBe("5 * 3 = 15");
+ expect(noteBodyText("a <b>tag</b> and <span color=\"teal\">x</span>")).toBe("a <b>tag</b> and <span color=\"teal\">x</span>");
+ expect(noteBodyText("close </u> first")).toBe("close </u> first");
+ });
+
+ test("literal text that looks like markup is escaped and reads back", () => {
+ const blocks = [
+ { kind: "paragraph" as const, indent: 0, runs: [{ text: "- not a bullet *or* <u>tag</u> \\ ~~", marks: {} }] },
+ { kind: "paragraph" as const, indent: 0, runs: [{ text: "1. not a number", marks: {} }] },
+ { kind: "paragraph" as const, indent: 0, runs: [{ text: "# not a heading", marks: {} }] },
+ ];
+ expect(parseNoteBody(serializeNoteBody(blocks))).toEqual(blocks);
+ });
+});
+
+describe("note editor document", () => {
+ const schema = getSchema([StarterKit, TaskList, TaskItem.configure({ nested: true }), TextColor]);
+ test("bodies survive the trip through the editor's document", () => {
+ for (const body of [
+ "",
+ "plain\n\nlines",
+ "# Title\n- a\n - b\n 1. c\n 2. d\n- e\n- [ ] f\n - [x] g\n> q1\n> q2\ntext",
+ "**bold** *it* <u>u</u> ~~s~~ <span color=\"green\">**g**</span>",
+ ]) {
+ const doc = docOf(parseNoteBody(body));
+ // The document has to be valid for the editor's schema.
+ expect(() => Node.fromJSON(schema, doc).check()).not.toThrow();
+ expect(serializeNoteBody(blocksOf(doc))).toBe(body);
+ }
+ });
+});
diff --git a/site/src/cut/lib/noteMarkdown.ts b/site/src/cut/lib/noteMarkdown.ts
new file mode 100644
index 00000000..fec9a846
--- /dev/null
+++ b/site/src/cut/lib/noteMarkdown.ts
@@ -0,0 +1,269 @@
+/** The note body's format: a line-per-block Markdown that the web editor, the
+ * phone's editor, its teleprompter and the chat all read and write.
+ *
+ * Every line is one block, so a note written as plain text — one thought to a
+ * line — reads exactly as it was typed. A line opens with its block's marker:
+ *
+ * # Heading ## Smaller ### Smallest
+ * - Bullet 1. Numbered - [ ] To-do - [x] Done
+ * > Quote
+ *
+ * List lines nest two spaces per level. Inside a line, **bold**, *italic*,
+ * ~~strikethrough~~, <u>underline</u> and <span color="red">color</span> style
+ * the words, and a backslash keeps the next character literal. The phone's
+ * parser in DonkeyKit follows this file; a change here changes both. */
+
+/** Text colors, by name, with the ink each one takes on the note's paper and
+ * on the dark teleprompter. */
+export const NOTE_TEXT_COLORS = [
+ { id: "gray", name: "Gray", paper: "#787774", dark: "#9b9b9b" },
+ { id: "brown", name: "Brown", paper: "#9f6b53", dark: "#ba856f" },
+ { id: "orange", name: "Orange", paper: "#d9730d", dark: "#c77d48" },
+ { id: "yellow", name: "Yellow", paper: "#cb912f", dark: "#ca9849" },
+ { id: "green", name: "Green", paper: "#448361", dark: "#529e72" },
+ { id: "blue", name: "Blue", paper: "#337ea9", dark: "#5e87c9" },
+ { id: "purple", name: "Purple", paper: "#9065b0", dark: "#9d68d3" },
+ { id: "pink", name: "Pink", paper: "#c14c8a", dark: "#d15796" },
+ { id: "red", name: "Red", paper: "#d44c47", dark: "#df5452" },
+] as const;
+export type NoteTextColor = (typeof NOTE_TEXT_COLORS)[number]["id"];
+const COLOR_IDS = new Set<string>(NOTE_TEXT_COLORS.map((c) => c.id));
+
+export type NoteBlockKind = "paragraph" | "heading" | "bullet" | "number" | "todo" | "quote";
+export const NOTE_LIST_KINDS = new Set<NoteBlockKind>(["bullet", "number", "todo"]);
+/** How deep a list nests. */
+export const NOTE_INDENT_MAX = 5;
+
+export type NoteMarks = {
+ bold?: boolean;
+ italic?: boolean;
+ underline?: boolean;
+ strike?: boolean;
+ color?: NoteTextColor;
+};
+export type NoteRun = { text: string; marks: NoteMarks };
+export type NoteBlock = {
+ kind: NoteBlockKind;
+ /** Heading size, 1 to 3. */
+ level?: number;
+ /** List nesting, 0 at the margin. */
+ indent: number;
+ checked?: boolean;
+ runs: NoteRun[];
+};
+
+/** What the chat is taught about writing a note body, from the same lists. */
+export const NOTE_BODY_FORMAT =
+ "The body is one block per line: '# ', '## ', '### ' headings; '- ' bullets; '1. ' numbered items; '- [ ] ' and '- [x] ' to-dos; '> ' quotes; any other line is a paragraph. " +
+ "List lines nest two spaces per level. Inline: **bold**, *italic*, ~~strikethrough~~, <u>underline</u>, <span color=\"NAME\">colored text</span> with NAME one of " +
+ NOTE_TEXT_COLORS.map((c) => c.id).join(", ") +
+ ". A backslash keeps the next character literal.";
+
+const LIST_LINE = /^((?: {2})*)(?:([-*•]) \[( |x|X)\] |([-*•]) |(\d+)\. )/;
+const HEADING_LINE = /^(#{1,3}) /;
+
+/** Read a body into its blocks. */
+export function parseNoteBody(body: string): NoteBlock[] {
+ return body.split("\n").map(parseLine);
+}
+
+function parseLine(line: string): NoteBlock {
+ const list = LIST_LINE.exec(line);
+ if (list) {
+ const indent = Math.min(list[1].length / 2, NOTE_INDENT_MAX);
+ const rest = line.slice(list[0].length);
+ if (list[3] !== undefined) return { kind: "todo", indent, checked: list[3] !== " ", runs: parseInline(rest) };
+ if (list[4] !== undefined) return { kind: "bullet", indent, runs: parseInline(rest) };
+ return { kind: "number", indent, runs: parseInline(rest) };
+ }
+ const heading = HEADING_LINE.exec(line);
+ if (heading) return { kind: "heading", level: heading[1].length, indent: 0, runs: parseInline(line.slice(heading[0].length)) };
+ if (line.startsWith("> ")) return { kind: "quote", indent: 0, runs: parseInline(line.slice(2)) };
+ return { kind: "paragraph", indent: 0, runs: parseInline(line) };
+}
+
+type Token =
+ | { t: "text"; v: string }
+ | { t: "toggle"; mark: "bold" | "italic" | "strike"; v: string }
+ | { t: "open"; mark: "underline" | "color"; color?: NoteTextColor; v: string }
+ | { t: "close"; mark: "underline" | "color"; v: string };
+
+const TAG = /^<(u|\/u|\/span|span color="([a-z]+)")>/;
+
+function tokenize(s: string): Token[] {
+ const out: Token[] = [];
+ let text = "";
+ const flush = () => {
+ if (text) out.push({ t: "text", v: text });
+ text = "";
+ };
+ for (let i = 0; i < s.length; ) {
+ const c = s[i];
+ if (c === "\\" && i + 1 < s.length) {
+ text += s[i + 1];
+ i += 2;
+ } else if (s.startsWith("**", i)) {
+ flush();
+ out.push({ t: "toggle", mark: "bold", v: "**" });
+ i += 2;
+ } else if (c === "*") {
+ flush();
+ out.push({ t: "toggle", mark: "italic", v: "*" });
+ i += 1;
+ } else if (s.startsWith("~~", i)) {
+ flush();
+ out.push({ t: "toggle", mark: "strike", v: "~~" });
+ i += 2;
+ } else if (c === "<" && TAG.test(s.slice(i))) {
+ const m = TAG.exec(s.slice(i))!;
+ const tag = m[1];
+ if (tag.startsWith("span") && !COLOR_IDS.has(m[2])) {
+ text += m[0];
+ } else {
+ flush();
+ if (tag === "u") out.push({ t: "open", mark: "underline", v: m[0] });
+ else if (tag === "/u") out.push({ t: "close", mark: "underline", v: m[0] });
+ else if (tag === "/span") out.push({ t: "close", mark: "color", v: m[0] });
+ else out.push({ t: "open", mark: "color", color: m[2] as NoteTextColor, v: m[0] });
+ }
+ i += m[0].length;
+ } else {
+ text += c;
+ i += 1;
+ }
+ }
+ flush();
+ return out;
+}
+
+/** A line's styled runs. A delimiter with nothing to pair with — the lone
+ * star in "5 * 3" — is read as the text it is. */
+export function parseInline(s: string): NoteRun[] {
+ const tokens = tokenize(s);
+ // Toggles pair up in order; an odd one out is literal.
+ for (const mark of ["bold", "italic", "strike"] as const) {
+ const at = tokens.flatMap((tk, i) => (tk.t === "toggle" && tk.mark === mark ? [i] : []));
+ if (at.length % 2) tokens[at.at(-1)!] = { t: "text", v: tokens[at.at(-1)!].v };
+ }
+ // Tags pair open-to-close; a close with nothing open, or an open never
+ // closed, is literal.
+ for (const mark of ["underline", "color"] as const) {
+ const open: number[] = [];
+ tokens.forEach((tk, i) => {
+ if (tk.t === "open" && tk.mark === mark) open.push(i);
+ else if (tk.t === "close" && tk.mark === mark) {
+ if (open.length) open.pop();
+ else tokens[i] = { t: "text", v: tk.v };
+ }
+ });
+ for (const i of open) tokens[i] = { t: "text", v: tokens[i].v };
+ }
+ const runs: NoteRun[] = [];
+ const marks: NoteMarks = {};
+ const colors: NoteTextColor[] = [];
+ let underline = 0;
+ for (const tk of tokens) {
+ if (tk.t === "text") {
+ const now: NoteMarks = { ...marks };
+ if (underline > 0) now.underline = true;
+ if (colors.length) now.color = colors.at(-1);
+ const last = runs.at(-1);
+ if (last && sameMarks(last.marks, now)) last.text += tk.v;
+ else runs.push({ text: tk.v, marks: now });
+ } else if (tk.t === "toggle") {
+ if (marks[tk.mark]) delete marks[tk.mark];
+ else marks[tk.mark] = true;
+ } else if (tk.t === "open") {
+ if (tk.mark === "underline") underline++;
+ else colors.push(tk.color!);
+ } else if (tk.mark === "underline") underline--;
+ else colors.pop();
+ }
+ return runs;
+}
+
+const sameMarks = (a: NoteMarks, b: NoteMarks) =>
+ !!a.bold === !!b.bold &&
+ !!a.italic === !!b.italic &&
+ !!a.underline === !!b.underline &&
+ !!a.strike === !!b.strike &&
+ a.color === b.color;
+
+/** Write blocks back out as a body. Numbered items count up within their run
+ * at each level. */
+export function serializeNoteBody(blocks: NoteBlock[]): string {
+ const counts: number[] = [];
+ return blocks
+ .map((b) => {
+ const indent = NOTE_LIST_KINDS.has(b.kind) ? Math.min(Math.max(b.indent, 0), NOTE_INDENT_MAX) : 0;
+ // A numbered run restarts after anything that is not a deeper list line.
+ if (b.kind === "number") {
+ counts.length = indent + 1;
+ counts[indent] = (counts[indent] ?? 0) + 1;
+ } else {
+ counts.length = NOTE_LIST_KINDS.has(b.kind) ? indent + 1 : 0;
+ if (NOTE_LIST_KINDS.has(b.kind)) counts[indent] = 0;
+ }
+ const pad = " ".repeat(indent);
+ const text = serializeInline(b.runs);
+ switch (b.kind) {
+ case "heading":
+ return `${"#".repeat(Math.min(Math.max(b.level ?? 1, 1), 3))} ${text}`;
+ case "bullet":
+ return `${pad}- ${text}`;
+ case "number":
+ return `${pad}${counts[indent]}. ${text}`;
+ case "todo":
+ return `${pad}- [${b.checked ? "x" : " "}] ${text}`;
+ case "quote":
+ return `> ${text}`;
+ default:
+ // A paragraph that starts like a marker keeps its first character
+ // literal, so it reads back as the paragraph it is.
+ return LIST_LINE.test(text) || HEADING_LINE.test(text) || text.startsWith("> ")
+ ? `\\${text}`
+ : text;
+ }
+ })
+ .join("\n");
+}
+
+const escapeText = (s: string) => s.replace(/[\\*~<]/g, (c) => `\\${c}`);
+
+// Marks open outside-in in this order and close inside-out, so a run that
+// shares a mark with the one before it keeps it open across the seam.
+const ORDER = ["color", "underline", "strike", "bold", "italic"] as const;
+type Open = { mark: (typeof ORDER)[number]; color?: NoteTextColor };
+const openTag = (o: Open) =>
+ o.mark === "color" ? `<span color="${o.color}">` : o.mark === "underline" ? "<u>" : o.mark === "strike" ? "~~" : o.mark === "bold" ? "**" : "*";
+const closeTag = (o: Open) =>
+ o.mark === "color" ? "</span>" : o.mark === "underline" ? "</u>" : openTag(o);
+
+export function serializeInline(runs: NoteRun[]): string {
+ let out = "";
+ const stack: Open[] = [];
+ for (const run of runs) {
+ if (!run.text) continue;
+ const want = ORDER.flatMap((mark): Open[] =>
+ mark === "color" ? (run.marks.color ? [{ mark, color: run.marks.color }] : []) : run.marks[mark] ? [{ mark }] : [],
+ );
+ // Keep the longest prefix of what is open that the run still wears.
+ let keep = 0;
+ while (keep < stack.length && keep < want.length && stack[keep].mark === want[keep].mark && stack[keep].color === want[keep].color) keep++;
+ while (stack.length > keep) out += closeTag(stack.pop()!);
+ for (const o of want.slice(keep)) {
+ out += openTag(o);
+ stack.push(o);
+ }
+ out += escapeText(run.text);
+ }
+ while (stack.length) out += closeTag(stack.pop()!);
+ return out;
+}
+
+/** The words of a body with its markup taken out. */
+export function noteBodyText(body: string): string {
+ return parseNoteBody(body)
+ .map((b) => b.runs.map((r) => r.text).join(""))
+ .join("\n");
+}
diff --git a/site/src/cut/lib/noteReference.ts b/site/src/cut/lib/noteReference.ts
index 9c1bd359..c3127b2b 100644
--- a/site/src/cut/lib/noteReference.ts
+++ b/site/src/cut/lib/noteReference.ts
@@ -3,6 +3,7 @@ import { NOTE_LABELS_MAX } from "@/cut/lib/types";
import type { AssetRef } from "@/cut/lib/assetRef";
import type { CutNote } from "@/cut/lib/notes";
import { normalizeLink } from "@/cut/lib/link";
+import { NOTE_BODY_FORMAT } from "@/cut/lib/noteMarkdown";
export const noteIdSchema = z.string().regex(/^[\w-]{1,64}$/);
export const noteLocationSchema = z.object({
@@ -20,7 +21,7 @@ export const noteReadSchema = z.object({ id: noteIdSchema.optional(), link: z.st
export const noteSaveSchema = z.object({
id: noteIdSchema.optional().describe("Existing note id; omit to create a note"),
title: z.string().max(200).optional(),
- body: z.string().max(20_000).optional(),
+ body: z.string().max(20_000).optional().describe(NOTE_BODY_FORMAT),
colorIndex: z.number().int().optional(),
labelIds: z.array(noteIdSchema).max(NOTE_LABELS_MAX).optional(),
libraryLocation: noteLocationSchema.nullable().optional().describe(NOTE_LIBRARY_LOCATION_DESCRIPTION),