Tailwind Snippet

by Nicholas Wilcox
5
4
3
2
1
Score: 51/100

Description

Category: Customization & UI

The Tailwind Snippet plugin integrates TailwindCSS with Obsidian, enabling users to generate and manage custom CSS snippets within their vault. The plugin allows for automatic updates of snippets based on file changes and provides options for customizing CSS, such as using Tailwind's Preflight styles, adding prefix selectors, and adjusting the PostCSS entrypoint. It also supports a custom Tailwind theme and entrypoints for dynamic content generation. This plugin enhances the styling capabilities of Obsidian with minimal configuration, while also allowing users to integrate Tailwind's powerful utilities and theming features.

Reviews

No reviews yet.

Stats

28
stars
1,002
downloads
1
forks
603
days
440
days
440
days
1
total PRs
0
open PRs
0
closed PRs
1
merged PRs
5
total issues
1
open issues
4
closed issues
52
commits

Latest Version

a year ago

Changelog

Added

  • Note on Tailwind versions

Changed

  • Updated non-tailwind dependencies

README file from

Github

Tailwind Snippet Obsidian Plugin

This plugin uses TailwindCSS as a PostCSS plugin to generate a CSS snippet in your Obsidian vault.

Disclaimer

This repository and its author are not affiliated with Tailwind.

How it works

This plugin implements Tailwind's PostCSS installation guide with the postcss JavaScript API. This produces a CSS snippet which you must manually enable once it is created. This snippet will automatically update based on changes to your files and settings.

This plugin makes use of the FileSystemAdapter API to read and write files in your vault's configuration directory.

This plugin adds a ribbon icon that allows you to manually trigger a refresh of the generated CSS snippet. This can be useful when non-Markdown files contain Tailwind classes.

If you aren't seeing changes that you expect, you may need to manually restart the plugin.

Note on Tailwind versions

This plugin is made with Tailwind v3. There are no plans to update this plugin to work with the latest Tailwind version, v4.

Briefly put, Tailwind v4 has sufficiently refactored and optimized the PostCSS plugin method of using Tailwind, such that it is difficult if not impossible for me to reconcile Tailwind v4 with the Obsidian runtime environment (i.e., Electron).

For those who are curious, you are welcome to clone this repository, upgrade to the latest Tailwind version, and observe the resulting esbuild errors.

Settings

Preflight

Preflight is a set of base styles that Tailwind injects into its @tailwind base directive. More literally, preflight is one of Tailwind's core plugins, and it parses a static stylesheet named preflight.css, feeding the styles into its addBase utility function.

However, the preflight plugin uses __dirname and path.join to locate the stylesheet, which results in an error in the context of the Obsidian application built with Electron. Additionally, Preflight styles conflict with Obsidian's base styles such that:

  1. the Obsidian UI is affected by Preflight styles, and
  2. some Preflight styles are overshadowed by Obsidian styles.

Therefore, this plugin (the tailwind-snippet plugin) does not apply Preflight styles by default. You can enable Preflight in the plugin settings, which will direct the plugin to source a packaged copy of preflight.css using the Obsidian API.

Prefix selector

You may also control what is affected by Tailwind's CSS rules by enabling this plugin's prefix selector option. This will add a prefix (default .tailwind) to all CSS selectors using a descendant combinator. so that .a, #foo.bar becomes .tailwind .a, .tailwind #foo.bar.

You can configure this so that only certain notes (or even certain sections of notes) are affected by Tailwind.

Combining with Preflight setting

You may have mixed success with the Preflight setting described above. If Obsidian's CSS rules are taking precedence over Preflight's styles, then setting a prefix selector may help Preflight take control.

PostCSS entrypoint

By default, this plugin will use Tailwind's default input template, which combines three of its directives:

@tailwind base;
@tailwind components;
@tailwind utilities;

You can specify a custom entrypoint using a file path that is relative to your vault's configuration directory (.obsidian/. This is useful if you want to use Tailwind's @layer directive for your own purposes.

See Using CSS and @layer from Tailwind's documentation for more information.

Tailwind theme

You can specify a custom Tailwind theme using a file path that is relative to your vault's configuration directory. The file contents should be a JSON object. This is useful if you want to replace or extend Tailwind's default theme.

Two caveats to this setting:

For now, you are limited to the themes you can define with a static JSON file.

Tailwind entrypoints

You can specify file globs relative to your vault's configuration directory that will be included in Tailwind's process. This is helpful if other files contain Tailwind CSS class names and use them to dynamically generate Markdown content.

Developer Notes

This is a fork of Obsidian's sample plugin repository. Changes other than implementing this plugin include:

  • Adding predev and prebuild NPM scripts to automatically copy Tailwind's preflight.css file from node_modules into the project root.
  • Various modifications to the release GitHub workflow.
  • Adding a custom esbuild plugin to copy this plugin's files into a test vault.

Test Vault

This repository contains an example Obsidian vault to showcase and test the plugin's functionality. You will need to enable this plugin after initially opening the folder in Obsidian, and then you must enable the generated CSS snippet after that to see the effects.

hot-reload

This repository also declares pjeby's hot-reload plugin as a submodule within the test vault's .obsidian/plugins/ directory. In order to actually download hot-reload, you must run the following commands after cloning this repository:

git submodule init
git submodule update

After that, you should be able to run npm run dev and then open the vault.

Similar Plugins

info
• Similar plugins are suggested based on the common tags between the plugins.
Custom Frames
4 years ago by Ellpeck
An Obsidian plugin that turns web apps into panes using iframes with custom styling. Also comes with presets for Google Keep, Todoist and more.
Obsidian Stylist
3 years ago by ixth
Obsidian plugin that allows to add classes and styles on markdown blocks
Base Tag Renderer
3 years ago by Darren Kuro
A lightweight obsidian plugin to render the basename of tags in preview mode.
Custom Classes
3 years ago by Lila Rest
A minimal Obsidian plugin that allows you to add your own HTML classes to chosen Markdown elements directly from your notes.
Code Styler
3 years ago by Mayuran Visakan
A plugin for Obsidian.md for styling codeblocks and inline code
Sheets Extended
3 years ago by NicoNekoru
Plugin that adds features to tables in obsidian including merging, vertical headers, and custom css
Checkbox styling helper
2 years ago by JaewonE
Helps you styling checkboxes in preview mode.
CSS Inserter
2 years ago by Erika Gozar
Inserts user-defined css snippets into the selected text.
css snippets
5 years ago by Daniel Brandenburg
Obsidian plugin for css snippets
Contextual Typography
5 years ago by mgmeyers
Admonition
5 years ago by Jeremy Valentine
Adds admonition block-styled content to Obsidian.md
Markdown Tags
a year ago by John Smith III
Enhance your Markdown documents with custom tags. Use predefined or custom labels, customizable colors, and arrow indicators to visually track tasks and statuses.
Source Mode Styling
3 months ago by Chris Howard
Obsidian plugin. Provides a customisable raw look in source mode using a monospace font to clearly differentiate from Live Preview.
Frontmatter to HTML Attributes
2 months ago by Tarek Saier
Makes YAML frontmatter available as data-* attributes in HTML, enabling metadata based CSS styling.