@deepseek-ai/dsh-client-ui-primitives 0.2.2-alpha.3 → 0.2.2-rc.2
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/README.i18n.yaml +16 -16
- package/README.md +21 -14
- package/README.zh.md +21 -14
- package/lib/HoverCard.module.css +8 -3
- package/lib/JsonTree.module.css +7 -17
- package/lib/Menu.module.css +157 -37
- package/lib/Modal.module.css +16 -0
- package/lib/QuotePreview.module.css +37 -0
- package/lib/RiskConfirmation.module.css +11 -37
- package/lib/Toast.module.css +2 -3
- package/lib/Tooltip.module.css +2 -1
- package/lib/index.js +1447 -776
- package/lib/index.js.map +1 -0
- package/lib/markdown/CodeBlock.module.css +64 -0
- package/lib/markdown/MarkdownText.module.css +20 -1
- package/lib/types/AnimatedRows.d.ts +3 -0
- package/lib/types/AnimatedRows.d.ts.map +1 -0
- package/lib/types/AnimatedRows.js.map +1 -0
- package/lib/types/BrandWordmark.d.ts.map +1 -0
- package/lib/types/BrandWordmark.js.map +1 -0
- package/lib/types/Button.d.ts.map +1 -0
- package/lib/types/Button.js.map +1 -0
- package/lib/types/Checkbox.d.ts +3 -1
- package/lib/types/Checkbox.d.ts.map +1 -0
- package/lib/types/Checkbox.js.map +1 -0
- package/lib/types/CodeFileIcon.d.ts.map +1 -0
- package/lib/types/CodeFileIcon.js.map +1 -0
- package/lib/types/CodeToolbar.d.ts.map +1 -0
- package/lib/types/CodeToolbar.js.map +1 -0
- package/lib/types/CommandText.d.ts.map +1 -0
- package/lib/types/CommandText.js.map +1 -0
- package/lib/types/ConfigField.d.ts.map +1 -0
- package/lib/types/ConfigField.js.map +1 -0
- package/lib/types/ConnectionIndicator.d.ts.map +1 -0
- package/lib/types/ConnectionIndicator.js.map +1 -0
- package/lib/types/DetailDocument.d.ts.map +1 -0
- package/lib/types/DetailDocument.js.map +1 -0
- package/lib/types/DiffBlock.d.ts.map +1 -0
- package/lib/types/DiffBlock.js.map +1 -0
- package/lib/types/DisclosureRow.d.ts.map +1 -0
- package/lib/types/DisclosureRow.js.map +1 -0
- package/lib/types/DraggableImage.d.ts.map +1 -0
- package/lib/types/DraggableImage.js.map +1 -0
- package/lib/types/FileTypeIcon.d.ts.map +1 -0
- package/lib/types/FileTypeIcon.js.map +1 -0
- package/lib/types/FishLogo.d.ts.map +1 -0
- package/lib/types/FishLogo.js.map +1 -0
- package/lib/types/FoldToggle.d.ts.map +1 -0
- package/lib/types/FoldToggle.js.map +1 -0
- package/lib/types/HoverCard.d.ts.map +1 -0
- package/lib/types/HoverCard.js.map +1 -0
- package/lib/types/HoverCardGroup.d.ts.map +1 -0
- package/lib/types/HoverCardGroup.js.map +1 -0
- package/lib/types/ImageLightbox.d.ts.map +1 -0
- package/lib/types/ImageLightbox.js.map +1 -0
- package/lib/types/ImagePreview.d.ts.map +1 -0
- package/lib/types/ImagePreview.js.map +1 -0
- package/lib/types/InlineEditor.d.ts.map +1 -0
- package/lib/types/InlineEditor.js.map +1 -0
- package/lib/types/Input.d.ts.map +1 -0
- package/lib/types/Input.js.map +1 -0
- package/lib/types/JsonTree.d.ts.map +1 -0
- package/lib/types/JsonTree.js.map +1 -0
- package/lib/types/LinkIcon.d.ts.map +1 -0
- package/lib/types/LinkIcon.js.map +1 -0
- package/lib/types/Menu.d.ts +26 -14
- package/lib/types/Menu.d.ts.map +1 -0
- package/lib/types/Menu.js.map +1 -0
- package/lib/types/MenuGroup.d.ts.map +1 -0
- package/lib/types/MenuGroup.js.map +1 -0
- package/lib/types/MenuRow.d.ts +37 -0
- package/lib/types/MenuRow.d.ts.map +1 -0
- package/lib/types/MenuRow.js.map +1 -0
- package/lib/types/MenuSurface.d.ts.map +1 -0
- package/lib/types/MenuSurface.js.map +1 -0
- package/lib/types/Modal.d.ts +3 -1
- package/lib/types/Modal.d.ts.map +1 -0
- package/lib/types/Modal.js.map +1 -0
- package/lib/types/PathLabel.d.ts.map +1 -0
- package/lib/types/PathLabel.js.map +1 -0
- package/lib/types/PermissionIcon.d.ts.map +1 -0
- package/lib/types/PermissionIcon.js.map +1 -0
- package/lib/types/Pill.d.ts.map +1 -0
- package/lib/types/Pill.js.map +1 -0
- package/lib/types/QuotePreview.d.ts +17 -4
- package/lib/types/QuotePreview.d.ts.map +1 -0
- package/lib/types/QuotePreview.js.map +1 -0
- package/lib/types/ReadBlock.d.ts.map +1 -0
- package/lib/types/ReadBlock.js.map +1 -0
- package/lib/types/ReferenceIcon.d.ts.map +1 -0
- package/lib/types/ReferenceIcon.js.map +1 -0
- package/lib/types/RiskConfirmation.d.ts.map +1 -0
- package/lib/types/RiskConfirmation.js.map +1 -0
- package/lib/types/SearchBlock.d.ts.map +1 -0
- package/lib/types/SearchBlock.js.map +1 -0
- package/lib/types/SegmentedControl.d.ts.map +1 -0
- package/lib/types/SegmentedControl.js.map +1 -0
- package/lib/types/SegmentedTabs.d.ts.map +1 -0
- package/lib/types/SegmentedTabs.js.map +1 -0
- package/lib/types/ShortcutKeys.d.ts.map +1 -0
- package/lib/types/ShortcutKeys.js.map +1 -0
- package/lib/types/SiteGlyph.d.ts.map +1 -0
- package/lib/types/SiteGlyph.js.map +1 -0
- package/lib/types/StateDot.d.ts.map +1 -0
- package/lib/types/StateDot.js.map +1 -0
- package/lib/types/SubmenuPanel.d.ts +19 -0
- package/lib/types/SubmenuPanel.d.ts.map +1 -0
- package/lib/types/SubmenuPanel.js.map +1 -0
- package/lib/types/Switch.d.ts.map +1 -0
- package/lib/types/Switch.js.map +1 -0
- package/lib/types/Tag.d.ts.map +1 -0
- package/lib/types/Tag.js.map +1 -0
- package/lib/types/TerminalBlock.d.ts.map +1 -0
- package/lib/types/TerminalBlock.js.map +1 -0
- package/lib/types/TextShimmer.d.ts.map +1 -0
- package/lib/types/TextShimmer.js.map +1 -0
- package/lib/types/Toast.d.ts.map +1 -0
- package/lib/types/Toast.js.map +1 -0
- package/lib/types/Tooltip.d.ts.map +1 -0
- package/lib/types/Tooltip.js.map +1 -0
- package/lib/types/UserMessageBubble.d.ts.map +1 -0
- package/lib/types/UserMessageBubble.js.map +1 -0
- package/lib/types/WebBlock.d.ts.map +1 -0
- package/lib/types/WebBlock.js.map +1 -0
- package/lib/types/ZoomControls.d.ts.map +1 -0
- package/lib/types/ZoomControls.js.map +1 -0
- package/lib/types/ansi.d.ts.map +1 -0
- package/lib/types/ansi.js.map +1 -0
- package/lib/types/clipboard.d.ts.map +1 -0
- package/lib/types/clipboard.js.map +1 -0
- package/lib/types/code-file-icon-artwork.d.ts.map +1 -0
- package/lib/types/code-file-icon-artwork.js.map +1 -0
- package/lib/types/code-file-types.d.ts.map +1 -0
- package/lib/types/code-file-types.js.map +1 -0
- package/lib/types/code-highlighting.d.ts.map +1 -0
- package/lib/types/code-highlighting.js.map +1 -0
- package/lib/types/darwin-desktop.d.ts.map +1 -0
- package/lib/types/darwin-desktop.js.map +1 -0
- package/lib/types/document-zoom.d.ts.map +1 -0
- package/lib/types/document-zoom.js.map +1 -0
- package/lib/types/file-drag-actions.d.ts.map +1 -0
- package/lib/types/file-drag-actions.js.map +1 -0
- package/lib/types/file-size.d.ts.map +1 -0
- package/lib/types/file-size.js.map +1 -0
- package/lib/types/focus.d.ts.map +1 -0
- package/lib/types/focus.js.map +1 -0
- package/lib/types/guide-artwork.d.ts.map +1 -0
- package/lib/types/guide-artwork.js.map +1 -0
- package/lib/types/head-tail-cap.d.ts.map +1 -0
- package/lib/types/head-tail-cap.js.map +1 -0
- package/lib/types/icons/artwork.d.ts +12 -0
- package/lib/types/icons/artwork.d.ts.map +1 -0
- package/lib/types/icons/artwork.js.map +1 -0
- package/lib/types/icons/index.d.ts +12 -0
- package/lib/types/icons/index.d.ts.map +1 -0
- package/lib/types/icons/index.js.map +1 -0
- package/lib/types/icons/props.d.ts.map +1 -0
- package/lib/types/icons/props.js.map +1 -0
- package/lib/types/icons/shared-artwork.d.ts.map +1 -0
- package/lib/types/icons/shared-artwork.js.map +1 -0
- package/lib/types/image-drag.d.ts.map +1 -0
- package/lib/types/image-drag.js.map +1 -0
- package/lib/types/index.d.ts +5 -4
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/input-modality.d.ts.map +1 -0
- package/lib/types/input-modality.js.map +1 -0
- package/lib/types/keyboard-composition.d.ts.map +1 -0
- package/lib/types/keyboard-composition.js.map +1 -0
- package/lib/types/markdown/CodeBlock.d.ts +8 -1
- package/lib/types/markdown/CodeBlock.d.ts.map +1 -0
- package/lib/types/markdown/CodeBlock.js.map +1 -0
- package/lib/types/markdown/FenceBlocks.d.ts +31 -0
- package/lib/types/markdown/FenceBlocks.d.ts.map +1 -0
- package/lib/types/markdown/FenceBlocks.js.map +1 -0
- package/lib/types/markdown/JsonBlock.d.ts.map +1 -0
- package/lib/types/markdown/JsonBlock.js.map +1 -0
- package/lib/types/markdown/MarkdownDelegate.d.ts +23 -1
- package/lib/types/markdown/MarkdownDelegate.d.ts.map +1 -0
- package/lib/types/markdown/MarkdownDelegate.js.map +1 -0
- package/lib/types/markdown/MarkdownText.d.ts +2 -0
- package/lib/types/markdown/MarkdownText.d.ts.map +1 -0
- package/lib/types/markdown/MarkdownText.js.map +1 -0
- package/lib/types/markdown/cjkFriendlyStrong.d.ts.map +1 -0
- package/lib/types/markdown/cjkFriendlyStrong.js.map +1 -0
- package/lib/types/markdown/copy-tex.d.ts +14 -0
- package/lib/types/markdown/copy-tex.d.ts.map +1 -0
- package/lib/types/markdown/copy-tex.js.map +1 -0
- package/lib/types/markdown/diff-fence.d.ts +58 -0
- package/lib/types/markdown/diff-fence.d.ts.map +1 -0
- package/lib/types/markdown/diff-fence.js.map +1 -0
- package/lib/types/markdown/file-link.d.ts.map +1 -0
- package/lib/types/markdown/file-link.js.map +1 -0
- package/lib/types/markdown/highlight.d.ts +18 -0
- package/lib/types/markdown/highlight.d.ts.map +1 -0
- package/lib/types/markdown/highlight.js.map +1 -0
- package/lib/types/markdown/incremental.d.ts.map +1 -0
- package/lib/types/markdown/incremental.js.map +1 -0
- package/lib/types/markdown/katex.d.ts.map +1 -0
- package/lib/types/markdown/katex.js.map +1 -0
- package/lib/types/markdown/local-image-syntax.d.ts.map +1 -0
- package/lib/types/markdown/local-image-syntax.js.map +1 -0
- package/lib/types/markdown/mathCompatibility.d.ts.map +1 -0
- package/lib/types/markdown/mathCompatibility.js.map +1 -0
- package/lib/types/markdown/parse.d.ts.map +1 -0
- package/lib/types/markdown/parse.js.map +1 -0
- package/lib/types/markdown/plain-text.d.ts.map +1 -0
- package/lib/types/markdown/plain-text.js.map +1 -0
- package/lib/types/markdown/quote-text.d.ts.map +1 -0
- package/lib/types/markdown/quote-text.js.map +1 -0
- package/lib/types/markdown/render.d.ts.map +1 -0
- package/lib/types/markdown/render.js.map +1 -0
- package/lib/types/markdown/useViewportHighlighting.d.ts.map +1 -0
- package/lib/types/markdown/useViewportHighlighting.js.map +1 -0
- package/lib/types/markdown/windows-path-destinations.d.ts.map +1 -0
- package/lib/types/markdown/windows-path-destinations.js.map +1 -0
- package/lib/types/menu-submenu-position.d.ts +15 -0
- package/lib/types/menu-submenu-position.d.ts.map +1 -0
- package/lib/types/menu-submenu-position.js.map +1 -0
- package/lib/types/overlay-top-margin.d.ts.map +1 -0
- package/lib/types/overlay-top-margin.js.map +1 -0
- package/lib/types/plugin-artwork.d.ts.map +1 -0
- package/lib/types/plugin-artwork.js.map +1 -0
- package/lib/types/pointer-grace.d.ts.map +1 -0
- package/lib/types/pointer-grace.js.map +1 -0
- package/lib/types/rank-by-name.d.ts.map +1 -0
- package/lib/types/rank-by-name.js.map +1 -0
- package/lib/types/relative-time.d.ts.map +1 -0
- package/lib/types/relative-time.js.map +1 -0
- package/lib/types/settings-form/SettingsForm.d.ts.map +1 -0
- package/lib/types/settings-form/SettingsForm.js.map +1 -0
- package/lib/types/settings-form/fields.d.ts.map +1 -0
- package/lib/types/settings-form/fields.js.map +1 -0
- package/lib/types/settings-form/form-model.d.ts.map +1 -0
- package/lib/types/settings-form/form-model.js.map +1 -0
- package/lib/types/tooltip-placement.d.ts.map +1 -0
- package/lib/types/tooltip-placement.js.map +1 -0
- package/lib/types/use-clipboard-copy.d.ts.map +1 -0
- package/lib/types/use-clipboard-copy.js.map +1 -0
- package/lib/types/useAnchoredMaxHeight.d.ts.map +1 -0
- package/lib/types/useAnchoredMaxHeight.js.map +1 -0
- package/lib/types/useDismissOnOutsidePointer.d.ts.map +1 -0
- package/lib/types/useDismissOnOutsidePointer.js.map +1 -0
- package/lib/types/useMenuSubmenu.d.ts +43 -0
- package/lib/types/useMenuSubmenu.d.ts.map +1 -0
- package/lib/types/useMenuSubmenu.js.map +1 -0
- package/lib/types/useModalLayer.d.ts.map +1 -0
- package/lib/types/useModalLayer.js.map +1 -0
- package/lib/types/useRowDragPreview.d.ts.map +1 -0
- package/lib/types/useRowDragPreview.js.map +1 -0
- package/lib/types/user-text.d.ts.map +1 -0
- package/lib/types/user-text.js.map +1 -0
- package/package.json +11 -8
- package/src/AnimatedRows.module.css +7 -0
- package/src/AnimatedRows.tsx +195 -0
- package/src/BrandWordmark.tsx +59 -0
- package/src/Button.module.css +84 -0
- package/src/Button.tsx +36 -0
- package/src/Checkbox.module.css +28 -0
- package/src/Checkbox.tsx +34 -0
- package/src/CodeCard.module.css +85 -0
- package/src/CodeFileIcon.tsx +28 -0
- package/src/CodeToolbar.tsx +62 -0
- package/src/CommandText.module.css +12 -0
- package/src/CommandText.tsx +46 -0
- package/src/ConfigField.module.css +12 -0
- package/src/ConfigField.tsx +53 -0
- package/src/ConnectionIndicator.module.css +120 -0
- package/src/ConnectionIndicator.tsx +103 -0
- package/src/DetailDocument.module.css +67 -0
- package/src/DetailDocument.tsx +120 -0
- package/src/DiffBlock.module.css +82 -0
- package/src/DiffBlock.tsx +221 -0
- package/src/DisclosureRow.module.css +115 -0
- package/src/DisclosureRow.tsx +124 -0
- package/src/DraggableImage.tsx +26 -0
- package/src/FileTypeIcon.module.css +50 -0
- package/src/FileTypeIcon.tsx +285 -0
- package/src/FishLogo.tsx +28 -0
- package/src/FoldToggle.tsx +33 -0
- package/src/HoverCard.module.css +108 -0
- package/src/HoverCard.tsx +356 -0
- package/src/HoverCardGroup.tsx +77 -0
- package/src/ImageLightbox.module.css +54 -0
- package/src/ImageLightbox.tsx +72 -0
- package/src/ImagePreview.module.css +24 -0
- package/src/ImagePreview.tsx +36 -0
- package/src/InlineEditor.module.css +23 -0
- package/src/InlineEditor.tsx +69 -0
- package/src/Input.module.css +38 -0
- package/src/Input.tsx +24 -0
- package/src/JsonTree.module.css +371 -0
- package/src/JsonTree.tsx +850 -0
- package/src/LinkIcon.tsx +118 -0
- package/src/Menu.module.css +443 -0
- package/src/Menu.tsx +553 -0
- package/src/MenuGroup.module.css +37 -0
- package/src/MenuGroup.tsx +103 -0
- package/src/MenuRow.tsx +89 -0
- package/src/MenuSurface.module.css +65 -0
- package/src/MenuSurface.tsx +54 -0
- package/src/Modal.module.css +147 -0
- package/src/Modal.tsx +96 -0
- package/src/PathLabel.module.css +28 -0
- package/src/PathLabel.tsx +41 -0
- package/src/PermissionIcon.tsx +119 -0
- package/src/Pill.module.css +30 -0
- package/src/Pill.tsx +36 -0
- package/src/QuotePreview.module.css +138 -0
- package/src/QuotePreview.tsx +133 -0
- package/src/ReadBlock.module.css +45 -0
- package/src/ReadBlock.tsx +151 -0
- package/src/ReferenceIcon.tsx +49 -0
- package/src/RiskConfirmation.module.css +47 -0
- package/src/RiskConfirmation.tsx +79 -0
- package/src/RowDragPreview.module.css +12 -0
- package/src/SearchBlock.module.css +114 -0
- package/src/SearchBlock.tsx +281 -0
- package/src/SegmentedControl.module.css +81 -0
- package/src/SegmentedControl.tsx +140 -0
- package/src/SegmentedTabs.module.css +77 -0
- package/src/SegmentedTabs.tsx +84 -0
- package/src/ShortcutKeys.module.css +33 -0
- package/src/ShortcutKeys.tsx +12 -0
- package/src/SiteGlyph.tsx +149 -0
- package/src/StateDot.module.css +100 -0
- package/src/StateDot.tsx +77 -0
- package/src/SubmenuPanel.tsx +51 -0
- package/src/Switch.module.css +49 -0
- package/src/Switch.tsx +42 -0
- package/src/Tag.module.css +57 -0
- package/src/Tag.tsx +42 -0
- package/src/TerminalBlock.module.css +207 -0
- package/src/TerminalBlock.tsx +294 -0
- package/src/TextShimmer.module.css +88 -0
- package/src/TextShimmer.tsx +58 -0
- package/src/Toast.module.css +102 -0
- package/src/Toast.tsx +101 -0
- package/src/Tooltip.module.css +68 -0
- package/src/Tooltip.tsx +273 -0
- package/src/UserMessageBubble.module.css +11 -0
- package/src/UserMessageBubble.tsx +16 -0
- package/src/WebBlock.module.css +153 -0
- package/src/WebBlock.tsx +196 -0
- package/src/ZoomControls.module.css +54 -0
- package/src/ZoomControls.tsx +92 -0
- package/src/ansi.ts +447 -0
- package/src/clipboard.ts +47 -0
- package/src/code-file-icon-artwork.manifest.json +71 -0
- package/src/code-file-icon-artwork.ts +60 -0
- package/src/code-file-types.ts +340 -0
- package/src/code-highlighting.ts +25 -0
- package/src/css-modules.d.ts +6 -0
- package/src/darwin-desktop.ts +11 -0
- package/src/document-zoom.ts +12 -0
- package/src/file-drag-actions.ts +29 -0
- package/src/file-size.ts +16 -0
- package/src/focus.ts +44 -0
- package/src/guide-artwork.tsx +32 -0
- package/src/head-tail-cap.ts +27 -0
- package/src/icons/artwork.ts +156 -0
- package/src/icons/index.tsx +634 -0
- package/src/icons/props.ts +8 -0
- package/src/icons/shared-artwork.tsx +71 -0
- package/src/image-drag.ts +84 -0
- package/src/index.ts +142 -0
- package/src/input-modality.ts +59 -0
- package/src/keyboard-composition.ts +36 -0
- package/src/markdown/CodeBlock.module.css +209 -0
- package/src/markdown/CodeBlock.tsx +268 -0
- package/src/markdown/FenceBlocks.tsx +51 -0
- package/src/markdown/JsonBlock.module.css +34 -0
- package/src/markdown/JsonBlock.tsx +36 -0
- package/src/markdown/MarkdownDelegate.tsx +102 -0
- package/src/markdown/MarkdownText.module.css +511 -0
- package/src/markdown/MarkdownText.tsx +218 -0
- package/src/markdown/cjkFriendlyStrong.ts +83 -0
- package/src/markdown/copy-tex.ts +53 -0
- package/src/markdown/diff-fence.ts +212 -0
- package/src/markdown/file-link.ts +45 -0
- package/src/markdown/highlight.ts +689 -0
- package/src/markdown/incremental.ts +360 -0
- package/src/markdown/katex.tsx +90 -0
- package/src/markdown/local-image-syntax.ts +29 -0
- package/src/markdown/mathCompatibility.ts +349 -0
- package/src/markdown/parse.ts +49 -0
- package/src/markdown/plain-text.ts +121 -0
- package/src/markdown/quote-text.ts +10 -0
- package/src/markdown/render.tsx +834 -0
- package/src/markdown/useViewportHighlighting.ts +72 -0
- package/src/markdown/windows-path-destinations.ts +34 -0
- package/src/menu-submenu-position.ts +20 -0
- package/src/overlay-top-margin.ts +18 -0
- package/src/plugin-artwork.tsx +110 -0
- package/src/pointer-grace.ts +47 -0
- package/src/rank-by-name.ts +93 -0
- package/src/relative-time.ts +36 -0
- package/src/settings-form/SettingsForm.module.css +53 -0
- package/src/settings-form/SettingsForm.tsx +74 -0
- package/src/settings-form/fields.module.css +153 -0
- package/src/settings-form/fields.tsx +151 -0
- package/src/settings-form/form-model.ts +393 -0
- package/src/tooltip-placement.ts +60 -0
- package/src/use-clipboard-copy.ts +44 -0
- package/src/useAnchoredMaxHeight.ts +45 -0
- package/src/useDismissOnOutsidePointer.ts +34 -0
- package/src/useMenuSubmenu.ts +182 -0
- package/src/useModalLayer.ts +108 -0
- package/src/useRowDragPreview.ts +76 -0
- package/src/user-text.module.css +46 -0
- package/src/user-text.tsx +67 -0
- package/lib/types/useAnchoredPosition.d.ts +0 -36
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Direct mdast→React markdown renderer. Replaces the react-markdown /
|
|
3
|
+
* remark-rehype pipeline with one switch over parsed nodes so streaming can
|
|
4
|
+
* cache frozen blocks as React elements; the rendered DOM is pinned
|
|
5
|
+
* byte-for-byte by `tests/fixtures/markdown-dom` and must not drift.
|
|
6
|
+
*
|
|
7
|
+
* External links reject executable and embedded-document protocols; settled
|
|
8
|
+
* local file links use an explicit owner callback. Images additionally require
|
|
9
|
+
* absolute HTTP(S), raw HTML renders as literal text (no HTML enters the
|
|
10
|
+
* DOM), and KaTeX runs without trusted commands. Fragment-only URLs are not
|
|
11
|
+
* absolute, so footnote references and back-references render as plain
|
|
12
|
+
* text rather than in-page links.
|
|
13
|
+
*
|
|
14
|
+
* Merge-extensible node unions fall through the documented default (render
|
|
15
|
+
* nothing) rather than ending in assertNever: grammars registered elsewhere
|
|
16
|
+
* may add node types this renderer has no mapping for.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { HTMLAttributes } from 'react'
|
|
20
|
+
import { Fragment, createElement, useCallback, useState } from 'react'
|
|
21
|
+
import type { Key, ReactNode } from 'react'
|
|
22
|
+
import clsx from 'clsx'
|
|
23
|
+
import type * as Md from 'mdast'
|
|
24
|
+
import type {} from 'mdast-util-math'
|
|
25
|
+
import { normalizeUri } from 'micromark-util-sanitize-uri'
|
|
26
|
+
import type { CodeToolbarLabels } from '../CodeToolbar.tsx'
|
|
27
|
+
import { FenceCodeBlock, FenceMathBlock } from './FenceBlocks.tsx'
|
|
28
|
+
import { isExplicitFilePath, parseFileLink } from './file-link.ts'
|
|
29
|
+
import { renderTexToReact } from './katex.tsx'
|
|
30
|
+
import { LinkIconMedium, classifyLinkPath } from '../LinkIcon.tsx'
|
|
31
|
+
import { useMarkdownDelegate } from './MarkdownDelegate.tsx'
|
|
32
|
+
import { HoverCard } from '../HoverCard.tsx'
|
|
33
|
+
import { DraggableImage } from '../DraggableImage.tsx'
|
|
34
|
+
import { ImageLightbox } from '../ImageLightbox.tsx'
|
|
35
|
+
import { ImagePreview } from '../ImagePreview.tsx'
|
|
36
|
+
import type { PositionedBlock } from './incremental.ts'
|
|
37
|
+
import css from './MarkdownText.module.css'
|
|
38
|
+
|
|
39
|
+
/** Copy-button labels forwarded to fence CodeBlocks (this package is cordis-free, so copy arrives via props). */
|
|
40
|
+
export interface MarkdownCodeLabels {
|
|
41
|
+
/** Copy-button idle label. */
|
|
42
|
+
copyLabel: string
|
|
43
|
+
/** Copy-button label during the post-copy confirmation window. */
|
|
44
|
+
copiedLabel: string
|
|
45
|
+
/** Shared card controls; omitted for custom toolbar layouts. */
|
|
46
|
+
toolbarLabels?: CodeToolbarLabels | undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Localized chrome for a Markdown document. */
|
|
50
|
+
export interface MarkdownLabels {
|
|
51
|
+
code: MarkdownCodeLabels
|
|
52
|
+
footnotes: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function sanitizeUrl(url: string): string {
|
|
56
|
+
if (isExplicitFilePath(url)) return ''
|
|
57
|
+
try {
|
|
58
|
+
switch (new URL(url).protocol) {
|
|
59
|
+
case 'javascript:':
|
|
60
|
+
case 'vbscript:':
|
|
61
|
+
case 'data:':
|
|
62
|
+
case 'blob:':
|
|
63
|
+
return ''
|
|
64
|
+
default:
|
|
65
|
+
return url
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
// Relative and otherwise unparsable destinations are disallowed alongside
|
|
69
|
+
// disallowed protocols; new URL() has no other failure mode for strings.
|
|
70
|
+
return ''
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function remoteImageUrl(url: string): string | undefined {
|
|
75
|
+
try {
|
|
76
|
+
const protocol = new URL(url).protocol
|
|
77
|
+
return protocol === 'http:' || protocol === 'https:' ? url : undefined
|
|
78
|
+
} catch {
|
|
79
|
+
// Same single failure mode as above: not an absolute URL.
|
|
80
|
+
return undefined
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Authenticated Host media routes as the Desktop application addresses them. */
|
|
85
|
+
const DESKTOP_MEDIA_ROUTES = [
|
|
86
|
+
'dsh-app://app/api/file?', 'dsh-app://app/api/plugin-market/detail-file?', 'dsh-app://app/api/plugin-manager/detail-file?',
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
/** Rewritten images may use Web media protocols or the Desktop application's media routes. */
|
|
90
|
+
function vocabularyImageUrl(url: string): string | undefined {
|
|
91
|
+
try {
|
|
92
|
+
const protocol = new URL(url).protocol
|
|
93
|
+
return protocol === 'http:' || protocol === 'https:' || protocol === 'blob:' || protocol === 'data:'
|
|
94
|
+
|| DESKTOP_MEDIA_ROUTES.some(route => url.startsWith(route))
|
|
95
|
+
? url
|
|
96
|
+
: undefined
|
|
97
|
+
} catch {
|
|
98
|
+
// A vocabulary result must be an absolute URL; anything else stays a miss.
|
|
99
|
+
return undefined
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The displayable source for one image destination: absolute HTTP(S) as
|
|
105
|
+
* authored, otherwise the context's local-path vocabulary when it vouches for
|
|
106
|
+
* the destination. Either miss leaves the authored fallback (alt text) to the
|
|
107
|
+
* caller.
|
|
108
|
+
* @param url - The authored markdown destination.
|
|
109
|
+
* @param pathImages - Rewriting vocabulary, when the render pass has one.
|
|
110
|
+
* @param load - The mounted image's load number for rewritten URLs.
|
|
111
|
+
* @returns The displayable image URL, or undefined.
|
|
112
|
+
*/
|
|
113
|
+
function imageSource(url: string, pathImages: MarkdownPathImages | undefined, load: number): string | undefined {
|
|
114
|
+
const remote = remoteImageUrl(sanitizeUrl(normalizeUri(url)))
|
|
115
|
+
if (remote !== undefined) return remote
|
|
116
|
+
const rewritten = pathImages?.resolve(url)
|
|
117
|
+
const allowed = rewritten === undefined ? undefined : vocabularyImageUrl(rewritten)
|
|
118
|
+
return allowed === undefined ? undefined : freshImageUrl(allowed, load)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// A module counter, not useId: useId derives from tree position, so images at
|
|
122
|
+
// the same position in two sessions would share a URL.
|
|
123
|
+
let imageLoads = 0
|
|
124
|
+
const nextImageLoad = (): number => ++imageLoads
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Tag a Host file-route image URL with its mount's load number. Browsers reuse
|
|
128
|
+
* a same-URL image within one document despite `no-store`, so without the tag
|
|
129
|
+
* a newly rendered image of a rewritten file would show the earlier bytes.
|
|
130
|
+
* @param url - Absolute resolved image URL; URLs outside the `api/file` route stay unchanged.
|
|
131
|
+
* @param load - Number allocated once per mounted image or file link.
|
|
132
|
+
* @returns The URL with a `load` query parameter, or the unchanged URL.
|
|
133
|
+
*/
|
|
134
|
+
function freshImageUrl(url: string, load: number): string {
|
|
135
|
+
let fresh: URL
|
|
136
|
+
try { fresh = new URL(url) }
|
|
137
|
+
catch { return url } // Only an unparsable owner-supplied URL throws; it is emitted as before.
|
|
138
|
+
if (!fresh.pathname.endsWith('/api/file')) return url
|
|
139
|
+
// Appending preserves the resolver's existing query encoding.
|
|
140
|
+
fresh.search = `${fresh.search === '' ? '?' : `${fresh.search}&`}load=${load}`
|
|
141
|
+
return fresh.href
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Link/image reference targets collected from a document (first definition per identifier wins, as in CommonMark). */
|
|
145
|
+
export interface ReferenceTargets {
|
|
146
|
+
/** Link/image definitions keyed by upper-cased identifier. */
|
|
147
|
+
definitions: Map<string, Md.Definition>
|
|
148
|
+
/** Footnote definitions keyed by upper-cased identifier. */
|
|
149
|
+
footnotes: Map<string, Md.FootnoteDefinition>
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Create an empty {@link ReferenceTargets}.
|
|
154
|
+
* @returns Fresh empty maps.
|
|
155
|
+
*/
|
|
156
|
+
export function createReferenceTargets(): ReferenceTargets {
|
|
157
|
+
return { definitions: new Map(), footnotes: new Map() }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Record every definition and footnote definition under `nodes` into
|
|
162
|
+
* `targets`, depth-first, keeping the first definition per identifier.
|
|
163
|
+
* @param nodes - Subtrees to walk (top-level blocks or any nested children).
|
|
164
|
+
* @param targets - Accumulator, typically shared across incremental segments.
|
|
165
|
+
*/
|
|
166
|
+
export function collectReferenceTargets(
|
|
167
|
+
nodes: readonly Md.RootContent[],
|
|
168
|
+
targets: ReferenceTargets,
|
|
169
|
+
): void {
|
|
170
|
+
for (const node of nodes) {
|
|
171
|
+
if (node.type === 'definition') {
|
|
172
|
+
const id = node.identifier.toUpperCase()
|
|
173
|
+
if (!targets.definitions.has(id)) targets.definitions.set(id, node)
|
|
174
|
+
} else if (node.type === 'footnoteDefinition') {
|
|
175
|
+
const id = node.identifier.toUpperCase()
|
|
176
|
+
if (!targets.footnotes.has(id)) targets.footnotes.set(id, node)
|
|
177
|
+
}
|
|
178
|
+
if ('children' in node) collectReferenceTargets(node.children, targets)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Local-path image vocabulary for image destinations: the owner maps an
|
|
184
|
+
* authored destination that fails the remote-URL allowlist (an absolute local
|
|
185
|
+
* file path, for example) to a displayable URL it can vouch for. Absent
|
|
186
|
+
* wherever no such vocabulary exists, authored local destinations keep their
|
|
187
|
+
* documented fallback (the image's alt text). Rewritten destinations must be
|
|
188
|
+
* absolute; the renderer re-checks their protocol before emitting them.
|
|
189
|
+
*/
|
|
190
|
+
export interface MarkdownPathImages {
|
|
191
|
+
/**
|
|
192
|
+
* Resolve one authored image destination.
|
|
193
|
+
* @param value - The destination exactly as the markdown author wrote it.
|
|
194
|
+
* @returns A displayable absolute URL, or undefined when the destination
|
|
195
|
+
* names no displayable image — it then stays inert alt text. The renderer
|
|
196
|
+
* appends a per-mount `load` query parameter to `api/file` route results.
|
|
197
|
+
*/
|
|
198
|
+
resolve(value: string): string | undefined
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* File-mention affordance for inline code: the owner resolves an authored
|
|
203
|
+
* token to the file it names, using its own vocabulary of real files — the
|
|
204
|
+
* renderer never guesses at what looks like a path.
|
|
205
|
+
*/
|
|
206
|
+
export interface MarkdownFileMentions {
|
|
207
|
+
/**
|
|
208
|
+
* Resolve one inline-code token.
|
|
209
|
+
* @param value - The authored token, exactly as written.
|
|
210
|
+
* @returns The opener with its accessible label and full-path title, or
|
|
211
|
+
* undefined when the token names no known file — it then stays inert code.
|
|
212
|
+
*/
|
|
213
|
+
resolve(value: string): {
|
|
214
|
+
open: () => void
|
|
215
|
+
contextMenuProps?: Pick<HTMLAttributes<HTMLElement>, 'onContextMenu' | 'onKeyDown' | 'tabIndex'>
|
|
216
|
+
label: string
|
|
217
|
+
title: string
|
|
218
|
+
} | undefined
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* One render pass's state: immutable options and targets plus the footnote
|
|
223
|
+
* numbering accumulated in document order while references render.
|
|
224
|
+
*/
|
|
225
|
+
export interface MarkdownRenderContext {
|
|
226
|
+
/** Streaming arm: fences highlight incrementally as they grow; TeX (including ```math fences) stays literal until the settled pass. */
|
|
227
|
+
readonly streaming: boolean
|
|
228
|
+
/** Localized fence copy-button labels. */
|
|
229
|
+
readonly labels: MarkdownLabels
|
|
230
|
+
/** Inside a blockquote's children: tables there always fill the quote's width. */
|
|
231
|
+
readonly inBlockquote?: boolean
|
|
232
|
+
/** Inline-code file mentions; absent wherever no opener vocabulary exists. */
|
|
233
|
+
readonly fileMentions: MarkdownFileMentions | undefined
|
|
234
|
+
/** Local-path image vocabulary; absent wherever no rewriting owner exists. */
|
|
235
|
+
readonly pathImages: MarkdownPathImages | undefined
|
|
236
|
+
/** Raw HTML renders nothing instead of literal text. */
|
|
237
|
+
readonly omitHtml: boolean
|
|
238
|
+
/** Inside an anchor's children: interactive mentions must not nest there. */
|
|
239
|
+
readonly inLink?: boolean
|
|
240
|
+
/** Reference targets visible to this pass. */
|
|
241
|
+
readonly targets: ReferenceTargets
|
|
242
|
+
/** Footnote identifiers in first-reference order; a footnote's number is its 1-based index here. */
|
|
243
|
+
readonly footnoteOrder: string[]
|
|
244
|
+
/** References rendered per identifier; drives the section's back-reference count. */
|
|
245
|
+
readonly footnoteCounts: Map<string, number>
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Render top-level blocks. Nodes that render nothing (definitions, unmapped
|
|
250
|
+
* types) are dropped rather than kept as null placeholders, matching the
|
|
251
|
+
* replaced pipeline's child lists so separator newlines land identically.
|
|
252
|
+
* @param blocks - Blocks with their stream-stable render keys.
|
|
253
|
+
* @param context - The pass state; footnote numbering mutates in document order.
|
|
254
|
+
* @returns One React node per rendered block.
|
|
255
|
+
*/
|
|
256
|
+
export function renderBlocks(
|
|
257
|
+
blocks: readonly PositionedBlock[],
|
|
258
|
+
context: MarkdownRenderContext,
|
|
259
|
+
): ReactNode[] {
|
|
260
|
+
return blocks
|
|
261
|
+
.map(block => renderNode(block.node, block.key, context))
|
|
262
|
+
.filter(element => element !== null)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Interleave the newline text nodes the replaced pipeline emitted between
|
|
267
|
+
* block-level children. They are invisible between elements but coalesce
|
|
268
|
+
* into adjacent literal raw-HTML text, where the DOM parity fixtures pin
|
|
269
|
+
* them.
|
|
270
|
+
* @param elements - Rendered block children with empty renders already dropped.
|
|
271
|
+
* @param edges - Also emit the leading and trailing newline (hast's loose wrap).
|
|
272
|
+
* @returns The interleaved children.
|
|
273
|
+
*/
|
|
274
|
+
export function wrapBlockChildren(elements: readonly ReactNode[], edges: boolean): ReactNode[] {
|
|
275
|
+
const wrapped: ReactNode[] = []
|
|
276
|
+
for (const element of elements) {
|
|
277
|
+
if (edges || wrapped.length > 0) wrapped.push('\n')
|
|
278
|
+
wrapped.push(element)
|
|
279
|
+
}
|
|
280
|
+
if (edges && elements.length > 0) wrapped.push('\n')
|
|
281
|
+
return wrapped
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* A block child rendered for a parent that must tell paragraphs apart from
|
|
286
|
+
* other blocks (list items unwrap them when tight; footnote bodies receive
|
|
287
|
+
* their back-references inside the trailing paragraph).
|
|
288
|
+
*/
|
|
289
|
+
type BlockEntry = { paragraph: ReactNode[] } | { element: ReactNode }
|
|
290
|
+
|
|
291
|
+
/** Render container children into {@link BlockEntry} values, dropping empty renders. */
|
|
292
|
+
function renderBlockEntries(
|
|
293
|
+
blocks: readonly Md.RootContent[],
|
|
294
|
+
context: MarkdownRenderContext,
|
|
295
|
+
): BlockEntry[] {
|
|
296
|
+
const entries: BlockEntry[] = []
|
|
297
|
+
for (const [index, block] of blocks.entries()) {
|
|
298
|
+
if (block.type === 'paragraph') {
|
|
299
|
+
entries.push({ paragraph: renderChildren(block.children, context) })
|
|
300
|
+
} else {
|
|
301
|
+
const element = renderNode(block, index, context)
|
|
302
|
+
if (element !== null) entries.push({ element })
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return entries
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function renderChildren(
|
|
309
|
+
nodes: readonly Md.RootContent[],
|
|
310
|
+
context: MarkdownRenderContext,
|
|
311
|
+
): ReactNode[] {
|
|
312
|
+
return nodes.map((node, index) => renderNode(node, index, context))
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function renderNode(node: Md.RootContent, key: Key, context: MarkdownRenderContext): ReactNode {
|
|
316
|
+
switch (node.type) {
|
|
317
|
+
case 'text':
|
|
318
|
+
return node.value
|
|
319
|
+
case 'paragraph':
|
|
320
|
+
return <p key={key}>{renderChildren(node.children, context)}</p>
|
|
321
|
+
case 'heading':
|
|
322
|
+
return createElement(`h${node.depth}`, { key }, ...renderChildren(node.children, context))
|
|
323
|
+
case 'blockquote':
|
|
324
|
+
return (
|
|
325
|
+
<blockquote key={key}>
|
|
326
|
+
{wrapBlockChildren(
|
|
327
|
+
renderChildren(node.children, { ...context, inBlockquote: true }).filter(child => child !== null),
|
|
328
|
+
true,
|
|
329
|
+
)}
|
|
330
|
+
</blockquote>
|
|
331
|
+
)
|
|
332
|
+
case 'thematicBreak':
|
|
333
|
+
return <hr key={key} />
|
|
334
|
+
case 'break':
|
|
335
|
+
// The replaced pipeline emitted a newline text node after each <br>.
|
|
336
|
+
return <Fragment key={key}><br />{'\n'}</Fragment>
|
|
337
|
+
case 'strong':
|
|
338
|
+
return <strong key={key}>{renderChildren(node.children, context)}</strong>
|
|
339
|
+
case 'emphasis':
|
|
340
|
+
return <em key={key}>{renderChildren(node.children, context)}</em>
|
|
341
|
+
case 'delete':
|
|
342
|
+
return <del key={key}>{renderChildren(node.children, context)}</del>
|
|
343
|
+
case 'inlineCode': {
|
|
344
|
+
// Parity with mdast-util-to-hast: inline code renders line endings as spaces.
|
|
345
|
+
const value = node.value.replace(/\r?\n|\r/g, ' ')
|
|
346
|
+
// An inline-code token that is entirely an absolute HTTP(S) URL keeps
|
|
347
|
+
// its code chrome and gains the same safe external anchor as a link;
|
|
348
|
+
// commands, partial URLs, and other schemes stay inert. The value is
|
|
349
|
+
// authored text, not a parsed destination, so no normalizeUri: port,
|
|
350
|
+
// path, and query render unchanged.
|
|
351
|
+
const href = inlineCodeHttpUrl(value)
|
|
352
|
+
if (href !== undefined) return <code key={key}>{renderSafeLink(href, [value], 'link')}</code>
|
|
353
|
+
// A token the owner's file-mention vocabulary recognizes opens that
|
|
354
|
+
// file; the resolver, not this renderer, decides what names a file.
|
|
355
|
+
// Inside an anchor the token stays inert — a button cannot nest there.
|
|
356
|
+
const mention = context.inLink === true ? undefined : context.fileMentions?.resolve(value)
|
|
357
|
+
if (mention !== undefined) {
|
|
358
|
+
return (
|
|
359
|
+
<code key={key}>
|
|
360
|
+
<button
|
|
361
|
+
type="button"
|
|
362
|
+
className={css.fileMention}
|
|
363
|
+
title={mention.title}
|
|
364
|
+
aria-label={mention.label}
|
|
365
|
+
onClick={mention.open}
|
|
366
|
+
{...mention.contextMenuProps}
|
|
367
|
+
>
|
|
368
|
+
<LinkIconMedium kind={classifyLinkPath(value)} className={css.linkIcon} />
|
|
369
|
+
{value}
|
|
370
|
+
</button>
|
|
371
|
+
</code>
|
|
372
|
+
)
|
|
373
|
+
}
|
|
374
|
+
return <code key={key}>{value}</code>
|
|
375
|
+
}
|
|
376
|
+
case 'html':
|
|
377
|
+
// No HTML parser enters the pipeline: raw HTML is literal text, or nothing where the owner omits it.
|
|
378
|
+
return context.omitHtml ? null : node.value
|
|
379
|
+
case 'code':
|
|
380
|
+
return renderCode(node, key, context)
|
|
381
|
+
case 'math':
|
|
382
|
+
return <Fragment key={key}>{renderTexToReact(node.value, true)}</Fragment>
|
|
383
|
+
case 'inlineMath':
|
|
384
|
+
return <Fragment key={key}>{renderTexToReact(node.value, false)}</Fragment>
|
|
385
|
+
case 'list':
|
|
386
|
+
return renderList(node, key, context)
|
|
387
|
+
case 'listItem':
|
|
388
|
+
// Reachable only in hand-built trees: the grammar emits items inside lists.
|
|
389
|
+
return renderListItem(node, listItemLoose(node), key, context)
|
|
390
|
+
case 'table':
|
|
391
|
+
return renderTable(node, key, context)
|
|
392
|
+
case 'link':
|
|
393
|
+
return renderAnchor(
|
|
394
|
+
node.url, renderChildren(node.children, { ...context, inLink: true }), key,
|
|
395
|
+
!anchorWrapsOnlyImages(node.children), context.streaming,
|
|
396
|
+
)
|
|
397
|
+
case 'linkReference':
|
|
398
|
+
return renderLinkReference(node, key, context)
|
|
399
|
+
case 'image':
|
|
400
|
+
return renderImage(node.url, node.alt ?? '', key, context)
|
|
401
|
+
case 'imageReference':
|
|
402
|
+
return renderImageReference(node, key, context)
|
|
403
|
+
case 'footnoteReference':
|
|
404
|
+
return renderFootnoteReference(node, key, context)
|
|
405
|
+
case 'definition':
|
|
406
|
+
case 'footnoteDefinition':
|
|
407
|
+
// Targets render elsewhere: definitions resolve references in place;
|
|
408
|
+
// footnote bodies render in the trailing section.
|
|
409
|
+
return null
|
|
410
|
+
default:
|
|
411
|
+
// Documented default for the merge-extensible union: node types without
|
|
412
|
+
// a mapping (tableRow/tableCell outside a table, frontmatter, future
|
|
413
|
+
// grammar contributions) render nothing.
|
|
414
|
+
return null
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function renderCode(node: Md.Code, key: Key, context: MarkdownRenderContext): ReactNode {
|
|
419
|
+
const language = node.lang ?? undefined
|
|
420
|
+
if (node.value === '') {
|
|
421
|
+
// Parity: the replaced pipeline kept the stock <pre> for an empty fence.
|
|
422
|
+
return (
|
|
423
|
+
<pre key={key}>
|
|
424
|
+
<code className={language === undefined ? undefined : `language-${language}`} />
|
|
425
|
+
</pre>
|
|
426
|
+
)
|
|
427
|
+
}
|
|
428
|
+
// The replaced pipeline recovered the grammar id from the hast class with
|
|
429
|
+
// /language-([\w-]+)/, which truncates at the first non-word character.
|
|
430
|
+
const lang = language === undefined ? undefined : /^[\w-]+/.exec(language)?.[0]
|
|
431
|
+
// Streaming keys are source offsets, stable while the fence grows, so the
|
|
432
|
+
// block instance (and its incremental highlight session) survives every
|
|
433
|
+
// chunk. A fence whose info string is still mid-chunk has no content yet and
|
|
434
|
+
// took the empty-fence arm above, so `lang` here is final.
|
|
435
|
+
if (lang === undefined) {
|
|
436
|
+
return <FenceCodeBlock key={key} code={node.value} streaming={context.streaming} labels={context.labels.code} />
|
|
437
|
+
}
|
|
438
|
+
return (
|
|
439
|
+
<MarkdownFenceSeat
|
|
440
|
+
key={key} lang={lang} meta={node.meta ?? undefined} code={node.value} streaming={context.streaming} labels={context.labels.code}
|
|
441
|
+
/>
|
|
442
|
+
)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* One fence whose language is final: the delegate's renderer when the owner
|
|
447
|
+
* supplies one, otherwise the built-in math and code blocks. Reading the
|
|
448
|
+
* delegate in this Component rather than in the render pass lets cached
|
|
449
|
+
* streaming elements follow a provider change.
|
|
450
|
+
*/
|
|
451
|
+
function MarkdownFenceSeat({ lang, meta, code, streaming, labels }: {
|
|
452
|
+
readonly lang: string
|
|
453
|
+
readonly meta: string | undefined
|
|
454
|
+
readonly code: string
|
|
455
|
+
readonly streaming: boolean
|
|
456
|
+
readonly labels: MarkdownCodeLabels
|
|
457
|
+
}): ReactNode {
|
|
458
|
+
const { renderCode } = useMarkdownDelegate()
|
|
459
|
+
if (renderCode !== undefined) {
|
|
460
|
+
// The seat box spaces the fence among its siblings, so the delegate's blocks carry no margins of their own.
|
|
461
|
+
return <div className={css.fenceSeat}>{renderCode({ lang: lang.toLowerCase(), code, streaming, meta })}</div>
|
|
462
|
+
}
|
|
463
|
+
// ```math fences render as display TeX once settled; while streaming they stay literal.
|
|
464
|
+
if (!streaming && lang === 'math') return <FenceMathBlock code={code} />
|
|
465
|
+
return <FenceCodeBlock lang={lang} code={code} streaming={streaming} labels={labels} />
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** A list is loose when it or any of its items is spread; every item then keeps its paragraphs. */
|
|
469
|
+
function listLoose(list: Md.List): boolean {
|
|
470
|
+
return (list.spread ?? false) || list.children.some(listItemLoose)
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function listItemLoose(item: Md.ListItem): boolean {
|
|
474
|
+
return item.spread ?? item.children.length > 1
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function renderList(node: Md.List, key: Key, context: MarkdownRenderContext): ReactNode {
|
|
478
|
+
const loose = listLoose(node)
|
|
479
|
+
const properties: { start?: number; className?: string } = {}
|
|
480
|
+
if (typeof node.start === 'number' && node.start !== 1) properties.start = node.start
|
|
481
|
+
if (node.children.some(item => typeof item.checked === 'boolean')) {
|
|
482
|
+
properties.className = 'contains-task-list'
|
|
483
|
+
}
|
|
484
|
+
return createElement(
|
|
485
|
+
node.ordered === true ? 'ol' : 'ul',
|
|
486
|
+
{ key, ...properties },
|
|
487
|
+
...node.children.map((item, index) => renderListItem(item, loose, index, context)),
|
|
488
|
+
)
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function renderListItem(
|
|
492
|
+
item: Md.ListItem,
|
|
493
|
+
loose: boolean,
|
|
494
|
+
key: Key,
|
|
495
|
+
context: MarkdownRenderContext,
|
|
496
|
+
): ReactNode {
|
|
497
|
+
const entries = renderBlockEntries(item.children, context)
|
|
498
|
+
const task = typeof item.checked === 'boolean'
|
|
499
|
+
if (task) {
|
|
500
|
+
const checkbox = <input key="task-checkbox" type="checkbox" checked={item.checked === true} disabled />
|
|
501
|
+
const head = entries[0]
|
|
502
|
+
if (head !== undefined && 'paragraph' in head) {
|
|
503
|
+
head.paragraph = head.paragraph.length > 0 ? [checkbox, ' ', ...head.paragraph] : [checkbox]
|
|
504
|
+
} else {
|
|
505
|
+
entries.unshift({ paragraph: [checkbox] })
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
// Newline placement and tight-paragraph unwrapping mirror
|
|
509
|
+
// mdast-util-to-hast's list-item handler: a newline before every child
|
|
510
|
+
// except a tight leading paragraph, and after a trailing non-paragraph
|
|
511
|
+
// (or any trailing child when loose).
|
|
512
|
+
const parts: ReactNode[] = []
|
|
513
|
+
for (const [index, entry] of entries.entries()) {
|
|
514
|
+
const isParagraph = 'paragraph' in entry
|
|
515
|
+
if (loose || index !== 0 || !isParagraph) parts.push('\n')
|
|
516
|
+
if (!isParagraph) parts.push(entry.element)
|
|
517
|
+
else if (loose) parts.push(<p key={`p-${index}`}>{entry.paragraph}</p>)
|
|
518
|
+
else parts.push(<Fragment key={`p-${index}`}>{entry.paragraph}</Fragment>)
|
|
519
|
+
}
|
|
520
|
+
const tail = entries[entries.length - 1]
|
|
521
|
+
if (tail !== undefined && (loose || !('paragraph' in tail))) parts.push('\n')
|
|
522
|
+
return (
|
|
523
|
+
<li key={key} className={task ? 'task-list-item' : undefined}>
|
|
524
|
+
{parts}
|
|
525
|
+
</li>
|
|
526
|
+
)
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function renderTable(node: Md.Table, key: Key, context: MarkdownRenderContext): ReactNode {
|
|
530
|
+
const align = node.align ?? null
|
|
531
|
+
const [headRow, ...bodyRows] = node.children
|
|
532
|
+
const columns = align === null ? headRow?.children.length ?? 0 : align.length
|
|
533
|
+
// Four or more columns read as a comparison matrix: the block keeps the
|
|
534
|
+
// table at natural width and exposes the stable `md-table-wide` hook so a
|
|
535
|
+
// hosting layout (the chat transcript) can widen it past the message
|
|
536
|
+
// column. Narrower tables — and any table inside a blockquote — fill the
|
|
537
|
+
// column and wrap instead (deepsuite chat TableWrapper parity).
|
|
538
|
+
const wide = columns >= 4 && context.inBlockquote !== true
|
|
539
|
+
return (
|
|
540
|
+
// On hover-capable inputs, wide tables rest with overflow-x hidden (the
|
|
541
|
+
// hover-revealed bar in MarkdownText.module.css), dropping Chromium's implicit scroller
|
|
542
|
+
// focusability — the explicit tabindex keeps them keyboard-reachable,
|
|
543
|
+
// and :focus-visible restores scrolling.
|
|
544
|
+
<div
|
|
545
|
+
key={key}
|
|
546
|
+
className={clsx(css.tableScroll, wide ? 'md-table-wide' : css.tableFill)}
|
|
547
|
+
tabIndex={wide ? 0 : undefined}
|
|
548
|
+
>
|
|
549
|
+
<table>
|
|
550
|
+
{headRow !== undefined && <thead>{renderTableRow(headRow, 'th', align, 0, context)}</thead>}
|
|
551
|
+
{bodyRows.length > 0 && (
|
|
552
|
+
<tbody>
|
|
553
|
+
{bodyRows.map((row, index) => renderTableRow(row, 'td', align, index + 1, context))}
|
|
554
|
+
</tbody>
|
|
555
|
+
)}
|
|
556
|
+
</table>
|
|
557
|
+
</div>
|
|
558
|
+
)
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function renderTableRow(
|
|
562
|
+
row: Md.TableRow,
|
|
563
|
+
cellTag: 'th' | 'td',
|
|
564
|
+
align: readonly Md.AlignType[] | null,
|
|
565
|
+
key: Key,
|
|
566
|
+
context: MarkdownRenderContext,
|
|
567
|
+
): ReactNode {
|
|
568
|
+
// With column alignment present, every row renders exactly one cell per
|
|
569
|
+
// column, padding or truncating the row (mdast-util-to-hast parity).
|
|
570
|
+
const length = align === null ? row.children.length : align.length
|
|
571
|
+
const cells: ReactNode[] = []
|
|
572
|
+
for (let index = 0; index < length; index++) {
|
|
573
|
+
const cell = row.children[index]
|
|
574
|
+
const alignValue = align?.[index]
|
|
575
|
+
cells.push(createElement(
|
|
576
|
+
cellTag,
|
|
577
|
+
// hast-util-to-jsx-runtime's default tableCellAlignToStyle turned the
|
|
578
|
+
// deprecated align attribute into an inline style; keep that DOM.
|
|
579
|
+
{ key: index, style: alignValue == null ? undefined : { textAlign: alignValue } },
|
|
580
|
+
...(cell === undefined ? [] : renderChildren(cell.children, context)),
|
|
581
|
+
))
|
|
582
|
+
}
|
|
583
|
+
return <tr key={key}>{cells}</tr>
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* True when an anchor's markdown children are all images, so the anchor is a
|
|
588
|
+
* clickable picture (badge, thumbnail): the leading URL glyph would dangle
|
|
589
|
+
* beside the image instead of leading link text, so those anchors skip it.
|
|
590
|
+
*/
|
|
591
|
+
function anchorWrapsOnlyImages(children: Md.PhrasingContent[]): boolean {
|
|
592
|
+
return children.length > 0 && children.every(child => child.type === 'image' || child.type === 'imageReference')
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/** Anchor over a safe absolute href, with optional owner navigation for HTTP(S). */
|
|
596
|
+
function renderSafeLink(href: string, children: ReactNode[], key: Key, glyph = true): ReactNode {
|
|
597
|
+
const safeHref = sanitizeUrl(href)
|
|
598
|
+
if (safeHref === '') return <Fragment key={key}>{children}</Fragment>
|
|
599
|
+
return <MarkdownAnchor key={key} href={safeHref} glyph={glyph}>{children}</MarkdownAnchor>
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function MarkdownAnchor({ href, glyph, children }: {
|
|
603
|
+
readonly href: string
|
|
604
|
+
readonly glyph: boolean
|
|
605
|
+
readonly children: ReactNode[]
|
|
606
|
+
}): ReactNode {
|
|
607
|
+
const { openExternalLink, getTriggerProps } = useMarkdownDelegate()
|
|
608
|
+
const external = ['http:', 'https:'].includes(new URL(href).protocol)
|
|
609
|
+
const open = external ? openExternalLink : undefined
|
|
610
|
+
return (
|
|
611
|
+
<a
|
|
612
|
+
href={href}
|
|
613
|
+
{...external ? getTriggerProps?.({ kind: 'url', url: href }) : {}}
|
|
614
|
+
{...(external ? { target: '_blank', rel: 'noopener noreferrer' } : {})}
|
|
615
|
+
onClick={open === undefined ? undefined : (event) => {
|
|
616
|
+
if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return
|
|
617
|
+
event.preventDefault()
|
|
618
|
+
open(href)
|
|
619
|
+
}}
|
|
620
|
+
>
|
|
621
|
+
{glyph && <LinkIconMedium kind="url" href={href} className={css.linkIcon} />}
|
|
622
|
+
{children}
|
|
623
|
+
</a>
|
|
624
|
+
)
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/** Local destinations use the scoped file delegate after settlement. */
|
|
628
|
+
function renderAnchor(url: string, children: ReactNode[], key: Key, glyph = true, streaming = false): ReactNode {
|
|
629
|
+
const file = parseFileLink(url)
|
|
630
|
+
if (file !== undefined) {
|
|
631
|
+
if (streaming) return <Fragment key={key}>{children}</Fragment>
|
|
632
|
+
return <MarkdownFileLink key={key} file={file} glyph={glyph}>{children}</MarkdownFileLink>
|
|
633
|
+
}
|
|
634
|
+
return renderSafeLink(normalizeUri(url), children, key, glyph)
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function MarkdownFileLink({ file, glyph, children }: {
|
|
638
|
+
readonly file: { path: string; line?: number }
|
|
639
|
+
readonly glyph: boolean
|
|
640
|
+
readonly children: ReactNode[]
|
|
641
|
+
}): ReactNode {
|
|
642
|
+
const { openFile, fileImages, getTriggerProps } = useMarkdownDelegate()
|
|
643
|
+
const [load] = useState(nextImageLoad)
|
|
644
|
+
if (openFile === undefined) return <>{children}</>
|
|
645
|
+
// Pure-image anchors already contain their preview and keep one navigation target.
|
|
646
|
+
const preview = glyph && classifyLinkPath(file.path) === 'image' ? fileImages : undefined
|
|
647
|
+
const resolved = preview?.resolve(file.path)
|
|
648
|
+
const src = resolved === undefined ? undefined : freshImageUrl(resolved, load)
|
|
649
|
+
const anchor = (
|
|
650
|
+
<button
|
|
651
|
+
type="button"
|
|
652
|
+
className={clsx(css.fileMention, css.fileLink)}
|
|
653
|
+
title={src === undefined ? file.path : undefined}
|
|
654
|
+
{...getTriggerProps?.({ kind: 'file', ...file })}
|
|
655
|
+
onClick={() => { openFile(file.path, file.line === undefined ? undefined : { line: file.line }) }}
|
|
656
|
+
>
|
|
657
|
+
{glyph && <LinkIconMedium kind={classifyLinkPath(file.path)} className={css.linkIcon} />}
|
|
658
|
+
{children}
|
|
659
|
+
</button>
|
|
660
|
+
)
|
|
661
|
+
if (src === undefined || preview === undefined) return anchor
|
|
662
|
+
return <HoverCard inline anchor={anchor}
|
|
663
|
+
content={<>
|
|
664
|
+
<ImagePreview src={src} alt={file.path} loadingLabel={preview.labels.loading} failedLabel={preview.labels.failed} />
|
|
665
|
+
<span className={css.previewName}>{file.path.split(/[\\/]/u).pop()}</span>
|
|
666
|
+
</>} />
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* The complete inline-code value when it is exactly an absolute HTTP(S) URL
|
|
671
|
+
* (no surrounding whitespace); anything else stays inert code.
|
|
672
|
+
*/
|
|
673
|
+
function inlineCodeHttpUrl(value: string): string | undefined {
|
|
674
|
+
if (value.trim() !== value) return undefined
|
|
675
|
+
try {
|
|
676
|
+
const protocol = new URL(value).protocol
|
|
677
|
+
return protocol === 'http:' || protocol === 'https:' ? value : undefined
|
|
678
|
+
} catch {
|
|
679
|
+
// Not an absolute URL at all — the only way new URL() rejects a string.
|
|
680
|
+
return undefined
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function renderImage(url: string, alt: string, key: Key, context: MarkdownRenderContext): ReactNode {
|
|
685
|
+
return <MarkdownImage key={`${key}:${url}`} destination={url} alt={alt}
|
|
686
|
+
pathImages={context.pathImages} streaming={context.streaming} inLink={context.inLink === true} />
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
function MarkdownImage({ destination, alt, pathImages, streaming, inLink }: {
|
|
690
|
+
destination: string
|
|
691
|
+
alt: string
|
|
692
|
+
pathImages: MarkdownPathImages | undefined
|
|
693
|
+
streaming: boolean
|
|
694
|
+
inLink: boolean
|
|
695
|
+
}): ReactNode {
|
|
696
|
+
const { fileImages } = useMarkdownDelegate()
|
|
697
|
+
const [load] = useState(nextImageLoad)
|
|
698
|
+
const file = streaming ? undefined : parseFileLink(destination)
|
|
699
|
+
const resolved = file === undefined ? undefined : fileImages?.resolve(file.path)
|
|
700
|
+
const src = resolved === undefined ? imageSource(destination, pathImages, load) : freshImageUrl(resolved, load)
|
|
701
|
+
if (src === undefined) return <span className={css.imageAlt}>{alt}</span>
|
|
702
|
+
return <LoadedMarkdownImage key={src} src={src} alt={alt} destination={destination} preview={inLink ? undefined : fileImages} />
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function LoadedMarkdownImage({ src, alt, destination, preview }: {
|
|
706
|
+
src: string
|
|
707
|
+
alt: string
|
|
708
|
+
destination: string
|
|
709
|
+
preview: ReturnType<typeof useMarkdownDelegate>['fileImages']
|
|
710
|
+
}): ReactNode {
|
|
711
|
+
const { getTriggerProps } = useMarkdownDelegate()
|
|
712
|
+
const [failed, setFailed] = useState(false)
|
|
713
|
+
const [open, setOpen] = useState(false)
|
|
714
|
+
const close = useCallback(() => { setOpen(false) }, [])
|
|
715
|
+
if (failed) return <span className={css.imageAlt}>{preview === undefined ? '' : `${preview.labels.failed} · `}{alt || destination}</span>
|
|
716
|
+
const file = parseFileLink(destination)
|
|
717
|
+
const contextMenuProps = getTriggerProps?.({ kind: 'image', url: src, ...(file === undefined ? {} : { path: file.path }) })
|
|
718
|
+
const imageProps = { className: css.image, src, alt, onError: () => { setFailed(true) },
|
|
719
|
+
loading: 'lazy' as const, decoding: 'async' as const, referrerPolicy: 'no-referrer' as const }
|
|
720
|
+
if (preview === undefined) return <img {...imageProps} {...contextMenuProps} />
|
|
721
|
+
const localFileName = file?.path.split(/[\\/]/u).at(-1)
|
|
722
|
+
const urlFileName = destination.split('/').at(-1)?.split(/[?#]/u)[0]
|
|
723
|
+
const exportName = localFileName || urlFileName || 'image'
|
|
724
|
+
const img = <DraggableImage
|
|
725
|
+
fileDrag={preview.fileDrag}
|
|
726
|
+
{...imageProps}
|
|
727
|
+
resourceAddress={file === undefined ? undefined : preview.resourceAddress?.(file.path)}
|
|
728
|
+
name={exportName}
|
|
729
|
+
/>
|
|
730
|
+
return <>
|
|
731
|
+
<button type="button" className={css.imageButton} title={preview.labels.open}
|
|
732
|
+
{...contextMenuProps}
|
|
733
|
+
aria-label={alt ? `${preview.labels.open}: ${alt}` : preview.labels.open}
|
|
734
|
+
onClick={() => { setOpen(true) }}>{img}</button>
|
|
735
|
+
{open && <ImageLightbox src={src} alt={alt} labels={preview.labels} onClose={close} contextMenuProps={contextMenuProps} />}
|
|
736
|
+
</>
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/** The bracketed source text a reference reverts to when its definition is missing. */
|
|
740
|
+
function referenceSuffix(node: Md.LinkReference | Md.ImageReference): string {
|
|
741
|
+
if (node.referenceType === 'collapsed') return '][]'
|
|
742
|
+
if (node.referenceType === 'full') return `][${node.label ?? node.identifier}]`
|
|
743
|
+
return ']'
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
function renderLinkReference(
|
|
747
|
+
node: Md.LinkReference,
|
|
748
|
+
key: Key,
|
|
749
|
+
context: MarkdownRenderContext,
|
|
750
|
+
): ReactNode {
|
|
751
|
+
const definition = context.targets.definitions.get(node.identifier.toUpperCase())
|
|
752
|
+
if (definition === undefined) {
|
|
753
|
+
// The grammar only emits references whose definitions exist somewhere in
|
|
754
|
+
// the same parse, but incremental segments and hand-built trees may still
|
|
755
|
+
// present unresolved ones: revert to the bracketed source text — which is
|
|
756
|
+
// not an anchor, so mentions inside it stay live.
|
|
757
|
+
return <Fragment key={key}>{'['}{renderChildren(node.children, context)}{referenceSuffix(node)}</Fragment>
|
|
758
|
+
}
|
|
759
|
+
const rendered = renderChildren(node.children, { ...context, inLink: true })
|
|
760
|
+
return renderAnchor(definition.url, rendered, key, !anchorWrapsOnlyImages(node.children), context.streaming)
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function renderImageReference(
|
|
764
|
+
node: Md.ImageReference,
|
|
765
|
+
key: Key,
|
|
766
|
+
context: MarkdownRenderContext,
|
|
767
|
+
): ReactNode {
|
|
768
|
+
const definition = context.targets.definitions.get(node.identifier.toUpperCase())
|
|
769
|
+
if (definition === undefined) return `![${node.alt ?? ''}${referenceSuffix(node)}`
|
|
770
|
+
return renderImage(definition.url, node.alt ?? '', key, context)
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function renderFootnoteReference(
|
|
774
|
+
node: Md.FootnoteReference,
|
|
775
|
+
key: Key,
|
|
776
|
+
context: MarkdownRenderContext,
|
|
777
|
+
): ReactNode {
|
|
778
|
+
const id = node.identifier.toUpperCase()
|
|
779
|
+
const seen = context.footnoteCounts.get(id)
|
|
780
|
+
if (seen === undefined) context.footnoteOrder.push(id)
|
|
781
|
+
context.footnoteCounts.set(id, (seen ?? 0) + 1)
|
|
782
|
+
// The in-page anchor is not an absolute URL, so only the numbered
|
|
783
|
+
// superscript renders (matching the replaced pipeline's unwrapped link).
|
|
784
|
+
return <sup key={key}>{String(context.footnoteOrder.indexOf(id) + 1)}</sup>
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Render the trailing footnote section for every footnote referenced during
|
|
789
|
+
* the pass, in first-reference order, with one plain-text back-reference
|
|
790
|
+
* marker per rendered reference.
|
|
791
|
+
* @param context - The pass state after all blocks rendered.
|
|
792
|
+
* @returns The section, or null when no referenced footnote has a definition.
|
|
793
|
+
*/
|
|
794
|
+
export function renderFootnoteSection(context: MarkdownRenderContext): ReactNode | null {
|
|
795
|
+
const items: ReactNode[] = []
|
|
796
|
+
for (const id of context.footnoteOrder) {
|
|
797
|
+
const definition = context.targets.footnotes.get(id)
|
|
798
|
+
if (definition === undefined) continue
|
|
799
|
+
const count = context.footnoteCounts.get(id) ?? 0
|
|
800
|
+
const backrefs: ReactNode[] = []
|
|
801
|
+
for (let reference = 1; reference <= count; reference++) {
|
|
802
|
+
if (backrefs.length > 0) backrefs.push(' ')
|
|
803
|
+
backrefs.push('↩')
|
|
804
|
+
if (reference > 1) backrefs.push(<sup key={`re-${reference}`}>{String(reference)}</sup>)
|
|
805
|
+
}
|
|
806
|
+
const entries = renderBlockEntries(definition.children, context)
|
|
807
|
+
const tail = entries[entries.length - 1]
|
|
808
|
+
const body: ReactNode[] = entries.map((entry, index) => (
|
|
809
|
+
'paragraph' in entry
|
|
810
|
+
? (
|
|
811
|
+
<p key={`p-${index}`}>
|
|
812
|
+
{entry.paragraph}
|
|
813
|
+
{entry === tail && <>{' '}{backrefs}</>}
|
|
814
|
+
</p>
|
|
815
|
+
)
|
|
816
|
+
: entry.element
|
|
817
|
+
))
|
|
818
|
+
// Without a trailing paragraph the back-references join the block list
|
|
819
|
+
// itself (and pick up the wrap newlines), as in the replaced pipeline.
|
|
820
|
+
if (tail === undefined || !('paragraph' in tail)) body.push(...backrefs)
|
|
821
|
+
items.push(
|
|
822
|
+
<li key={id} id={`user-content-fn-${normalizeUri(id.toLowerCase())}`}>
|
|
823
|
+
{wrapBlockChildren(body, true)}
|
|
824
|
+
</li>,
|
|
825
|
+
)
|
|
826
|
+
}
|
|
827
|
+
if (items.length === 0) return null
|
|
828
|
+
return (
|
|
829
|
+
<section key="footnotes" data-footnotes className="footnotes">
|
|
830
|
+
<h2 id="footnote-label" className="sr-only">{context.labels.footnotes}</h2>
|
|
831
|
+
<ol>{items}</ol>
|
|
832
|
+
</section>
|
|
833
|
+
)
|
|
834
|
+
}
|