@deepseek-ai/dsh-client-ui-primitives 0.2.2-rc.1 → 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 +9 -6
- 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,349 @@
|
|
|
1
|
+
/** Extend upstream dollar-only math syntax with TeX delimiters while reusing its token vocabulary. */
|
|
2
|
+
|
|
3
|
+
import { factorySpace } from 'micromark-factory-space'
|
|
4
|
+
import type {} from 'micromark-extension-math'
|
|
5
|
+
import { markdownLineEnding } from 'micromark-util-character'
|
|
6
|
+
import { codes, constants, types } from 'micromark-util-symbol'
|
|
7
|
+
import type { Construct, Extension, Previous, State, Tokenizer } from 'micromark-util-types'
|
|
8
|
+
|
|
9
|
+
// oxlint-disable typescript/no-this-alias -- micromark binds tokenizer context only on the outer callback.
|
|
10
|
+
|
|
11
|
+
const previousBackslash: Previous = function (code) {
|
|
12
|
+
if (code !== codes.backslash) return true
|
|
13
|
+
const tail = this.events.at(-1)
|
|
14
|
+
/* v8 ignore next -- a previous code necessarily has a preceding event. */
|
|
15
|
+
if (tail === undefined) return false
|
|
16
|
+
return tail[1].type === types.characterEscape
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const tokenizeBackslashMathText: Tokenizer = function (effects, ok, nok) {
|
|
20
|
+
return start
|
|
21
|
+
|
|
22
|
+
function start(code: number | null): State | undefined {
|
|
23
|
+
/* v8 ignore next -- the text construct is dispatched only for a backslash. */
|
|
24
|
+
if (code !== codes.backslash) return nok(code)
|
|
25
|
+
effects.enter('mathText')
|
|
26
|
+
effects.enter('mathTextSequence')
|
|
27
|
+
effects.consume(code)
|
|
28
|
+
return open
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function open(code: number | null): State | undefined {
|
|
32
|
+
if (code !== codes.leftParenthesis) return nok(code)
|
|
33
|
+
effects.consume(code)
|
|
34
|
+
effects.exit('mathTextSequence')
|
|
35
|
+
return between
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function between(code: number | null): State | undefined {
|
|
39
|
+
if (code === codes.eof) return nok(code)
|
|
40
|
+
if (code === codes.backslash) {
|
|
41
|
+
return effects.attempt({ partial: true, tokenize: tokenizeClose }, close, afterCloseAttempt)(code)
|
|
42
|
+
}
|
|
43
|
+
if (markdownLineEnding(code)) {
|
|
44
|
+
effects.enter(types.lineEnding)
|
|
45
|
+
effects.consume(code)
|
|
46
|
+
effects.exit(types.lineEnding)
|
|
47
|
+
return between
|
|
48
|
+
}
|
|
49
|
+
return dataStart(code)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function afterCloseAttempt(code: number | null): State | undefined {
|
|
53
|
+
return effects.check({ partial: true, tokenize: tokenizeOpen }, nok, dataStart)(code)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function dataStart(code: number | null): State | undefined {
|
|
57
|
+
effects.enter('mathTextData')
|
|
58
|
+
effects.consume(code)
|
|
59
|
+
return code === codes.backslash ? afterDataBackslash : data
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function afterDataBackslash(code: number | null): State | undefined {
|
|
63
|
+
if (code === codes.backslash) {
|
|
64
|
+
effects.consume(code)
|
|
65
|
+
return data
|
|
66
|
+
}
|
|
67
|
+
return data(code)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function data(code: number | null): State | undefined {
|
|
71
|
+
if (code === codes.eof || code === codes.backslash || markdownLineEnding(code)) {
|
|
72
|
+
effects.exit('mathTextData')
|
|
73
|
+
return between(code)
|
|
74
|
+
}
|
|
75
|
+
effects.consume(code)
|
|
76
|
+
return data
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function close(code: number | null): State | undefined {
|
|
80
|
+
effects.exit('mathText')
|
|
81
|
+
return ok(code)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function tokenizeClose(closeEffects: Parameters<Tokenizer>[0], closeOk: State, closeNok: State): State {
|
|
85
|
+
return slash
|
|
86
|
+
|
|
87
|
+
function slash(code: number | null): State | undefined {
|
|
88
|
+
/* v8 ignore next -- this partial construct is attempted only at a backslash. */
|
|
89
|
+
if (code !== codes.backslash) return closeNok(code)
|
|
90
|
+
closeEffects.enter('mathTextSequence')
|
|
91
|
+
closeEffects.consume(code)
|
|
92
|
+
return parenthesis
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function parenthesis(code: number | null): State | undefined {
|
|
96
|
+
if (code !== codes.rightParenthesis) return closeNok(code)
|
|
97
|
+
closeEffects.consume(code)
|
|
98
|
+
closeEffects.exit('mathTextSequence')
|
|
99
|
+
return closeOk
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function tokenizeOpen(openEffects: Parameters<Tokenizer>[0], openOk: State, openNok: State): State {
|
|
104
|
+
return slash
|
|
105
|
+
|
|
106
|
+
function slash(code: number | null): State | undefined {
|
|
107
|
+
/* v8 ignore next -- the opening check follows a failed close attempt at a backslash. */
|
|
108
|
+
if (code !== codes.backslash) return openNok(code)
|
|
109
|
+
openEffects.enter(types.chunkString)
|
|
110
|
+
openEffects.consume(code)
|
|
111
|
+
return parenthesis
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function parenthesis(code: number | null): State | undefined {
|
|
115
|
+
if (code !== codes.leftParenthesis) return openNok(code)
|
|
116
|
+
openEffects.consume(code)
|
|
117
|
+
openEffects.exit(types.chunkString)
|
|
118
|
+
return openOk
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function createMathFlow(marker: number, openMarker: number, closeMarker: number, multiline: boolean): Construct {
|
|
124
|
+
const tokenize: Tokenizer = function (effects, ok, nok) {
|
|
125
|
+
const self = this
|
|
126
|
+
let oddBackslashRun = false
|
|
127
|
+
const tail = self.events.at(-1)
|
|
128
|
+
const initialSize = tail?.[1].type === types.linePrefix
|
|
129
|
+
? tail[2].sliceSerialize(tail[1], true).length
|
|
130
|
+
: 0
|
|
131
|
+
|
|
132
|
+
return start
|
|
133
|
+
|
|
134
|
+
function start(code: number | null): State | undefined {
|
|
135
|
+
/* v8 ignore next -- the flow construct is dispatched only for its marker. */
|
|
136
|
+
if (code !== marker) return nok(code)
|
|
137
|
+
effects.enter('mathFlow')
|
|
138
|
+
effects.enter('mathFlowFence')
|
|
139
|
+
effects.enter('mathFlowFenceSequence')
|
|
140
|
+
effects.consume(code)
|
|
141
|
+
return open
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function open(code: number | null): State | undefined {
|
|
145
|
+
if (code !== openMarker) return nok(code)
|
|
146
|
+
effects.consume(code)
|
|
147
|
+
effects.exit('mathFlowFenceSequence')
|
|
148
|
+
effects.exit('mathFlowFence')
|
|
149
|
+
return marker === codes.dollarSign ? afterDollarOpen : content
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function afterDollarOpen(code: number | null): State | undefined {
|
|
153
|
+
return code === codes.dollarSign ? nok(code) : content(code)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function content(code: number | null): State | undefined {
|
|
157
|
+
if (code === codes.eof) return nok(code)
|
|
158
|
+
if (code === marker && (marker !== codes.dollarSign || !oddBackslashRun)) {
|
|
159
|
+
return effects.attempt(
|
|
160
|
+
{ partial: true, tokenize: tokenizeClosingFence },
|
|
161
|
+
closed,
|
|
162
|
+
afterClosingFenceAttempt,
|
|
163
|
+
)(code)
|
|
164
|
+
}
|
|
165
|
+
if (markdownLineEnding(code)) {
|
|
166
|
+
return multiline
|
|
167
|
+
? effects.attempt(nonLazyContinuation, afterContinuation, nok)(code)
|
|
168
|
+
: nok(code)
|
|
169
|
+
}
|
|
170
|
+
return valueStart(code)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function afterClosingFenceAttempt(code: number | null): State | undefined {
|
|
174
|
+
return marker === codes.backslash
|
|
175
|
+
? effects.check({ partial: true, tokenize: tokenizeOpeningFence }, nok, markerValueStart)(code)
|
|
176
|
+
: markerValueStart(code)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function afterContinuation(code: number | null): State | undefined {
|
|
180
|
+
return effects.attempt(
|
|
181
|
+
{ partial: true, tokenize: tokenizeClosingFence },
|
|
182
|
+
closed,
|
|
183
|
+
initialSize
|
|
184
|
+
? factorySpace(effects, content, types.linePrefix, initialSize + 1)
|
|
185
|
+
: content,
|
|
186
|
+
)(code)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function valueStart(code: number | null): State | undefined {
|
|
190
|
+
effects.enter('mathFlowValue')
|
|
191
|
+
oddBackslashRun = code === codes.backslash
|
|
192
|
+
effects.consume(code)
|
|
193
|
+
return value
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function markerValueStart(code: number | null): State | undefined {
|
|
197
|
+
effects.enter('mathFlowValue')
|
|
198
|
+
oddBackslashRun = false
|
|
199
|
+
effects.consume(code)
|
|
200
|
+
return valueAfterMarker
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function valueAfterMarker(code: number | null): State | undefined {
|
|
204
|
+
if (code === marker) {
|
|
205
|
+
effects.consume(code)
|
|
206
|
+
return value
|
|
207
|
+
}
|
|
208
|
+
return value(code)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function value(code: number | null): State | undefined {
|
|
212
|
+
if (code === codes.eof || code === marker || markdownLineEnding(code)) {
|
|
213
|
+
effects.exit('mathFlowValue')
|
|
214
|
+
return content(code)
|
|
215
|
+
}
|
|
216
|
+
oddBackslashRun = code === codes.backslash ? !oddBackslashRun : false
|
|
217
|
+
effects.consume(code)
|
|
218
|
+
return value
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function closed(code: number | null): State | undefined {
|
|
222
|
+
effects.exit('mathFlow')
|
|
223
|
+
return ok(code)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function tokenizeClosingFence(
|
|
227
|
+
closeEffects: Parameters<Tokenizer>[0],
|
|
228
|
+
closeOk: State,
|
|
229
|
+
closeNok: State,
|
|
230
|
+
): State {
|
|
231
|
+
return factorySpace(closeEffects, sequenceStart, types.linePrefix, constants.tabSize)
|
|
232
|
+
|
|
233
|
+
function sequenceStart(code: number | null): State | undefined {
|
|
234
|
+
if (code !== marker) return closeNok(code)
|
|
235
|
+
closeEffects.enter('mathFlowFence')
|
|
236
|
+
closeEffects.enter('mathFlowFenceSequence')
|
|
237
|
+
closeEffects.consume(code)
|
|
238
|
+
return sequenceEnd
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function sequenceEnd(code: number | null): State | undefined {
|
|
242
|
+
if (code !== closeMarker) return closeNok(code)
|
|
243
|
+
closeEffects.consume(code)
|
|
244
|
+
closeEffects.exit('mathFlowFenceSequence')
|
|
245
|
+
return factorySpace(closeEffects, after, types.whitespace)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function after(code: number | null): State | undefined {
|
|
249
|
+
if (code !== codes.eof && !markdownLineEnding(code)) return closeNok(code)
|
|
250
|
+
closeEffects.exit('mathFlowFence')
|
|
251
|
+
return closeOk(code)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function tokenizeOpeningFence(
|
|
256
|
+
openEffects: Parameters<Tokenizer>[0],
|
|
257
|
+
openOk: State,
|
|
258
|
+
openNok: State,
|
|
259
|
+
): State {
|
|
260
|
+
return sequenceStart
|
|
261
|
+
|
|
262
|
+
function sequenceStart(code: number | null): State | undefined {
|
|
263
|
+
/* v8 ignore next -- the opening check follows a failed close attempt at the marker. */
|
|
264
|
+
if (code !== marker) return openNok(code)
|
|
265
|
+
openEffects.enter(types.chunkString)
|
|
266
|
+
openEffects.consume(code)
|
|
267
|
+
return sequenceEnd
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function sequenceEnd(code: number | null): State | undefined {
|
|
271
|
+
if (code !== openMarker) return openNok(code)
|
|
272
|
+
openEffects.consume(code)
|
|
273
|
+
openEffects.exit(types.chunkString)
|
|
274
|
+
return openOk
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
concrete: true,
|
|
281
|
+
name: marker === codes.dollarSign ? 'sameLineDollarMathFlow' : 'backslashMathFlow',
|
|
282
|
+
tokenize,
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const tokenizeNonLazyContinuation: Tokenizer = function (effects, ok, nok) {
|
|
287
|
+
const self = this
|
|
288
|
+
|
|
289
|
+
return start
|
|
290
|
+
|
|
291
|
+
function start(code: number | null): State | undefined {
|
|
292
|
+
/* v8 ignore next -- continuation constructs are attempted only after a line ending. */
|
|
293
|
+
if (code === codes.eof) return ok(code)
|
|
294
|
+
/* v8 ignore next -- continuation constructs are attempted only after a line ending. */
|
|
295
|
+
if (!markdownLineEnding(code)) return nok(code)
|
|
296
|
+
effects.enter(types.lineEnding)
|
|
297
|
+
effects.consume(code)
|
|
298
|
+
effects.exit(types.lineEnding)
|
|
299
|
+
return lineStart
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function lineStart(code: number | null): State | undefined {
|
|
303
|
+
return self.parser.lazy[self.now().line] ? nok(code) : ok(code)
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const nonLazyContinuation: Construct = {
|
|
308
|
+
partial: true,
|
|
309
|
+
tokenize: tokenizeNonLazyContinuation,
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const backslashMathText: Construct = {
|
|
313
|
+
name: 'backslashMathText',
|
|
314
|
+
previous: previousBackslash,
|
|
315
|
+
tokenize: tokenizeBackslashMathText,
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const backslashMathFlow = createMathFlow(
|
|
319
|
+
codes.backslash,
|
|
320
|
+
codes.leftSquareBracket,
|
|
321
|
+
codes.rightSquareBracket,
|
|
322
|
+
true,
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
const sameLineDollarMathFlow = createMathFlow(
|
|
326
|
+
codes.dollarSign,
|
|
327
|
+
codes.dollarSign,
|
|
328
|
+
codes.dollarSign,
|
|
329
|
+
false,
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
const backslashMath: Extension = {
|
|
333
|
+
flow: {
|
|
334
|
+
[codes.backslash]: backslashMathFlow,
|
|
335
|
+
[codes.dollarSign]: sameLineDollarMathFlow,
|
|
336
|
+
},
|
|
337
|
+
text: { [codes.backslash]: backslashMathText },
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* TeX backslash delimiters and same-line display-dollar blocks as a micromark
|
|
342
|
+
* syntax extension reusing `micromark-extension-math`'s token vocabulary; the
|
|
343
|
+
* caller must also register `math()` on the same parse so the emitted tokens
|
|
344
|
+
* compile to standard math nodes.
|
|
345
|
+
* @returns The micromark syntax extension.
|
|
346
|
+
*/
|
|
347
|
+
export function mathCompatibility(): Extension {
|
|
348
|
+
return backslashMath
|
|
349
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The markdown renderer's two mdast grammars, one per rendering arm. Each
|
|
3
|
+
* arm is internally consistent — the incremental tail parses, the one-shot
|
|
4
|
+
* parses, and the plain-text projection of a given grammar always agree on
|
|
5
|
+
* where blocks start and end — and the settled grammar is the streaming one
|
|
6
|
+
* plus the math extensions, so the arms differ only where TeX delimiters
|
|
7
|
+
* begin a math construct (a `$$` block is a paragraph while streaming and a
|
|
8
|
+
* math block once settled, by design).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Root } from 'mdast'
|
|
12
|
+
import { recoverLocalImages } from './local-image-syntax.ts'
|
|
13
|
+
import { fromMarkdown } from 'mdast-util-from-markdown'
|
|
14
|
+
import { gfmFromMarkdown } from 'mdast-util-gfm'
|
|
15
|
+
import { mathFromMarkdown } from 'mdast-util-math'
|
|
16
|
+
import { gfm } from 'micromark-extension-gfm'
|
|
17
|
+
import { math } from 'micromark-extension-math'
|
|
18
|
+
import { cjkFriendlyStrong } from './cjkFriendlyStrong.ts'
|
|
19
|
+
import { mathCompatibility } from './mathCompatibility.ts'
|
|
20
|
+
import { windowsPathDestinations } from './windows-path-destinations.ts'
|
|
21
|
+
|
|
22
|
+
/** GFM strikethrough requires `~~`; a single `~` stays literal, as in ranges such as `10~20`. */
|
|
23
|
+
const gfmOptions = { singleTilde: false }
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Parse GFM markdown (the streaming arm's grammar: no math, so incomplete
|
|
27
|
+
* TeX never flashes KaTeX errors mid-stream).
|
|
28
|
+
* @param text - Markdown source.
|
|
29
|
+
* @returns The mdast root.
|
|
30
|
+
*/
|
|
31
|
+
export function parseGfm(text: string): Root {
|
|
32
|
+
return recoverLocalImages(fromMarkdown(text, {
|
|
33
|
+
extensions: [gfm(gfmOptions), cjkFriendlyStrong()],
|
|
34
|
+
mdastExtensions: [gfmFromMarkdown(), windowsPathDestinations()],
|
|
35
|
+
}), text)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Parse GFM markdown plus TeX math with the compatibility delimiters
|
|
40
|
+
* (the settled arm's grammar).
|
|
41
|
+
* @param text - Markdown source.
|
|
42
|
+
* @returns The mdast root.
|
|
43
|
+
*/
|
|
44
|
+
export function parseGfmWithMath(text: string): Root {
|
|
45
|
+
return recoverLocalImages(fromMarkdown(text, {
|
|
46
|
+
extensions: [gfm(gfmOptions), cjkFriendlyStrong(), mathCompatibility(), math()],
|
|
47
|
+
mdastExtensions: [gfmFromMarkdown(), mathFromMarkdown(), windowsPathDestinations()],
|
|
48
|
+
}), text)
|
|
49
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown-to-plain-text projection for compact summaries and labels.
|
|
3
|
+
* Parsing shares the renderer's streaming GFM grammar ({@link parseGfm}), so
|
|
4
|
+
* the projection strips exactly the markup the renderer would draw; raw HTML
|
|
5
|
+
* stays literal, links keep their labels, images keep alt text, and code
|
|
6
|
+
* keeps its source text.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { parseGfm } from './parse.ts'
|
|
10
|
+
|
|
11
|
+
/** Amount of parsed Markdown content returned by the extractor. */
|
|
12
|
+
export type MarkdownPlainTextMode = 'all' | 'first-line' | 'first-paragraph'
|
|
13
|
+
|
|
14
|
+
/** Options for {@link extractMarkdownPlainText}. */
|
|
15
|
+
export interface MarkdownPlainTextOptions {
|
|
16
|
+
/** Projection boundary; defaults to the complete document. */
|
|
17
|
+
mode?: MarkdownPlainTextMode
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface MarkdownNode {
|
|
21
|
+
type: string
|
|
22
|
+
value?: string
|
|
23
|
+
alt?: string
|
|
24
|
+
children?: MarkdownNode[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function inlineText(node: MarkdownNode): string {
|
|
28
|
+
switch (node.type) {
|
|
29
|
+
case 'text':
|
|
30
|
+
case 'inlineCode':
|
|
31
|
+
case 'code':
|
|
32
|
+
return node.value ?? ''
|
|
33
|
+
case 'image':
|
|
34
|
+
case 'imageReference':
|
|
35
|
+
return node.alt ?? ''
|
|
36
|
+
case 'break':
|
|
37
|
+
return '\n'
|
|
38
|
+
case 'html':
|
|
39
|
+
return node.value ?? ''
|
|
40
|
+
default:
|
|
41
|
+
return node.children?.map(inlineText).join('') ?? ''
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function compactInline(text: string): string {
|
|
46
|
+
return text.replace(/\s+/g, ' ').trim()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function blockText(node: MarkdownNode): string {
|
|
50
|
+
switch (node.type) {
|
|
51
|
+
case 'root':
|
|
52
|
+
case 'blockquote':
|
|
53
|
+
return node.children?.map(blockText).filter(Boolean).join('\n\n') ?? ''
|
|
54
|
+
case 'paragraph':
|
|
55
|
+
case 'heading':
|
|
56
|
+
return compactInline(inlineText(node))
|
|
57
|
+
case 'code':
|
|
58
|
+
return node.value?.trim() ?? ''
|
|
59
|
+
case 'list':
|
|
60
|
+
return node.children?.map(blockText).filter(Boolean).join('\n') ?? ''
|
|
61
|
+
case 'listItem':
|
|
62
|
+
return node.children?.map(blockText).filter(Boolean).join(' ') ?? ''
|
|
63
|
+
case 'table':
|
|
64
|
+
return node.children?.map(blockText).filter(Boolean).join('\n') ?? ''
|
|
65
|
+
case 'tableRow':
|
|
66
|
+
return node.children?.map(blockText).join('\t') ?? ''
|
|
67
|
+
case 'tableCell':
|
|
68
|
+
return compactInline(inlineText(node))
|
|
69
|
+
case 'html':
|
|
70
|
+
return node.value ?? ''
|
|
71
|
+
case 'thematicBreak':
|
|
72
|
+
case 'definition':
|
|
73
|
+
return ''
|
|
74
|
+
default:
|
|
75
|
+
return compactInline(inlineText(node))
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function findFirstParagraph(node: MarkdownNode): string | undefined {
|
|
80
|
+
if (node.type === 'paragraph') {
|
|
81
|
+
const text = compactInline(inlineText(node))
|
|
82
|
+
if (text !== '') return text
|
|
83
|
+
}
|
|
84
|
+
for (const child of node.children ?? []) {
|
|
85
|
+
const text = findFirstParagraph(child)
|
|
86
|
+
if (text !== undefined) return text
|
|
87
|
+
}
|
|
88
|
+
return undefined
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function fullText(root: MarkdownNode): string {
|
|
92
|
+
return blockText(root)
|
|
93
|
+
.split('\n')
|
|
94
|
+
.map(line => line.trim())
|
|
95
|
+
.join('\n')
|
|
96
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
97
|
+
.trim()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Parse GFM Markdown, remove its presentation markup, and preserve raw HTML literally.
|
|
102
|
+
* @param markdown - Markdown source.
|
|
103
|
+
* @param options - Optional extraction boundary.
|
|
104
|
+
* @returns Plain text for the whole document, first visible line, or first semantic paragraph.
|
|
105
|
+
*/
|
|
106
|
+
export function extractMarkdownPlainText(
|
|
107
|
+
markdown: string,
|
|
108
|
+
options: MarkdownPlainTextOptions = {},
|
|
109
|
+
): string {
|
|
110
|
+
const { mode = 'all' } = options
|
|
111
|
+
const root = parseGfm(markdown) as MarkdownNode
|
|
112
|
+
const all = fullText(root)
|
|
113
|
+
switch (mode) {
|
|
114
|
+
case 'all':
|
|
115
|
+
return all
|
|
116
|
+
case 'first-line':
|
|
117
|
+
return all.split('\n').find(line => line !== '') ?? ''
|
|
118
|
+
case 'first-paragraph':
|
|
119
|
+
return findFirstParagraph(root) ?? all.split('\n').find(line => line !== '') ?? ''
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Shared Markdown blockquote formatting for browser text. */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Project selected visible text as an ordinary Markdown blockquote.
|
|
5
|
+
* @param text - selected visible text without quote markers.
|
|
6
|
+
* @returns one `> `-prefixed line per normalized input line.
|
|
7
|
+
*/
|
|
8
|
+
export function formatQuoteText(text: string): string {
|
|
9
|
+
return text.replace(/\r\n?/gu, '\n').split('\n').map(line => `> ${line}`).join('\n')
|
|
10
|
+
}
|