Color mode

Attachment

Attachment link and embed card rendering for Obsidian wikilinks.

日本語

Overview

attachment() provides the renderAttachment hook that @riebeckite/plugin-obsidian-markdown uses when a wikilink resolves to a non-image file ([[report.pdf]], ![[report.pdf]], ...).

Without this plugin, those wikilinks fall back to a plain download link.

Usage

ts
import { defineConfig } from "@riebeckite/core";
import { attachment } from "@riebeckite/plugin-attachment";
import { obsidianMarkdown } from "@riebeckite/plugin-obsidian-markdown";
 
export default defineConfig({
  // ...
  plugins: [obsidianMarkdown(), attachment()],
});

Rendering

html
<a class="wikilink wikilink-attachment" href="..." download>label</a>

Embed (![[file]])

html
<aside class="attachment-card rr-attachment" data-attachment-path="...">
  <div class="attachment-card__meta">
    <span class="attachment-card__format">PDF</span>
    <span class="attachment-card__size">1.2 MB</span>
  </div>
  <div class="attachment-card__name">report.pdf</div>
  <a class="attachment-card__download" href="..." download>label</a>
</aside>
  • Format is the uppercased file extension
  • Size is read from disk under config.content.directory (path-traversal safe) and omitted when the file cannot be read
  • The embed card carries the stable rr-attachment root hook that themes may target

Styles ship in style.css (inline attachment links also get a ↓ suffix).

Options

Option Type Default Description
showSize boolean true Read the file size and show it in the embed card

Exports

  • attachment(options?) / attachmentPlugin — plugin factory
  • Type: AttachmentOptions

See also

History

1 changesCollapseExpand
1 + <!-- Generated from packages/plugins/attachment/README.md. Do not edit this page directly; edit the package README and run `pnpm docs:sync`. -->
2 +
3 + # Attachment
4 +
5 + Attachment link and embed card rendering for Obsidian wikilinks.
6 +
7 + [日本語](./attachment.md)
8 +
9 + ## Overview
10 +
11 + `attachment()` provides the `renderAttachment` hook that
12 + `@riebeckite/plugin-obsidian-markdown` uses when a wikilink resolves to a
13 + non-image file (`[[report.pdf]]`, `![[report.pdf]]`, ...).
14 +
15 + Without this plugin, those wikilinks fall back to a plain download link.
16 +
17 + ## Usage
18 +
19 + ```ts
20 + import { defineConfig } from "@riebeckite/core";
21 + import { attachment } from "@riebeckite/plugin-attachment";
22 + import { obsidianMarkdown } from "@riebeckite/plugin-obsidian-markdown";
23 +
24 + export default defineConfig({
25 + // ...
26 + plugins: [obsidianMarkdown(), attachment()],
27 + });
28 + ```
29 +
30 + ## Rendering
31 +
32 + ### Link (non-embed)
33 +
34 + ```html
35 + <a class="wikilink wikilink-attachment" href="..." download>label</a>
36 + ```
37 +
38 + ### Embed (`![[file]]`)
39 +
40 + ```html
41 + <aside class="attachment-card rr-attachment" data-attachment-path="...">
42 + <div class="attachment-card__meta">
43 + <span class="attachment-card__format">PDF</span>
44 + <span class="attachment-card__size">1.2 MB</span>
45 + </div>
46 + <div class="attachment-card__name">report.pdf</div>
47 + <a class="attachment-card__download" href="..." download>label</a>
48 + </aside>
49 + ```
50 +
51 + - Format is the uppercased file extension
52 + - Size is read from disk under `config.content.directory` (path-traversal
53 + safe) and omitted when the file cannot be read
54 + - The embed card carries the stable `rr-attachment` root hook that themes
55 + may target
56 +
57 + Styles ship in `style.css` (inline attachment links also get a `↓` suffix).
58 +
59 + ## Options
60 +
61 + | Option | Type | Default | Description |
62 + | ------ | ---- | ------- | ----------- |
63 + | `showSize` | `boolean` | `true` | Read the file size and show it in the embed card |
64 +
65 + ## Exports
66 +
67 + - `attachment(options?)` / `attachmentPlugin` — plugin factory
68 + - Type: `AttachmentOptions`
69 +
70 + ## See also
71 +
72 + - [Plugin guide](../reference/plugin-api.en.md)
73 + - [`@riebeckite/plugin-obsidian-markdown`](./obsidian-markdown.en.md)
74 +