Skip to content

Repository files navigation

Obsidian Units

Soulver-style inline unit conversions for Obsidian notes.

Usage

Wrap a conversion expression in inline code to show the result automatically:

I need `33 meters to feet` of lumber.

In Reading View and Live Preview, Obsidian Units renders the calculated result after the inline code without changing the note text.

If the surrounding sentence already supplies the unit, add | value:

I need `3 kg to pound | value` pounds of soil.

Inline render modes:

  • 33 meters to feet renders the value and unit.
  • 33 meters to feet | value renders only the value.
  • 33 meters to feet | unit renders only the target unit name.

For editors that auto-pair backticks, a trailing plural s after the inline code is tolerated:

`33 ounces to gram`s

renders as 935.5349 grams, not 935.5349 gramss.

In Live Preview, Obsidian Units keeps the inline code editable while your cursor is inside it, so auto-paired backticks do not prevent you from finishing a target unit or adding | value. You can also type the target unit in singular form; the rendered result uses the target value to choose singular or plural output.

Inline arithmetic is also supported:

`10/2`
`10 / 2`
`10 / 2 =`
`(10 + 2) / 3`
`2^8`

Inline arithmetic can reference numeric labels from earlier lines. The context is parsed top-to-bottom; later assignments override earlier ones from that point onward.

oldPay = `940`
oldCPI = `290`
newCPI = `330`
newPay = `oldPay (newCPI / oldCPI)`

oldPay = `1000`
newerPay = `oldPay (newCPI / oldCPI)`

The labels above are available by name inside later inline arithmetic expressions. Earlier results are not recalculated from later assignments.

Performance Note

Variable references are currently resolved by scanning earlier note content for each inline expression. This is simple and works well for typical notes, but large calculation-heavy documents should eventually use a per-render-pass top-down context cache.

You can also write a conversion expression, place the cursor on that line, and run Obsidian Units: Convert units in selection or current line from the command palette.

Examples:

5 ft to cm
2 cups to ml
180 lb to kg
72 F to C
55 mph to km/h
10 MiB to MB

The command replaces the expression with:

5 ft = 152.4 cm

You can also select an expression inside a larger line and convert only the selection.

Commands

  • Convert units in selection or current line replaces the selected expression, or the current line if there is no selection.
  • Insert unit conversion result only inserts only the result at the cursor or over the current selection.

Supported Categories

  • Length
  • Area
  • Mass
  • Volume
  • Speed
  • Acceleration
  • Data
  • Time
  • Pressure
  • Energy
  • Power
  • Temperature

The conversions.tsv file is a planning/reference list for future category expansion. Runtime conversion is handled by TypeScript unit tables that convert through one base unit per category.

Material densities (mass ↔ volume)

Mass and volume are different dimensions, so a conversion like 1 tsp to g is incomplete — the answer depends on what's in the teaspoon. Once you teach the plugin a material's density, expressions like the following work in either direction:

`1 tsp of maple syrup to g`     → 6.7503 grams
`100 g of maple syrup to ml`    → 72.993 milliliters

The keyword of <material> appears between the source unit and to/as/in/->. The material name can contain spaces and is matched case-insensitively. Mismatched dimensions other than mass ↔ volume are still rejected (the plugin does not bridge volume → length, etc.).

Adding a density via the UI

In Settings → Obsidian Units → Material densities, click Add density. The modal collects three fields:

  • Material name — how you'll refer to the material in expressions.
  • Density value — the numeric density.
  • Density unit — pick from g/ml, kg/m^3, lb/ft^3, or oz/fl oz.

Edit or delete existing entries from the same screen. Changes take effect immediately in open Live Preview panes.

Hand-editing the data file

Densities are persisted in the plugin's data.json (alongside other settings). The shape is:

{
  "densities": [
    { "name": "maple syrup", "value": 1.37, "unit": "g/ml" },
    { "name": "olive oil",   "value": 0.91, "unit": "g/ml" }
  ]
}

Reference values (for copying):

Material Density (g/mL)
Water 1.00
Whole milk 1.03
Butter 0.91
All-purpose flour (sifted) 0.53
Granulated sugar 0.85
Honey 1.42
Maple syrup 1.37
Olive oil 0.91

Flour density varies a lot with packing — adjust to your own measurement.

Development

npm install
npm run dev

For a production build:

npm run build

About

Soulver-style inline unit conversions for Obsidian notes.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages