- Preview not available{ext ? ` for .${ext} files` : ' for this file'}
+ Preview not available{reason ? '' : ext ? ` for .${ext} files` : ' for this file'}
- Use the download button to view this file
+ {reason ?? 'Use the download button to view this file'}
)
diff --git a/apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/heading-anchors.test.ts b/apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/heading-anchors.test.ts
index 12f42b48c8a..dba7cbd7250 100644
--- a/apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/heading-anchors.test.ts
+++ b/apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/heading-anchors.test.ts
@@ -3,8 +3,8 @@
*/
import { Editor } from '@tiptap/core'
import { afterEach, describe, expect, it } from 'vitest'
-import { createMarkdownContentExtensions } from './extensions'
-import { findHeadingPos } from './heading-anchors'
+import { createMarkdownContentExtensions } from '@/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/extensions'
+import { scrollToHeading } from '@/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/heading-anchors'
let editor: Editor | null = null
afterEach(() => {
@@ -12,21 +12,42 @@ afterEach(() => {
editor = null
})
-/** A ProseMirror doc parsed from markdown, for the position-resolution tests. */
-function docOf(markdown: string) {
+function editorOf(markdown: string) {
editor = new Editor({ extensions: createMarkdownContentExtensions() })
editor.commands.setContent(markdown, { contentType: 'markdown' })
- return editor.state.doc
+ return editor
}
-describe('findHeadingPos', () => {
- it('disambiguates duplicate slugs GitHub-style (foo, foo-1, foo-2)', () => {
- const doc = docOf('# Notes\n\na\n\n# Notes\n\nb\n\n# Notes\n\nc')
- const first = findHeadingPos(doc, 'notes')
- const second = findHeadingPos(doc, 'notes-1')
- const third = findHeadingPos(doc, 'notes-2')
- expect(first).toBeGreaterThanOrEqual(0)
- expect(second).toBeGreaterThan(first)
- expect(third).toBeGreaterThan(second)
+describe('Markdown heading navigation', () => {
+ it.each([
+ ['Unicode headings', '# Café 你好', 'café-你好', 0],
+ ['punctuation spacing', '# Network & data', 'network--data', 0],
+ ['existing suffixes', '# Notes\n\n# Notes-1\n\n# Notes', 'notes-2', 2],
+ ] as const)('scrolls to GitHub fragments for %s', (_name, markdown, slug, index) => {
+ const editor = editorOf(markdown)
+ const headings = editor.view.dom.querySelectorAll