Any Viewer

by tingke
5
4
3
2
1
Score: 50/100

Description

一个 Obsidian 插件:在笔记中插入并预览任意类型的文件 —— Word、Excel、PowerPoint、HTML、CSV 等,无法预览的格式显示文件卡片,一键调用系统默认应用打开。

Reviews

No reviews yet.

Stats

2
stars
271
downloads
0
forks
15
days
8
days
8
days
0
total PRs
0
open PRs
0
closed PRs
0
merged PRs
0
total issues
0
open issues
0
closed issues
27
commits

Latest Version

8 days ago

Changelog

本版本把 Any Viewer 从"几个内嵌预览"升级为可切片的内嵌系统:所有支持的文件类型都可以整份嵌入,也可以只嵌入特定页、工作表、单元格区域、行或元素锚点,尺寸语法与片段语法自由组合。

新增

  • 显示语法(片段),用于 ![[文件]] 嵌入:
    • pptx / docx:#page=3、#page=3~10、#3~(区间自动归一化、越界钳制、起始越界回退整份)
    • xlsx:#Sheet2、#A3:E8、#Sheet2!A1:C8、#5:20(激活工作表、单元格区域含合并单元格裁剪、行区间形式)
    • html:#元素id 滚动锚定
    • 片段与尺寸语法自由组合(![[deck.pptx#page=3|300]])
    • 嵌入标题栏显示片段徽标("第 2–4 页" / "Sheet2 · A1:D8")
    • xlsx 片段嵌入隐藏工作表标签栏(片段已锁定区域)
  • 标签页定位:片段嵌入点"在标签页打开",标签页渲染完整文件并自动滚动/激活到片段位置(页、工作表、行、锚点)
  • 渲染串行队列:重量级解析逐个执行并带 20 秒超时——同一笔记内大量同类型嵌入不再有并发解析死锁风险,标签页渲染可插队优先
  • 按文件名的兜底解析:关闭"检测所有文件扩展名"时嵌入照常解析(全库按文件名匹配,优先来源目录)
  • 动画降级展示:无法内置渲染的类型显示居中的内联 SVG 动画(文档 + 周期性摇动的挂锁,跟随主题,尊重系统"减少动态效果"设置)加一行文案——不再重复文件名和操作按钮

变更

  • pptx 单页嵌入收敛为实际幻灯片高度(无滚动条/黑边);多页区间与整份嵌入一致——固定视口高度、内容内部滚动
  • docx 页面水平居中;表格不再继承 Obsidian 预览样式(单元格/斑马纹/边框已提升特异性隔离)
  • 嵌入接管加全局兜底扫描:阅读模式渐进渲染 detach/reattach 的芯片不再永久残留
  • 未支持类型的降级展示重设计:居中动画 + 一行文案,交互(系统应用打开 / Shift 显示在文件夹)不变

修复

  • 范围片段起始列大于 1 时表格列数错位、渲染范围外列(exceljs 路径)
  • 范围嵌入的合并单元格在切片边界出现空洞(现在按交集裁剪,跨界合并从首个界内单元格续排)
  • "检测所有文件扩展名"关闭时嵌入显示为永久芯片(basename 兜底 + 渐进渲染 detach/reattach 后不再丢失接管)
  • Obsidian 预览表格样式渗入 xlsx 嵌入(margin/边框被主题覆盖)
  • pptx 渐进渲染下页隐藏过早应用导致"全部页都显示"(页数稳定后才应用)

Full Changelog: https://github.com/tingke/obsidian-any-viewer/compare/0.4.2...0.5.0

README file from

Github

Obsidian Any Viewer

Release Build & Release License: MIT

English | 中文

An Obsidian plugin to insert and preview any file type inside your notes — Word, Excel, PowerPoint, HTML, CSV and more. Unsupported formats get a neat file card that opens with the system default app.

Package name obsidian-any-viewer, plugin ID any-viewer.

Fragment syntax demo

✨ What's new in v0.6

  • docx outline panel: an H1–H9 outline tree (with page numbers) beside docx tabs — click to jump to a section
  • In-document search: Ctrl/Cmd+F inside tabs opens a native-style search bar with highlighting, match count and jump navigation; rebindable under Settings → Hotkeys
  • Reading position memory: tabs remember where you left off (and which worksheet you were on) and restore it on reopen. Fragment locate always wins; embeds never participate
  • HTML source mode: flip any HTML view between rendered and syntax-highlighted source
  • Single-element extraction: ![[page.html#hero]] renders just that element instead of the whole page
  • Edge-to-edge tabs: tab content fills the pane — no card border
  • Appearance tweaks: with Style Settings installed, fine-tune density, file icon colors and shapes (zero visual change without it)

Outline panel

Supported file types

Inline embeds + tab view

Format Rendering
.docx High-fidelity rendering (styles, page breaks, headers/footers) via docx-preview
.xlsx .xlsm Real cell styling: fills (incl. theme colors & tint), fonts, borders, alignment, merged cells, column widths, row heights, number formats via exceljs
.xls .csv .tsv Table rendering with sheet tabs via SheetJS
.pptx Slide rendering (great for image-based decks) via pptx-preview
.html .htm Sandboxed iframe (srcdoc with inlined stylesheets; script execution configurable)

Mixed embeds

File card fallback

Any other type Obsidian doesn't natively render (.zip, .exe, .psd, .sketch, …) becomes a file card: type icon + filename + size.

  • Click → open with the system default app
  • Shift+click → reveal in the system file manager (desktop only)

Left untouched

Images, audio, video, PDF, Markdown and Canvas are rendered by Obsidian itself.

Usage

Easy insertion (any type)

  • Command palette → Any Viewer: 插入本地文件(任意类型), or click the paperclip ribbon icon
  • Paste a copied file with Ctrl/Cmd+V, or drag & drop it into the editor
  • Files are stored in the vault (location configurable) and an ![[file]] embed is inserted at the cursor; name conflicts are auto-numbered

Embeds & sizing

Write ![[filename.ext]] in a note to preview it inline:

Syntax Effect
![[report.xlsx]] Default size (full width, default height from settings)
![[report.xlsx|300]] Card sized to 300px wide; content keeps natural size and scrolls inside
![[doc.docx|x400]] Height only: 400px tall
![[doc.docx|300x400]] 300px wide + 400px tall

Display syntax (fragments)

Pick which part of the file to show — combines freely with the sizing syntax (fragment before the \|, size after):

Syntax Effect
![[deck.pptx#page=3]] Only slide 3 (single page ≡ 3~3)
![[deck.pptx#page=3~10]] Slides 3–10, stacked (3~ = to the last slide)
![[doc.docx#page=2]] Only page 2 (same range forms as pptx)
![[doc.docx#Conclusion]] From the page containing that heading to the end of the document (falls back to the whole file if no heading matches)
![[book.xlsx#Sheet2]] Start on the named worksheet (tab bar stays)
![[book.xlsx#A1:D10]] Only that cell range
![[book.xlsx#Sheet2!A1:D10]] Named worksheet + range
![[book.xlsx#5:20]] Only rows 5–20
![[page.html#header]] Renders only that element (v0.6: single-element extraction)

Element extraction

Range rules: - works like ~; reversed ranges normalize automatically (8~3 → 3~8); the end clamps to the last page; an out-of-bounds start or an unresolved heading falls back to the whole file. The embed header shows a badge ("Pages 3–10", "Heading …"). Fragments scope the inline embed only (a worksheet/range fragment hides the sheet tab bar) — opening the file in a tab shows the whole document and auto-scrolls to the fragment position (like Obsidian's native PDF embeds). Note that #element-id means different things per channel: embeds extract the element, tabs render the full page and scroll.

Embeds have a header bar: click the filename or double-click the content to open the file in a tab; header buttons open a tab or the system app (HTML embeds additionally get a reading/source toggle).

Tab view

Clicking .docx/.xlsx/.xls/.csv/.tsv/.pptx/.html/.htm files in the explorer opens them in a full-height preview pane — edge-to-edge, no card border:

Tab fill

  • docx outline panel: H1–H9 tree on the left, click to jump, collapsible
  • In-document search: Ctrl/Cmd+F (rebindable in Settings → Hotkeys) opens the search bar; Enter / Shift+Enter to jump between matches, Esc to close; supported for docx / xlsx / pptx
  • Reading position memory: close and reopen — the view scrolls back to where you left off (xlsx also restores the last active worksheet)

In-document search

HTML source mode

Both HTML embeds (header button) and HTML tabs (pane action bar) offer a reading/source toggle: source mode shows the raw HTML with syntax highlighting (oversized files are truncated). #element-id fragment locating only applies in reading mode.

Source mode

Appearance tweaks (Style Settings)

With Style Settings installed, its panel gains an Any Viewer group:

  • Density & sizes: header height, toolbar buttons, content padding, table cell padding, table font size, scrollbar width, selection/hover tint strength
  • File icon colors: Word / Excel / PowerPoint / HTML (off by default — icons follow the host theme palette)
  • Shapes: compact mode, tighter/larger/square corners, flat embeds, no table stripes

Every option defaults to the plugin's built-in value — without Style Settings, or with everything untouched, the visuals are exactly as they've always been.

Style Settings

Coexisting with other plugins

  • Extensions claimed by other plugins are skipped automatically (with a notice); inline embeds keep working
  • Turning a format off in settings makes this plugin completely hands-off that type (view registration and embeds — restart required), leaving it to plugins like styled-ms-office-viewer or CodeSpace

Installation

Manual

  1. Download main.js, styles.css, manifest.json from the latest release
  2. Put them in <your vault>/.obsidian/plugins/any-viewer/
  3. Restart Obsidian → Settings → Community plugins → enable Any Viewer

BRAT

BRAT → Add Plugin → paste this repository's Git URL.

Privacy, cost & network access

  • Free, no paywall: Any Viewer is MIT-licensed freeware — no paid features, no ads, no license keys, no upsells. Nothing here requires payment, now or later.
  • No network access: files are parsed and rendered entirely on your device. The plugin itself makes zero network requests — no telemetry, no analytics, no AI calls; your documents never leave your vault.
  • One caveat: HTML embeds render local .html files inside a sandboxed iframe. If such a file itself references external URLs (CDN fonts / scripts / images), those assets are loaded by the embedded page — governed by Obsidian's CSP and the "Allow scripts in HTML" setting (on by default, can be turned off).

Building from source

npm install
npm run build     # produces main.js
npm test          # fragment parser + Style Settings consistency checks

The demo GIFs in this README are generated by promo/make_demo_gifs.py (python3 promo/make_demo_gifs.py) — regenerate after visual changes.

Known limitations

  • Legacy binary formats (.doc, .ppt) can't be previewed inline (file card instead); they still open with the system app
  • In HTML embeds, external <script src> may be blocked by Obsidian's CSP; inline scripts run fine
  • "Open with system app / reveal in file manager" is desktop-only
  • .pptx preview is static — animations and media don't play
  • In-document search covers docx / xlsx / pptx tabs only (HTML body lives inside an iframe; embeds have no search bar)
  • Reading position memory applies to the tab channel only; fragment locating always wins over memory restore
  • The docx outline relies on standard built-in heading styles (canonical style ids written by Word); generators using non-standard style ids silently show no outline
  • Compared to WASM-based viewers (e.g. styled-ms-office-viewer), docx/pptx fidelity is lower; both can coexist — tabs for them, inline embeds for Any Viewer

Acknowledgements

License

MIT