Shared Blocks

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

Description

An Obsidian plugin that allows you to have common and shared sections between multiple notes.

Reviews

No reviews yet.

Stats

1
stars
291
downloads
0
forks
26
days
0
days
2
days
24
total PRs
0
open PRs
0
closed PRs
24
merged PRs
0
total issues
0
open issues
0
closed issues
45
commits

Latest Version

2 days ago

Changelog

  • Interface available in 8 more languages (Simplified Chinese, Japanese, Korean, Spanish, German, French, Brazilian Portuguese and Russian), following Obsidian's language setting.

README file from

Github

Shared Blocks

Latest release Downloads CI License: MIT

Write a block of text once, in one note, and reuse it anywhere in your vault. When you edit the original, every place that references it re-renders while you look at it.

Everything happens locally. The plugin reads and renders notes from your vault and nothing else: no account, no server, no telemetry, no network access of any kind.

Editing a shared block in one note while another note that references it twice updates on screen

Left: the note that defines the block. Right: a note that uses it twice, in Reading view. Editing the definition updates both copies as you type.

Interface languages: English, 简体中文, 日本語, 한국어, Español, Deutsch, Français, Português (Brasil) and Русский, following Obsidian's language setting. A translation that reads wrong? Open an issue with the text and what it should say.

How it works

Define a block in any note, between two markers on lines of their own:

==share:contact==
**Support:** [email protected]
Office hours: 9:00 – 17:00 CET
==/share==

The name accepts letters (accented and non-Latin included), digits, _ and -. A block with an empty body is ignored, so a half-written block reports itself as missing instead of quietly rendering nothing.

Reference it from any other note:

==ref:Company handbook^contact==

Company handbook is the note holding the definition — the same link text you would put in [[ ]], so a bare name, a subfolder path, or anything Obsidian can resolve from the note you are writing in. contact is the block name.

The reference renders the block's markdown in place, styled as a quoted block, in Reading view and in Live Preview alike. In Live Preview a reference on a line of its own shows as the rendered block, the way an embed does, and turns back into its ==ref:…== text when you click it or move the cursor onto its line. Edit the definition and every reference on screen updates, without reopening the note.

A note in Live Preview showing two shared blocks rendered in place, one nested inside the other

You rarely need to type a reference in full. After ==ref: the editor suggests the notes that define blocks; pick one and it suggests that note's blocks, then closes the reference for you.

References can be nested: a shared block may itself contain a reference to another one. A cycle is detected and reported in place rather than hanging.

Blocks with fill-in values

A block can be a small template. Write {{name}} where a value goes, or {{name|default text}} to give it a default:

==share:greeting==
Hello {{name}}, welcome to the {{team|support}} team.
==/share==

A reference passes the values after the block name, as key=value pairs. Put a value in double quotes when it has spaces, and write \" for a quote inside it:

==ref:Company handbook^greeting name=Ana team="customer success"==

This renders "Hello Ana, welcome to the customer success team." Leave team out and it reads "support". A placeholder with no value and no default stays in the text as {{name}}, highlighted, with the tooltip "No value for name". Keys the block does not use are ignored, and if a key is repeated the last one wins. Placeholders inside code spans and code blocks are left alone, so a block can show {{name}} as an example.

References without values, and blocks without placeholders, render exactly as before. When you pick a block from the autocomplete or the insert command, the reference starts with an empty name="" for each placeholder, ready to fill in; an empty value counts as not given, so the default applies. Renaming or moving the note keeps the values in every reference.

Commands

Command What it does
Share selection as a block Wraps the selected text in ==share:…== markers after asking for a name, and copies a reference to it, ready to paste into another note
Insert reference to a block Searches every block in the vault by name, note or text, and inserts a reference to the one you pick
Open the block referenced on this line Opens the note that defines the block, with the cursor on its ==share:…== marker
Refresh all blocks Rescans the whole vault and re-renders every reference on screen
Show cache stats Reports how many blocks are currently cached

You should not normally need the refresh command; it is there for when a block goes stale after an edit made outside Obsidian.

Performance

Opening a vault costs nothing: there is no scan at startup. A block is read the first time a reference asks for one, and edits are coalesced rather than handled per keystroke. The manual refresh scans in chunks, yielding between them, so a large vault does not freeze the window.

Limitations

  • In Live Preview only a reference on a line of its own is rendered. One in the middle of a sentence renders in Reading view and stays as highlighted text while you edit.
  • The markers use Obsidian's highlight syntax, so a block definition shows as a highlighted line in its source note.
  • Blocks are matched by note path and block name. Renaming or moving a note rewrites every ==ref:…== that pointed at it, the way Obsidian updates ordinary links; renaming a block means updating the references yourself.

Installing

In Obsidian, open Settings -> Community plugins -> Browse, search for Shared Blocks, then install and enable it.

To install it by hand instead, copy main.js, manifest.json and styles.css into <vault>/.obsidian/plugins/shared-blocks/ and enable the plugin in Settings → Community plugins.

Development

npm install
npm run dev     # esbuild in watch mode
npm run build   # type-check, then a production bundle
npm test        # unit tests for the parsing and cache logic

Tests run on plain Node with no extra dependency — Node strips the types itself from 22.18 onward, which is what engines asks for. They cover src/blocks.ts, the pure half of the plugin: block parsing, reference parsing, cache keys, and which blocks changed between two reads of a note. main.ts is the only file that touches the vault, the metadata cache or the DOM.

More plugins by Siulved54

Plugin What it does Source
Text Case and Cleanup Change case, make camelCase or slugs, sort lines and remove duplicates, and repair text pasted out of a PDF, without touching code or URLs. text-format
Typography as You Type Curly quotes, dashes and ellipses as you type, kept out of code and maths, with Backspace to take one back. smart-typography-plugin
Section Numbering Number headings as an outline (1, 1.1, 1.2) and keep every link to them working when they renumber. section-numbering
Spreadsheet to Table Paste cells from Excel or Google Sheets as a Markdown table with a real header, insert CSV files, and copy tables back out. spreadsheet-to-table
Hybrid Line Numbers Relative and hybrid line numbers for Vim-style jumps, where a folded section counts as one line. hybrid-line-numbers
List Item Callouts Colour a single list item as a callout by starting it with a character such as &, ! or ?. list-item-callouts
Folder Counts See how many notes or files each folder holds, right in the file explorer, with a vault total and folder exclusions. folder-counts
Note Reading Time Reading time of the current note or your selection in the status bar, optionally saved to a property. note-reading-time
Task Rollover Roll unfinished tasks from your last daily note into today's when it is created, with a real undo. task-rollover
Zoom Into Section Zoom into a heading or list item to see only it and its contents, with a breadcrumb bar to climb back out. zoom-into-section
Link Title on Paste Paste a web address and get a Markdown link with the page's title, fetched in the background and undone in one step. link-title-on-paste
Update Radar Checks your installed community plugins for updates in the background, shows what changed, and flags the ones that look abandoned. community-update-checker
Dataview to Bases Convert Dataview queries into Bases blocks, and see which queries in your vault can be converted. dataview-to-bases
Line Editing Commands Duplicate, join, sort and reverse lines, insert blank lines and jump to a line number, with multi-cursor support. line-editing-commands
Note Mover Rules Move notes into folders by ordered rules on tags, properties, titles and paths, with a preview before any bulk move. note-mover-rules
Tab History Keeps each tab's back and forward history across restarts, and adds commands to move, maximize and close tabs. tab-history
URL Cards Shows web addresses as cards with title, description and image, and reads existing cardlink blocks. url-cards
Vim Config Loads a vimrc-style file from your vault so your key mappings and editor commands are ready when vim mode starts. vim-config
Task Archive Moves completed tasks, with their sub-items, into an archive section or note. task-archive
Revisit Later Link the current note into a future daily note, with a date typed in plain English, so it comes back when you want to review it. revisit-later
Explorer Colors Plus Color files and folders in the file explorer, with a palette, cascading to children, and import from File Color. explorer-colors-plus
Book Lookup Create book notes from Open Library or Google Books, with cover images, ISBN search and Book Search compatible templates. book-lookup
Web Search Menu Search the web for selected text or the note title from the right-click menu, with engines you define. web-search-menu
Word Lookup Look up any word in a sidebar dictionary with definitions, phonetics, synonyms and antonyms, or create a note for it. word-lookup
Quick Translate Translate the selection or a whole note into another language with no account, keeping links, code and front matter untouched. quick-translate
Dice Rolls Inline dice rolls you click to reroll, in Live Preview and Reading view, with full dice notation, a roll dialog and a roll history. Reads Dice Roller notes. dice-rolls
Claude Studio Notion-style AI writing, chat and vault tools powered by your local Claude Code CLI. claude-studio

All of them are in the community directory: Settings -> Community plugins -> Browse, then search for the name.

License

MIT. See LICENSE.