@jant/core 0.6.14 → 0.6.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/commands/import-site.js +81 -13
- package/bin/commands/migrate.js +55 -0
- package/bin/commands/posts/rebuild-html.js +184 -0
- package/bin/commands/site/snapshot/import.js +14 -10
- package/bin/lib/d1-query.js +23 -5
- package/bin/lib/migration-runner.js +29 -7
- package/bin/lib/node-database.js +32 -0
- package/bin/lib/site-snapshot.js +347 -46
- package/bin/lib/sql-export.js +1 -1
- package/bin/lib/thread-collection-migration.js +326 -0
- package/dist/app-BxCOR3Uc.js +6 -0
- package/dist/{app-2i7-WQHg.js → app-C-oi_t8W.js} +7408 -6343
- package/dist/client/.vite/manifest.json +3 -3
- package/dist/client/_assets/client-B_eGKN5p.css +2 -0
- package/dist/client/_assets/{client-BvID5ucz.js → client-DxY5BFe8.js} +58 -37
- package/dist/client/_assets/client-auth-CakPESv9.js +5533 -0
- package/dist/{export-DWn149b7.js → export-CsFx6F_M.js} +1259 -125
- package/dist/{github-sync-Ckk0sJxK.js → github-sync-Cq1pzzOI.js} +1 -1
- package/dist/{github-sync-C0zyF6XS.js → github-sync-ppWXN3jb.js} +2 -2
- package/dist/index.js +3 -3
- package/dist/node.js +5 -5
- package/package.json +11 -10
- package/src/__tests__/bin/posts-rebuild-html.test.ts +137 -0
- package/src/__tests__/dev-navigation-defaults.test.ts +22 -0
- package/src/__tests__/export-hugo-build.test.ts +63 -4
- package/src/__tests__/export-import-roundtrip.test.ts +6 -4
- package/src/__tests__/export-service.test.ts +142 -9
- package/src/__tests__/helpers/app.ts +3 -0
- package/src/__tests__/helpers/export-fixtures.ts +2 -0
- package/src/__tests__/import-site-command.test.ts +65 -0
- package/src/__tests__/vite-config.test.ts +45 -0
- package/src/app.tsx +16 -3
- package/src/client/__tests__/collection-created-notice.test.ts +36 -0
- package/src/client/__tests__/collection-form-bridge.test.ts +10 -1
- package/src/client/__tests__/collection-page-actions.test.ts +71 -2
- package/src/client/__tests__/compose-bridge.test.ts +64 -0
- package/src/client/__tests__/feed-video-player.test.ts +16 -1
- package/src/client/__tests__/footnote-rail.test.ts +472 -0
- package/src/client/__tests__/hydrate-partial.test.ts +3 -0
- package/src/client/__tests__/toast.test.ts +18 -1
- package/src/client/collection-created-notice.ts +66 -0
- package/src/client/collection-form-bridge.ts +17 -0
- package/src/client/collection-navigation.ts +44 -0
- package/src/client/collection-page-actions.ts +57 -1
- package/src/client/components/__tests__/jant-collection-directory.test.ts +155 -6
- package/src/client/components/__tests__/jant-compose-dialog.test.ts +370 -5
- package/src/client/components/__tests__/jant-compose-editor.test.ts +97 -0
- package/src/client/components/__tests__/jant-compose-fullscreen.test.ts +104 -0
- package/src/client/components/__tests__/jant-config-editor.test.ts +405 -0
- package/src/client/components/__tests__/jant-media-lightbox.test.ts +121 -0
- package/src/client/components/__tests__/jant-nav-manager.test.ts +538 -2
- package/src/client/components/__tests__/jant-post-form.test.ts +2 -2
- package/src/client/components/__tests__/jant-post-menu.test.ts +47 -5
- package/src/client/components/__tests__/jant-settings-avatar.test.ts +2 -2
- package/src/client/components/__tests__/jant-settings-general.test.ts +3 -3
- package/src/client/components/collection-manager-types.ts +9 -3
- package/src/client/components/compose-types.ts +8 -0
- package/src/client/components/jant-collection-directory.ts +165 -30
- package/src/client/components/jant-command-palette.ts +2 -1
- package/src/client/components/jant-compose-dialog.ts +85 -21
- package/src/client/components/jant-compose-editor.ts +13 -7
- package/src/client/components/jant-compose-fullscreen.ts +24 -4
- package/src/client/components/jant-config-editor.ts +722 -0
- package/src/client/components/jant-media-lightbox.ts +100 -18
- package/src/client/components/jant-nav-manager.ts +1283 -54
- package/src/client/components/jant-post-form.ts +3 -3
- package/src/client/components/jant-post-menu.ts +86 -74
- package/src/client/components/nav-manager-types.ts +51 -2
- package/src/client/components/post-form-types.ts +1 -1
- package/src/client/compose-bridge.ts +4 -1
- package/src/client/feed-video-player.ts +62 -2
- package/src/client/footnote-rail.ts +478 -0
- package/src/client/hydrate-partial.ts +2 -0
- package/src/client/media-lightbox-events.ts +63 -0
- package/src/client/site-header-fragment.ts +38 -0
- package/src/client/tiptap/__tests__/blockquote-editing.test.ts +201 -0
- package/src/client/tiptap/__tests__/clear-formatting.test.ts +168 -0
- package/src/client/tiptap/__tests__/list-editing.test.ts +447 -0
- package/src/client/tiptap/__tests__/markdown-clipboard.test.ts +727 -4
- package/src/client/tiptap/__tests__/table-controls.test.ts +263 -0
- package/src/client/tiptap/__tests__/table-size-picker.test.ts +179 -0
- package/src/client/tiptap/bubble-menu.ts +88 -10
- package/src/client/tiptap/continuous-lists.ts +102 -0
- package/src/client/tiptap/create-editor.ts +3 -0
- package/src/client/tiptap/extensions.ts +14 -5
- package/src/client/tiptap/markdown-clipboard.ts +608 -11
- package/src/client/tiptap/slash-commands.ts +8 -1
- package/src/client/tiptap/structural-keymap.ts +211 -0
- package/src/client/tiptap/tab-indent.ts +8 -22
- package/src/client/tiptap/table-control-labels.ts +30 -0
- package/src/client/tiptap/table-controls.ts +537 -0
- package/src/client/tiptap/table-size-picker.ts +254 -0
- package/src/client/toast.ts +8 -6
- package/src/client-auth.ts +1 -0
- package/src/client.ts +1 -0
- package/src/db/__tests__/d1-query.test.ts +43 -1
- package/src/db/__tests__/migration-runner.test.ts +63 -0
- package/src/db/__tests__/migrations.test.ts +469 -0
- package/src/db/__tests__/thread-collection-migration.test.ts +364 -0
- package/src/db/migrations/0027_old_blue_blade.sql +39 -0
- package/src/db/migrations/0028_superb_post.sql +2 -0
- package/src/db/migrations/0029_boring_magma.sql +1 -0
- package/src/db/migrations/0030_typical_vivisector.sql +50 -0
- package/src/db/migrations/meta/0027_snapshot.json +2511 -0
- package/src/db/migrations/meta/0028_snapshot.json +2511 -0
- package/src/db/migrations/meta/0029_snapshot.json +2519 -0
- package/src/db/migrations/meta/0030_snapshot.json +2541 -0
- package/src/db/migrations/meta/_journal.json +28 -0
- package/src/db/migrations/pg/0025_moaning_epoch.sql +39 -0
- package/src/db/migrations/pg/0026_talented_killer_shrike.sql +2 -0
- package/src/db/migrations/pg/0027_short_cannonball.sql +1 -0
- package/src/db/migrations/pg/0028_perfect_sharon_carter.sql +27 -0
- package/src/db/migrations/pg/meta/0025_snapshot.json +3204 -0
- package/src/db/migrations/pg/meta/0026_snapshot.json +3204 -0
- package/src/db/migrations/pg/meta/0027_snapshot.json +3211 -0
- package/src/db/migrations/pg/meta/0028_snapshot.json +3248 -0
- package/src/db/migrations/pg/meta/_journal.json +28 -0
- package/src/db/pg/schema.ts +28 -20
- package/src/db/rehearsal-fixtures/demo-current.json +39 -4
- package/src/db/rehearsal-fixtures/demo-current.sql +121 -6
- package/src/db/schema.ts +28 -20
- package/src/i18n/__tests__/detect.test.ts +8 -2
- package/src/i18n/detect.ts +14 -5
- package/src/i18n/locales/public/en.po +133 -30
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +128 -25
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +128 -25
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +513 -10
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +515 -12
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +515 -12
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/lib/__tests__/api-settings.test.ts +299 -0
- package/src/lib/__tests__/constants.test.ts +5 -0
- package/src/lib/__tests__/feed-policy.test.ts +25 -0
- package/src/lib/__tests__/footnotes-upgrade.test.ts +181 -0
- package/src/lib/__tests__/markdown-roundtrip-embed.test.ts +61 -0
- package/src/lib/__tests__/markdown-to-tiptap.test.ts +32 -4
- package/src/lib/__tests__/markdown.test.ts +8 -6
- package/src/lib/__tests__/navigation.test.ts +59 -2
- package/src/lib/__tests__/post-body-html.test.ts +176 -0
- package/src/lib/__tests__/post-display.test.ts +64 -0
- package/src/lib/__tests__/resolve-config.test.ts +113 -1
- package/src/lib/__tests__/summary.test.ts +82 -0
- package/src/lib/__tests__/timeline.test.ts +109 -70
- package/src/lib/__tests__/timezones.test.ts +31 -3
- package/src/lib/__tests__/tiptap-render.test.ts +268 -9
- package/src/lib/__tests__/tiptap-to-markdown.test.ts +6 -0
- package/src/lib/__tests__/view.test.ts +53 -0
- package/src/lib/__tests__/worker-response-cache.test.ts +18 -1
- package/src/lib/api-settings.ts +239 -12
- package/src/lib/collection-sort.ts +7 -5
- package/src/lib/constants.ts +2 -0
- package/src/lib/feed-path.ts +25 -0
- package/src/lib/feed-policy.ts +64 -0
- package/src/lib/footnotes.ts +264 -0
- package/src/lib/github-sync-site-config.ts +2 -0
- package/src/lib/hugo-markdown.ts +10 -3
- package/src/lib/jant-branding.ts +1 -0
- package/src/lib/markdown-manager.ts +188 -5
- package/src/lib/markdown.ts +10 -3
- package/src/lib/navigation.ts +16 -3
- package/src/lib/post-body-html.ts +131 -0
- package/src/lib/post-display.ts +7 -1
- package/src/lib/render.tsx +9 -2
- package/src/lib/resolve-config.ts +100 -16
- package/src/lib/schemas.ts +133 -1
- package/src/lib/settings-paths.ts +5 -0
- package/src/lib/site-skill.ts +78 -0
- package/src/lib/summary.ts +16 -5
- package/src/lib/timeline.ts +98 -122
- package/src/lib/timezones.ts +54 -14
- package/src/lib/tiptap-render.ts +355 -81
- package/src/lib/view.ts +30 -20
- package/src/lib/worker-response-cache.ts +11 -18
- package/src/middleware/__tests__/public-content-access.test.ts +91 -0
- package/src/middleware/config.ts +2 -2
- package/src/middleware/public-content-access.ts +87 -0
- package/src/node/__tests__/cli-export.test.ts +14 -0
- package/src/node/__tests__/cli-migrate.test.ts +6 -0
- package/src/node/__tests__/cli-site-snapshot.test.ts +205 -2
- package/src/node/__tests__/cli-snapshot-meta.test.ts +100 -0
- package/src/node/index.ts +2 -1
- package/src/preset.css +16 -2
- package/src/routes/__tests__/compose.test.ts +51 -0
- package/src/routes/__tests__/site-skill.test.ts +112 -0
- package/src/routes/api/__tests__/collections.test.ts +91 -19
- package/src/routes/api/__tests__/mcp.test.ts +65 -1
- package/src/routes/api/__tests__/nav-items.test.ts +91 -0
- package/src/routes/api/__tests__/public-access.test.ts +81 -0
- package/src/routes/api/__tests__/settings.test.ts +217 -0
- package/src/routes/api/collections.ts +22 -26
- package/src/routes/api/export.ts +2 -0
- package/src/routes/api/internal/__tests__/post-body-html.test.ts +163 -0
- package/src/routes/api/internal/__tests__/sites.test.ts +35 -2
- package/src/routes/api/internal/post-body-html.ts +43 -0
- package/src/routes/api/internal/sites.ts +24 -0
- package/src/routes/api/nav-items.ts +24 -1
- package/src/routes/api/posts.ts +2 -2
- package/src/routes/api/public/__tests__/archive.test.ts +35 -0
- package/src/routes/api/public/__tests__/posts.test.ts +208 -0
- package/src/routes/api/public/archive.ts +4 -0
- package/src/routes/api/public/posts.ts +41 -24
- package/src/routes/api/search.ts +3 -0
- package/src/routes/api/settings.ts +33 -0
- package/src/routes/auth/__tests__/setup.test.ts +7 -4
- package/src/routes/compose.tsx +2 -1
- package/src/routes/dash/settings.tsx +45 -2
- package/src/routes/feed/__tests__/feed.test.ts +210 -6
- package/src/routes/feed/feed.ts +23 -14
- package/src/routes/pages/__tests__/archive-params.test.ts +92 -3
- package/src/routes/pages/__tests__/collection-routing.test.ts +63 -5
- package/src/routes/pages/__tests__/collections.test.ts +9 -9
- package/src/routes/pages/__tests__/preview.test.ts +174 -0
- package/src/routes/pages/__tests__/search.test.ts +69 -0
- package/src/routes/pages/archive.tsx +27 -7
- package/src/routes/pages/collection.tsx +32 -19
- package/src/routes/pages/collections.tsx +6 -1
- package/src/routes/pages/page.tsx +83 -11
- package/src/routes/site-skill.ts +18 -0
- package/src/services/__tests__/auth.test.ts +7 -5
- package/src/services/__tests__/collection.test.ts +159 -44
- package/src/services/__tests__/navigation.test.ts +229 -21
- package/src/services/__tests__/post-timeline.test.ts +109 -30
- package/src/services/__tests__/post.test.ts +567 -5
- package/src/services/__tests__/search.test.ts +48 -1
- package/src/services/__tests__/settings.test.ts +8 -0
- package/src/services/__tests__/site-admin.test.ts +121 -1
- package/src/services/auth.ts +2 -2
- package/src/services/bootstrap.ts +3 -2
- package/src/services/collection.ts +226 -167
- package/src/services/export-theme/assets/client-site.css +1 -1
- package/src/services/export-theme/assets/client-site.js +46 -25
- package/src/services/export-theme/layouts/_default/list.html +18 -4
- package/src/services/export-theme/layouts/_default/rss.xml +8 -12
- package/src/services/export-theme/layouts/featured/list.html +5 -4
- package/src/services/export-theme/layouts/partials/featured-thread.html +56 -0
- package/src/services/export-theme/layouts/partials/footer.html +1 -1
- package/src/services/export-theme/layouts/partials/media-gallery.html +1 -0
- package/src/services/export-theme/styles/main.css +30 -2
- package/src/services/export.ts +91 -80
- package/src/services/mcp.ts +37 -27
- package/src/services/media.ts +1 -1
- package/src/services/navigation.ts +185 -46
- package/src/services/post.ts +874 -271
- package/src/services/search.ts +8 -2
- package/src/services/settings.ts +2 -10
- package/src/services/site-admin.ts +63 -43
- package/src/style-cjk-jp.css +1 -1
- package/src/style-cjk-kr.css +1 -1
- package/src/style-cjk-tc.css +1 -1
- package/src/style-cjk.css +1 -1
- package/src/styles/components.css +540 -0
- package/src/styles/site-media.css +111 -19
- package/src/styles/tokens.css +14 -9
- package/src/styles/ui.css +829 -29
- package/src/types/bindings.ts +3 -0
- package/src/types/config.ts +243 -12
- package/src/types/constants.ts +22 -1
- package/src/types/entities.ts +9 -8
- package/src/types/operations.ts +18 -10
- package/src/types/props.ts +8 -2
- package/src/types/raw-assets.d.ts +5 -0
- package/src/types/views.ts +16 -4
- package/src/ui/__tests__/font-themes.test.ts +42 -30
- package/src/ui/compose/ComposeDialog.tsx +92 -2
- package/src/ui/dash/appearance/NavigationContent.tsx +332 -4
- package/src/ui/dash/appearance/__tests__/NavigationContent.test.tsx +23 -0
- package/src/ui/dash/settings/ConfigEditorContent.tsx +578 -0
- package/src/ui/dash/settings/GeneralContent.tsx +15 -5
- package/src/ui/dash/settings/SettingsRootContent.tsx +21 -1
- package/src/ui/dash/settings/__tests__/ConfigEditorContent.test.tsx +98 -0
- package/src/ui/dash/settings/__tests__/SettingsRootContent.test.tsx +15 -0
- package/src/ui/feed/CuratedThreadPreview.tsx +16 -4
- package/src/ui/feed/LinkCard.tsx +2 -12
- package/src/ui/feed/NoteCard.tsx +10 -20
- package/src/ui/feed/QuoteCard.tsx +2 -12
- package/src/ui/feed/ThreadPreview.tsx +26 -34
- package/src/ui/feed/TimelineFeed.tsx +2 -2
- package/src/ui/feed/__tests__/thread-preview.test.ts +197 -56
- package/src/ui/feed/__tests__/timeline-cards.test.ts +178 -3
- package/src/ui/feed/thread-preview-state.ts +5 -7
- package/src/ui/font-themes.ts +74 -26
- package/src/ui/layouts/BaseLayout.tsx +22 -8
- package/src/ui/layouts/__tests__/BaseLayout.test.tsx +64 -1
- package/src/ui/pages/CollectionPage.tsx +101 -22
- package/src/ui/pages/CollectionsPage.tsx +3 -1
- package/src/ui/pages/PostPage.tsx +39 -12
- package/src/ui/pages/SearchPage.tsx +6 -14
- package/src/ui/pages/__tests__/ArchivePage.test.tsx +7 -0
- package/src/ui/pages/__tests__/PostPage.test.tsx +88 -0
- package/src/ui/shared/CollectionDirectory.tsx +13 -9
- package/src/ui/shared/CollectionsManager.tsx +17 -7
- package/src/ui/shared/DraftPreviewBar.tsx +33 -0
- package/src/ui/shared/HomePageBranding.tsx +2 -2
- package/src/ui/shared/MediaGallery.tsx +1 -0
- package/src/ui/shared/PostFooter.tsx +3 -1
- package/src/ui/shared/__tests__/home-page-branding.test.tsx +1 -1
- package/src/ui/shared/__tests__/media-gallery.test.ts +1 -0
- package/src/ui/shared/__tests__/navigation-labels.test.ts +2 -2
- package/src/ui/shared/__tests__/post-footer.test.ts +15 -0
- package/src/ui/shared/collection-management-labels.ts +33 -2
- package/src/ui/shared/navigation-labels.ts +2 -4
- package/src/ui/shared/post-article-attributes.ts +46 -0
- package/dist/app-DZDlmh7C.js +0 -6
- package/dist/client/_assets/client-Cevfpm8H.css +0 -2
- package/dist/client/_assets/client-auth-v3yvhbgZ.js +0 -4736
- package/src/client/tiptap/wrapping-input-rules.ts +0 -102
|
@@ -1,23 +1,44 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
|
|
3
3
|
import type { Editor } from "@tiptap/core";
|
|
4
|
+
import { TextSelection } from "@tiptap/pm/state";
|
|
4
5
|
import { afterEach, describe, expect, it } from "vitest";
|
|
5
6
|
import { createTiptapEditor } from "../create-editor.js";
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
isCodeEditorHtml,
|
|
9
|
+
isObsidianHtml,
|
|
10
|
+
normalizeObsidianClipboardArtifacts,
|
|
11
|
+
normalizePastedFootnoteHtml,
|
|
12
|
+
} from "../markdown-clipboard.js";
|
|
7
13
|
|
|
8
14
|
const editors: Editor[] = [];
|
|
9
15
|
|
|
10
|
-
function dispatchMarkdownPaste(
|
|
16
|
+
function dispatchMarkdownPaste(
|
|
17
|
+
editor: Editor,
|
|
18
|
+
text: string,
|
|
19
|
+
html = "",
|
|
20
|
+
markdown = "",
|
|
21
|
+
) {
|
|
11
22
|
const event = new Event("paste", {
|
|
12
23
|
bubbles: true,
|
|
13
24
|
cancelable: true,
|
|
14
25
|
}) as Event & { clipboardData: unknown };
|
|
15
26
|
event.clipboardData = {
|
|
16
27
|
getData: (type: string) =>
|
|
17
|
-
type === "text/plain"
|
|
28
|
+
type === "text/plain"
|
|
29
|
+
? text
|
|
30
|
+
: type === "text/html"
|
|
31
|
+
? html
|
|
32
|
+
: type === "text/markdown"
|
|
33
|
+
? markdown
|
|
34
|
+
: "",
|
|
18
35
|
files: [],
|
|
19
36
|
items: [],
|
|
20
|
-
types:
|
|
37
|
+
types: [
|
|
38
|
+
...(markdown ? ["text/markdown"] : []),
|
|
39
|
+
...(html ? ["text/html"] : []),
|
|
40
|
+
...(text ? ["text/plain"] : []),
|
|
41
|
+
],
|
|
21
42
|
};
|
|
22
43
|
editor.commands.focus();
|
|
23
44
|
editor.view.dom.dispatchEvent(event);
|
|
@@ -28,6 +49,60 @@ afterEach(() => {
|
|
|
28
49
|
document.body.innerHTML = "";
|
|
29
50
|
});
|
|
30
51
|
|
|
52
|
+
describe("Obsidian clipboard detection", () => {
|
|
53
|
+
it("finds the marker even when metadata precedes it", () => {
|
|
54
|
+
expect(
|
|
55
|
+
isObsidianHtml('<meta charset="utf-8"><!-- obsidian --><p>Rendered</p>'),
|
|
56
|
+
).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("does not infer Obsidian from its footnote classes", () => {
|
|
60
|
+
expect(
|
|
61
|
+
isObsidianHtml('<sup class="footnote-ref"><a href="#fn-1">1</a></sup>'),
|
|
62
|
+
).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("normalizeObsidianClipboardArtifacts", () => {
|
|
67
|
+
it("removes bare internal spacer paragraphs from marked fragments", () => {
|
|
68
|
+
expect(
|
|
69
|
+
normalizeObsidianClipboardArtifacts(
|
|
70
|
+
"<!-- obsidian --><p>First</p><p> \n </p><p></p><p>Second</p>",
|
|
71
|
+
),
|
|
72
|
+
).toBe("<!-- obsidian --><p>First</p><p>Second</p>");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("does not normalize the same shape from ordinary rich HTML", () => {
|
|
76
|
+
const html = "<p>First</p><p> \n </p><p>Second</p>";
|
|
77
|
+
expect(normalizeObsidianClipboardArtifacts(html)).toBe(html);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it.each([
|
|
81
|
+
["explicit break", "<p><br></p>"],
|
|
82
|
+
["media", '<p><img src="image.png"></p>'],
|
|
83
|
+
["attributed spacer", '<p data-purpose="spacer"></p>'],
|
|
84
|
+
["non-breaking space", "<p> </p>"],
|
|
85
|
+
])("preserves %s paragraphs", (_, middle) => {
|
|
86
|
+
const html = `<!-- obsidian --><p>First</p>${middle}<p>Second</p>`;
|
|
87
|
+
expect(normalizeObsidianClipboardArtifacts(html)).toBe(html);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("preserves nested and edge empty paragraphs", () => {
|
|
91
|
+
const html =
|
|
92
|
+
"<!-- obsidian --><p></p><blockquote><p></p><p>Quote</p></blockquote><p></p>";
|
|
93
|
+
expect(normalizeObsidianClipboardArtifacts(html)).toBe(html);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("normalizePastedFootnoteHtml", () => {
|
|
98
|
+
it("leaves ordinary superscript section links and lists unchanged", () => {
|
|
99
|
+
const html =
|
|
100
|
+
'<p>Chapter<sup><a href="#section-1">1</a></sup></p><ol><li id="section-1">Section</li></ol>';
|
|
101
|
+
|
|
102
|
+
expect(normalizePastedFootnoteHtml(html)).toBe(html);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
31
106
|
describe("isCodeEditorHtml", () => {
|
|
32
107
|
it("detects VS Code HTML via data-vscode attribute", () => {
|
|
33
108
|
const html = `<meta charset='utf-8'><div style="color: #d4d4d4;background-color: #1e1e1e;" data-vscode-theme-name="Default Dark+"><div style="line-height:18px"><span style="color: #569cd6;">const</span> x = 1;</div></div>`;
|
|
@@ -75,6 +150,409 @@ describe("isCodeEditorHtml", () => {
|
|
|
75
150
|
});
|
|
76
151
|
|
|
77
152
|
describe("MarkdownClipboard", () => {
|
|
153
|
+
it("prefers an explicit text/markdown flavor over HTML and plain text", () => {
|
|
154
|
+
const element = document.createElement("div");
|
|
155
|
+
document.body.appendChild(element);
|
|
156
|
+
const editor = createTiptapEditor({ element });
|
|
157
|
+
editors.push(editor);
|
|
158
|
+
|
|
159
|
+
dispatchMarkdownPaste(
|
|
160
|
+
editor,
|
|
161
|
+
"Plain fallback",
|
|
162
|
+
"<p>Rich fallback</p>",
|
|
163
|
+
"# Markdown source\n\nBody[^note]\n\n[^note]: Definition",
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
expect(editor.getJSON().content?.map((node) => node.type)).toEqual([
|
|
167
|
+
"heading",
|
|
168
|
+
"paragraph",
|
|
169
|
+
"footnoteDefinition",
|
|
170
|
+
]);
|
|
171
|
+
expect(editor.getJSON().content?.[2]?.attrs).toEqual({ label: "note" });
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("uses marked Obsidian plain text as Markdown instead of rendered HTML", () => {
|
|
175
|
+
const element = document.createElement("div");
|
|
176
|
+
document.body.appendChild(element);
|
|
177
|
+
const editor = createTiptapEditor({ element });
|
|
178
|
+
editors.push(editor);
|
|
179
|
+
|
|
180
|
+
dispatchMarkdownPaste(
|
|
181
|
+
editor,
|
|
182
|
+
"Plain body[^plain-note]\n\n[^plain-note]: Plain definition",
|
|
183
|
+
[
|
|
184
|
+
'<meta charset="utf-8"><!-- obsidian -->',
|
|
185
|
+
'<p><strong>HTML body</strong><sup class="footnote-ref" data-footnote-id="fnref-1">',
|
|
186
|
+
'<a class="footnote-link" href="#fn-1">[1]</a></sup></p>',
|
|
187
|
+
"<p></p>",
|
|
188
|
+
'<section class="footnotes"><hr><ol>',
|
|
189
|
+
'<li data-footnote-id="fn-1"><p>HTML <em>definition</em> ',
|
|
190
|
+
'<a class="footnote-backref footnote-link" href="#fnref-1">↩︎</a>',
|
|
191
|
+
"</p></li></ol></section>",
|
|
192
|
+
].join(""),
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
expect(editor.getJSON().content?.map((node) => node.type)).toEqual([
|
|
196
|
+
"paragraph",
|
|
197
|
+
"footnoteDefinition",
|
|
198
|
+
]);
|
|
199
|
+
expect(editor.getJSON().content?.[0]?.content?.[0]).toEqual({
|
|
200
|
+
type: "text",
|
|
201
|
+
text: "Plain body",
|
|
202
|
+
});
|
|
203
|
+
expect(editor.getJSON().content?.[0]?.content?.[1]).toEqual({
|
|
204
|
+
type: "footnoteReference",
|
|
205
|
+
attrs: { label: "plain-note" },
|
|
206
|
+
});
|
|
207
|
+
expect(editor.getJSON().content?.[1]?.attrs).toEqual({
|
|
208
|
+
label: "plain-note",
|
|
209
|
+
});
|
|
210
|
+
expect(JSON.stringify(editor.getJSON())).toContain("Plain definition");
|
|
211
|
+
expect(JSON.stringify(editor.getJSON())).not.toContain("HTML body");
|
|
212
|
+
expect(JSON.stringify(editor.getJSON())).not.toContain("footnote-backref");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("keeps normal rich HTML ahead of its plain fallback", () => {
|
|
216
|
+
const element = document.createElement("div");
|
|
217
|
+
document.body.appendChild(element);
|
|
218
|
+
const editor = createTiptapEditor({ element });
|
|
219
|
+
editors.push(editor);
|
|
220
|
+
|
|
221
|
+
dispatchMarkdownPaste(
|
|
222
|
+
editor,
|
|
223
|
+
"# Plain fallback",
|
|
224
|
+
"<p><strong>Rich source</strong></p>",
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
expect(editor.getJSON()).toEqual({
|
|
228
|
+
type: "doc",
|
|
229
|
+
content: [
|
|
230
|
+
{
|
|
231
|
+
type: "paragraph",
|
|
232
|
+
content: [
|
|
233
|
+
{
|
|
234
|
+
type: "text",
|
|
235
|
+
marks: [{ type: "bold" }],
|
|
236
|
+
text: "Rich source",
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("turns pasted blank-line breaks into semantic paragraphs", () => {
|
|
245
|
+
const element = document.createElement("div");
|
|
246
|
+
document.body.appendChild(element);
|
|
247
|
+
const editor = createTiptapEditor({ element });
|
|
248
|
+
editors.push(editor);
|
|
249
|
+
|
|
250
|
+
dispatchMarkdownPaste(
|
|
251
|
+
editor,
|
|
252
|
+
"First paragraph\n\nSecond paragraph\ncontinued",
|
|
253
|
+
[
|
|
254
|
+
"<p>First paragraph<br><br>",
|
|
255
|
+
'<strong>Second paragraph</strong><br><a href="https://example.com">continued</a>',
|
|
256
|
+
"</p>",
|
|
257
|
+
].join(""),
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
expect(editor.getJSON()).toEqual({
|
|
261
|
+
type: "doc",
|
|
262
|
+
content: [
|
|
263
|
+
{
|
|
264
|
+
type: "paragraph",
|
|
265
|
+
content: [{ type: "text", text: "First paragraph" }],
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
type: "paragraph",
|
|
269
|
+
content: [
|
|
270
|
+
{
|
|
271
|
+
type: "text",
|
|
272
|
+
marks: [{ type: "bold" }],
|
|
273
|
+
text: "Second paragraph",
|
|
274
|
+
},
|
|
275
|
+
{ type: "hardBreak" },
|
|
276
|
+
{
|
|
277
|
+
type: "text",
|
|
278
|
+
marks: [
|
|
279
|
+
expect.objectContaining({
|
|
280
|
+
type: "link",
|
|
281
|
+
attrs: expect.objectContaining({
|
|
282
|
+
href: "https://example.com",
|
|
283
|
+
}),
|
|
284
|
+
}),
|
|
285
|
+
],
|
|
286
|
+
text: "continued",
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("preserves a single hard break in pasted rich text", () => {
|
|
295
|
+
const element = document.createElement("div");
|
|
296
|
+
document.body.appendChild(element);
|
|
297
|
+
const editor = createTiptapEditor({ element });
|
|
298
|
+
editors.push(editor);
|
|
299
|
+
|
|
300
|
+
dispatchMarkdownPaste(
|
|
301
|
+
editor,
|
|
302
|
+
"First line\nSecond line",
|
|
303
|
+
"<p>First line<br>Second line</p>",
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
expect(editor.getJSON().content).toEqual([
|
|
307
|
+
{
|
|
308
|
+
type: "paragraph",
|
|
309
|
+
content: [
|
|
310
|
+
{ type: "text", text: "First line" },
|
|
311
|
+
{ type: "hardBreak" },
|
|
312
|
+
{ type: "text", text: "Second line" },
|
|
313
|
+
],
|
|
314
|
+
},
|
|
315
|
+
]);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("keeps a valid empty paragraph for break-only pasted blocks", () => {
|
|
319
|
+
const element = document.createElement("div");
|
|
320
|
+
document.body.appendChild(element);
|
|
321
|
+
const editor = createTiptapEditor({ element });
|
|
322
|
+
editors.push(editor);
|
|
323
|
+
|
|
324
|
+
dispatchMarkdownPaste(editor, "", "<p><br><br><br></p>");
|
|
325
|
+
|
|
326
|
+
expect(editor.getJSON()).toEqual({
|
|
327
|
+
type: "doc",
|
|
328
|
+
content: [{ type: "paragraph" }],
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("normalizes longer break runs inside their structural container", () => {
|
|
333
|
+
const element = document.createElement("div");
|
|
334
|
+
document.body.appendChild(element);
|
|
335
|
+
const editor = createTiptapEditor({ element });
|
|
336
|
+
editors.push(editor);
|
|
337
|
+
|
|
338
|
+
dispatchMarkdownPaste(
|
|
339
|
+
editor,
|
|
340
|
+
"First quote\n\nSecond quote",
|
|
341
|
+
"<blockquote><p>First quote<br> \n <br>\t<br>Second quote</p></blockquote>",
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
expect(editor.getJSON().content).toEqual([
|
|
345
|
+
{
|
|
346
|
+
type: "blockquote",
|
|
347
|
+
content: [
|
|
348
|
+
{
|
|
349
|
+
type: "paragraph",
|
|
350
|
+
content: [{ type: "text", text: "First quote" }],
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
type: "paragraph",
|
|
354
|
+
content: [{ type: "text", text: "Second quote" }],
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
{ type: "paragraph" },
|
|
359
|
+
]);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it("does not rewrite existing documents outside the paste boundary", () => {
|
|
363
|
+
const element = document.createElement("div");
|
|
364
|
+
document.body.appendChild(element);
|
|
365
|
+
const editor = createTiptapEditor({
|
|
366
|
+
element,
|
|
367
|
+
content: {
|
|
368
|
+
type: "doc",
|
|
369
|
+
content: [
|
|
370
|
+
{
|
|
371
|
+
type: "paragraph",
|
|
372
|
+
content: [
|
|
373
|
+
{ type: "text", text: "First" },
|
|
374
|
+
{ type: "hardBreak" },
|
|
375
|
+
{ type: "hardBreak" },
|
|
376
|
+
{ type: "text", text: "Second" },
|
|
377
|
+
],
|
|
378
|
+
},
|
|
379
|
+
],
|
|
380
|
+
},
|
|
381
|
+
});
|
|
382
|
+
editors.push(editor);
|
|
383
|
+
|
|
384
|
+
expect(editor.getJSON().content).toEqual([
|
|
385
|
+
{
|
|
386
|
+
type: "paragraph",
|
|
387
|
+
content: [
|
|
388
|
+
{ type: "text", text: "First" },
|
|
389
|
+
{ type: "hardBreak" },
|
|
390
|
+
{ type: "hardBreak" },
|
|
391
|
+
{ type: "text", text: "Second" },
|
|
392
|
+
],
|
|
393
|
+
},
|
|
394
|
+
]);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it("copies a complete document as canonical Markdown without changing it", () => {
|
|
398
|
+
const element = document.createElement("div");
|
|
399
|
+
document.body.appendChild(element);
|
|
400
|
+
const editor = createTiptapEditor({
|
|
401
|
+
element,
|
|
402
|
+
content: {
|
|
403
|
+
type: "doc",
|
|
404
|
+
content: [
|
|
405
|
+
{
|
|
406
|
+
type: "heading",
|
|
407
|
+
attrs: { level: 2 },
|
|
408
|
+
content: [{ type: "text", text: "Heading" }],
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
type: "paragraph",
|
|
412
|
+
content: [
|
|
413
|
+
{
|
|
414
|
+
type: "text",
|
|
415
|
+
marks: [{ type: "bold" }],
|
|
416
|
+
text: "Bold",
|
|
417
|
+
},
|
|
418
|
+
{ type: "text", text: " and " },
|
|
419
|
+
{
|
|
420
|
+
type: "text",
|
|
421
|
+
marks: [
|
|
422
|
+
{
|
|
423
|
+
type: "link",
|
|
424
|
+
attrs: {
|
|
425
|
+
href: "https://example.com",
|
|
426
|
+
target: "_blank",
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
],
|
|
430
|
+
text: "link",
|
|
431
|
+
},
|
|
432
|
+
],
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
type: "blockquote",
|
|
436
|
+
content: [
|
|
437
|
+
{
|
|
438
|
+
type: "paragraph",
|
|
439
|
+
content: [{ type: "text", text: "Quote" }],
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
type: "paragraph",
|
|
443
|
+
content: [{ type: "text", text: "Second" }],
|
|
444
|
+
},
|
|
445
|
+
],
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
type: "bulletList",
|
|
449
|
+
content: [
|
|
450
|
+
{
|
|
451
|
+
type: "listItem",
|
|
452
|
+
content: [
|
|
453
|
+
{
|
|
454
|
+
type: "paragraph",
|
|
455
|
+
content: [{ type: "text", text: "One" }],
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
type: "bulletList",
|
|
459
|
+
content: [
|
|
460
|
+
{
|
|
461
|
+
type: "listItem",
|
|
462
|
+
content: [
|
|
463
|
+
{
|
|
464
|
+
type: "paragraph",
|
|
465
|
+
content: [{ type: "text", text: "Nested" }],
|
|
466
|
+
},
|
|
467
|
+
],
|
|
468
|
+
},
|
|
469
|
+
],
|
|
470
|
+
},
|
|
471
|
+
],
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
type: "listItem",
|
|
475
|
+
content: [
|
|
476
|
+
{
|
|
477
|
+
type: "paragraph",
|
|
478
|
+
content: [{ type: "text", text: "Two" }],
|
|
479
|
+
},
|
|
480
|
+
],
|
|
481
|
+
},
|
|
482
|
+
],
|
|
483
|
+
},
|
|
484
|
+
],
|
|
485
|
+
},
|
|
486
|
+
});
|
|
487
|
+
editors.push(editor);
|
|
488
|
+
editor.commands.selectAll();
|
|
489
|
+
const before = editor.getJSON();
|
|
490
|
+
const { dom, text } = editor.view.serializeForClipboard(
|
|
491
|
+
editor.state.selection.content(),
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
expect(text).toBe(
|
|
495
|
+
"## Heading\n\n**Bold** and [link](https://example.com)\n\n> Quote\n>\n> Second\n\n- One\n - Nested\n- Two",
|
|
496
|
+
);
|
|
497
|
+
expect(dom.querySelector("h2")?.textContent).toBe("Heading");
|
|
498
|
+
expect(dom.innerHTML).toContain("<strong>Bold</strong>");
|
|
499
|
+
expect(dom.innerHTML).toContain("<blockquote>");
|
|
500
|
+
expect(editor.getJSON()).toEqual(before);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it("keeps partial selections as readable plain text", () => {
|
|
504
|
+
const element = document.createElement("div");
|
|
505
|
+
document.body.appendChild(element);
|
|
506
|
+
const editor = createTiptapEditor({
|
|
507
|
+
element,
|
|
508
|
+
content: {
|
|
509
|
+
type: "doc",
|
|
510
|
+
content: [
|
|
511
|
+
{
|
|
512
|
+
type: "paragraph",
|
|
513
|
+
content: [
|
|
514
|
+
{
|
|
515
|
+
type: "text",
|
|
516
|
+
marks: [{ type: "bold" }],
|
|
517
|
+
text: "Bold",
|
|
518
|
+
},
|
|
519
|
+
{ type: "text", text: " and " },
|
|
520
|
+
{
|
|
521
|
+
type: "text",
|
|
522
|
+
marks: [
|
|
523
|
+
{
|
|
524
|
+
type: "link",
|
|
525
|
+
attrs: {
|
|
526
|
+
href: "https://example.com",
|
|
527
|
+
target: "_blank",
|
|
528
|
+
},
|
|
529
|
+
},
|
|
530
|
+
],
|
|
531
|
+
text: "link",
|
|
532
|
+
},
|
|
533
|
+
],
|
|
534
|
+
},
|
|
535
|
+
],
|
|
536
|
+
},
|
|
537
|
+
});
|
|
538
|
+
editors.push(editor);
|
|
539
|
+
editor.view.dispatch(
|
|
540
|
+
editor.state.tr.setSelection(
|
|
541
|
+
TextSelection.create(editor.state.doc, 1, 14),
|
|
542
|
+
),
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
const { dom, text } = editor.view.serializeForClipboard(
|
|
546
|
+
editor.state.selection.content(),
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
expect(text).toBe("Bold and link");
|
|
550
|
+
expect(text).not.toContain("**");
|
|
551
|
+
expect(text).not.toContain("https://example.com");
|
|
552
|
+
expect(dom.innerHTML).toContain("<strong>Bold</strong>");
|
|
553
|
+
expect(dom.innerHTML).toContain("<a");
|
|
554
|
+
});
|
|
555
|
+
|
|
78
556
|
it.each([
|
|
79
557
|
["plain text", ""],
|
|
80
558
|
[
|
|
@@ -150,6 +628,251 @@ describe("MarkdownClipboard", () => {
|
|
|
150
628
|
});
|
|
151
629
|
});
|
|
152
630
|
|
|
631
|
+
it("converts Obsidian HTML-only footnotes and removes generated backlinks", () => {
|
|
632
|
+
const element = document.createElement("div");
|
|
633
|
+
document.body.appendChild(element);
|
|
634
|
+
const editor = createTiptapEditor({ element });
|
|
635
|
+
editors.push(editor);
|
|
636
|
+
|
|
637
|
+
dispatchMarkdownPaste(
|
|
638
|
+
editor,
|
|
639
|
+
"",
|
|
640
|
+
[
|
|
641
|
+
'<p>Body<sup class="footnote-ref" data-footnote-id="fnref-1">',
|
|
642
|
+
'<a class="footnote-link" href="#fn-1" data-footref="source-note">[1]</a>',
|
|
643
|
+
"</sup></p>",
|
|
644
|
+
'<section class="footnotes"><hr><ol>',
|
|
645
|
+
'<li data-footnote-id="fn-1"><p>Definition with ',
|
|
646
|
+
'<a href="https://example.com">a source</a> ',
|
|
647
|
+
'<a class="footnote-backref footnote-link" href="#fnref-1">↩︎</a>',
|
|
648
|
+
"</p></li></ol></section>",
|
|
649
|
+
].join(""),
|
|
650
|
+
);
|
|
651
|
+
|
|
652
|
+
const json = editor.getJSON();
|
|
653
|
+
expect(json.content?.map((node) => node.type)).toEqual([
|
|
654
|
+
"paragraph",
|
|
655
|
+
"footnoteDefinition",
|
|
656
|
+
]);
|
|
657
|
+
expect(json.content?.[0]?.content?.[1]).toEqual({
|
|
658
|
+
type: "footnoteReference",
|
|
659
|
+
attrs: { label: "source-note" },
|
|
660
|
+
});
|
|
661
|
+
expect(json.content?.[1]?.attrs).toEqual({ label: "source-note" });
|
|
662
|
+
expect(JSON.stringify(json)).toContain("https://example.com");
|
|
663
|
+
expect(JSON.stringify(json)).not.toContain("footnote-backref");
|
|
664
|
+
expect(JSON.stringify(json)).not.toContain("#fnref-1");
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
it("converts GitHub-style footnotes into structural nodes", () => {
|
|
668
|
+
const element = document.createElement("div");
|
|
669
|
+
document.body.appendChild(element);
|
|
670
|
+
const editor = createTiptapEditor({ element });
|
|
671
|
+
editors.push(editor);
|
|
672
|
+
|
|
673
|
+
dispatchMarkdownPaste(
|
|
674
|
+
editor,
|
|
675
|
+
"",
|
|
676
|
+
[
|
|
677
|
+
'<p>Body<sup><a id="user-content-fnref-1" href="#user-content-fn-1" data-footnote-ref>1</a></sup></p>',
|
|
678
|
+
'<section class="footnotes" data-footnotes>',
|
|
679
|
+
'<h2 id="footnote-label">Footnotes</h2><ol>',
|
|
680
|
+
'<li id="user-content-fn-1"><p>Definition ',
|
|
681
|
+
'<a href="#user-content-fnref-1" data-footnote-backref>↩</a>',
|
|
682
|
+
"</p></li></ol></section>",
|
|
683
|
+
].join(""),
|
|
684
|
+
);
|
|
685
|
+
|
|
686
|
+
const json = editor.getJSON();
|
|
687
|
+
expect(json.content?.map((node) => node.type)).toEqual([
|
|
688
|
+
"paragraph",
|
|
689
|
+
"footnoteDefinition",
|
|
690
|
+
]);
|
|
691
|
+
expect(json.content?.[0]?.content?.[1]).toEqual({
|
|
692
|
+
type: "footnoteReference",
|
|
693
|
+
attrs: { label: "1" },
|
|
694
|
+
});
|
|
695
|
+
expect(json.content?.[1]?.attrs).toEqual({ label: "1" });
|
|
696
|
+
expect(JSON.stringify(json)).not.toContain("horizontalRule");
|
|
697
|
+
expect(JSON.stringify(json)).not.toContain("orderedList");
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
it("converts DPUB-ARIA inline footnotes with rich block content", () => {
|
|
701
|
+
const element = document.createElement("div");
|
|
702
|
+
document.body.appendChild(element);
|
|
703
|
+
const editor = createTiptapEditor({ element });
|
|
704
|
+
editors.push(editor);
|
|
705
|
+
|
|
706
|
+
dispatchMarkdownPaste(
|
|
707
|
+
editor,
|
|
708
|
+
"",
|
|
709
|
+
[
|
|
710
|
+
'<p>Body <a id="fnref-note" href="#fn-note" role="doc-noteref">[note]</a>.</p>',
|
|
711
|
+
'<aside id="fn-note" role="doc-footnote">',
|
|
712
|
+
"<p>First paragraph.</p>",
|
|
713
|
+
"<ul><li><p>Nested item</p></li></ul>",
|
|
714
|
+
'<p><a href="#fnref-note" role="doc-backlink">Back</a></p>',
|
|
715
|
+
"</aside>",
|
|
716
|
+
].join(""),
|
|
717
|
+
);
|
|
718
|
+
|
|
719
|
+
const json = editor.getJSON();
|
|
720
|
+
expect(json.content?.map((node) => node.type)).toEqual([
|
|
721
|
+
"paragraph",
|
|
722
|
+
"footnoteDefinition",
|
|
723
|
+
]);
|
|
724
|
+
expect(json.content?.[0]?.content?.[1]).toEqual({
|
|
725
|
+
type: "footnoteReference",
|
|
726
|
+
attrs: { label: "note" },
|
|
727
|
+
});
|
|
728
|
+
expect(json.content?.[1]?.content?.map((node) => node.type)).toEqual([
|
|
729
|
+
"paragraph",
|
|
730
|
+
"bulletList",
|
|
731
|
+
]);
|
|
732
|
+
expect(JSON.stringify(json)).not.toContain("doc-backlink");
|
|
733
|
+
expect(JSON.stringify(json)).not.toContain("Back");
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
it("keeps repeated HTML references paired to one definition", () => {
|
|
737
|
+
const element = document.createElement("div");
|
|
738
|
+
document.body.appendChild(element);
|
|
739
|
+
const editor = createTiptapEditor({ element });
|
|
740
|
+
editors.push(editor);
|
|
741
|
+
|
|
742
|
+
dispatchMarkdownPaste(
|
|
743
|
+
editor,
|
|
744
|
+
"",
|
|
745
|
+
[
|
|
746
|
+
'<p>First<sup class="footnote-ref"><a href="#fn-1" data-footref="same">[1]</a></sup> ',
|
|
747
|
+
'second<sup class="footnote-ref"><a href="#fn-1" data-footref="same">[1-2]</a></sup>.</p>',
|
|
748
|
+
'<section class="footnotes"><ol><li id="fn-1"><p>Definition ',
|
|
749
|
+
'<a class="footnote-backref" href="#first">↩</a>',
|
|
750
|
+
'<a class="footnote-backref" href="#second">↩</a>',
|
|
751
|
+
"</p></li></ol></section>",
|
|
752
|
+
].join(""),
|
|
753
|
+
);
|
|
754
|
+
|
|
755
|
+
const json = editor.getJSON();
|
|
756
|
+
const serialized = JSON.stringify(json);
|
|
757
|
+
expect(serialized.match(/"type":"footnoteReference"/g)).toHaveLength(2);
|
|
758
|
+
expect(serialized.match(/"type":"footnoteDefinition"/g)).toHaveLength(1);
|
|
759
|
+
expect(serialized.match(/"label":"same"/g)).toHaveLength(3);
|
|
760
|
+
expect(serialized).not.toContain("↩");
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
it("round-trips Jant's editor HTML with raw footnote labels", () => {
|
|
764
|
+
const sourceElement = document.createElement("div");
|
|
765
|
+
const destinationElement = document.createElement("div");
|
|
766
|
+
document.body.appendChild(sourceElement);
|
|
767
|
+
document.body.appendChild(destinationElement);
|
|
768
|
+
const content = {
|
|
769
|
+
type: "doc",
|
|
770
|
+
content: [
|
|
771
|
+
{
|
|
772
|
+
type: "paragraph",
|
|
773
|
+
content: [
|
|
774
|
+
{ type: "text", text: "Body" },
|
|
775
|
+
{ type: "footnoteReference", attrs: { label: "note" } },
|
|
776
|
+
],
|
|
777
|
+
},
|
|
778
|
+
{
|
|
779
|
+
type: "footnoteDefinition",
|
|
780
|
+
attrs: { label: "note" },
|
|
781
|
+
content: [
|
|
782
|
+
{
|
|
783
|
+
type: "paragraph",
|
|
784
|
+
content: [{ type: "text", text: "Definition" }],
|
|
785
|
+
},
|
|
786
|
+
],
|
|
787
|
+
},
|
|
788
|
+
],
|
|
789
|
+
};
|
|
790
|
+
const source = createTiptapEditor({ element: sourceElement, content });
|
|
791
|
+
const destination = createTiptapEditor({ element: destinationElement });
|
|
792
|
+
editors.push(source, destination);
|
|
793
|
+
source.commands.selectAll();
|
|
794
|
+
const { dom } = source.view.serializeForClipboard(
|
|
795
|
+
source.state.selection.content(),
|
|
796
|
+
);
|
|
797
|
+
|
|
798
|
+
expect(
|
|
799
|
+
dom
|
|
800
|
+
.querySelector("[data-footnote-definition]")
|
|
801
|
+
?.getAttribute("data-footnote-label"),
|
|
802
|
+
).toBe("note");
|
|
803
|
+
|
|
804
|
+
dispatchMarkdownPaste(destination, "", dom.innerHTML);
|
|
805
|
+
|
|
806
|
+
expect(destination.getJSON()).toEqual(source.getJSON());
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
it("accepts the legacy display-form label in Jant editor HTML", () => {
|
|
810
|
+
const element = document.createElement("div");
|
|
811
|
+
document.body.appendChild(element);
|
|
812
|
+
const editor = createTiptapEditor({ element });
|
|
813
|
+
editors.push(editor);
|
|
814
|
+
|
|
815
|
+
dispatchMarkdownPaste(
|
|
816
|
+
editor,
|
|
817
|
+
"",
|
|
818
|
+
'<p>Body<sup data-footnote-reference data-footnote-label="1">[^1]</sup></p><div data-footnote-definition data-footnote-label="[^1]:"><p>Definition</p></div>',
|
|
819
|
+
);
|
|
820
|
+
|
|
821
|
+
expect(editor.getJSON().content?.[0]?.content?.[1]).toEqual({
|
|
822
|
+
type: "footnoteReference",
|
|
823
|
+
attrs: { label: "1" },
|
|
824
|
+
});
|
|
825
|
+
expect(editor.getJSON().content?.[1]?.attrs).toEqual({ label: "1" });
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
it("normalizes Obsidian inline footnotes into references and definitions", () => {
|
|
829
|
+
const element = document.createElement("div");
|
|
830
|
+
document.body.appendChild(element);
|
|
831
|
+
const editor = createTiptapEditor({ element });
|
|
832
|
+
editors.push(editor);
|
|
833
|
+
|
|
834
|
+
dispatchMarkdownPaste(
|
|
835
|
+
editor,
|
|
836
|
+
"Body^[Inline **bold** with [a source](https://example.com).]",
|
|
837
|
+
);
|
|
838
|
+
|
|
839
|
+
const json = editor.getJSON();
|
|
840
|
+
expect(json.content?.map((node) => node.type)).toEqual([
|
|
841
|
+
"paragraph",
|
|
842
|
+
"footnoteDefinition",
|
|
843
|
+
]);
|
|
844
|
+
expect(json.content?.[0]?.content?.[1]).toEqual({
|
|
845
|
+
type: "footnoteReference",
|
|
846
|
+
attrs: { label: "1" },
|
|
847
|
+
});
|
|
848
|
+
expect(json.content?.[1]?.attrs).toEqual({ label: "1" });
|
|
849
|
+
expect(JSON.stringify(json)).toContain('"type":"bold"');
|
|
850
|
+
expect(JSON.stringify(json)).toContain("https://example.com");
|
|
851
|
+
});
|
|
852
|
+
|
|
853
|
+
it("allocates inline footnote labels around existing definitions", () => {
|
|
854
|
+
const element = document.createElement("div");
|
|
855
|
+
document.body.appendChild(element);
|
|
856
|
+
const editor = createTiptapEditor({ element });
|
|
857
|
+
editors.push(editor);
|
|
858
|
+
|
|
859
|
+
dispatchMarkdownPaste(
|
|
860
|
+
editor,
|
|
861
|
+
"Named[^1] and inline^[Second definition.]\n\n[^1]: First definition.",
|
|
862
|
+
);
|
|
863
|
+
|
|
864
|
+
const json = editor.getJSON();
|
|
865
|
+
expect(
|
|
866
|
+
json.content
|
|
867
|
+
?.filter((node) => node.type === "footnoteDefinition")
|
|
868
|
+
.map((node) => node.attrs?.label),
|
|
869
|
+
).toEqual(["1", "2"]);
|
|
870
|
+
expect(json.content?.[0]?.content?.[3]).toEqual({
|
|
871
|
+
type: "footnoteReference",
|
|
872
|
+
attrs: { label: "2" },
|
|
873
|
+
});
|
|
874
|
+
});
|
|
875
|
+
|
|
153
876
|
it("keeps the formatting toolbar hidden for a selected footnote node", () => {
|
|
154
877
|
const element = document.createElement("div");
|
|
155
878
|
document.body.appendChild(element);
|