Description
Adds support for local CSS @imports and @importing CSS from notes.
Additional Information
Links: | |
---|---|
Maintainers: | personalizedrefrigerator |
Version: | 1.0.2 |
Minimum app version: | 3.0 |
Downloads: This version: | 1 |
Last updated: | 2025-03-05T20:27:10Z |
Joplin Local CSS @import
s
This is a proof-of-concept plugin intended to address this issue.
At present, it works by finding @import
s in <style>
blocks, then manually fetching and inserting the corresponding CSS file.
Example note
<style>
/* Import CSS from a file: */
@import "/tmp/test.css";
/* Import CSS from a note: */
@import ":/50775d77690042ad92fdc7478b539afa";
</style>
This is a note
Above, the @import ":/50775d77690042ad92fdc7478b539afa"
imports CSS from a note with ID 50775d77690042ad92fdc7478b539afa
. The note should contain a single css
code block contianing the CSS to be imported. For example,
Optionally, a comment can be included on the lines before the CSS block.
```css
/* CSS here! */
```
How it works
Currently, this plugin:
- Searches for
@import
s in<style>
blocks using regular expressions.- Although find-replace with regular expressions simplifies the implementation, it may cause issues if, for example, there are commented-out
@import
s. In the future, it may make sense to use a library like csstree to parse CSS and extract the imports.
- Although find-replace with regular expressions simplifies the implementation, it may cause issues if, for example, there are commented-out
- Fetches note/file imports and removes their
@import
statements from their parent style blocks. - Inserts the imported content using a new
<style>
element.
Known issues
- Using CSS supports/layer import options is unsupported.
- Does not support the Rich Text Editor.
- On mobile, does not allow importing CSS from files (only from other notes).
- Import failure errors may be logged to Joplin's console as a result of the original
@import
statements (before replacement).