|
| 1 | +# Alerts usage and customization |
| 2 | + |
| 3 | +There are five default alerts, that are styled without configuration. These are the |
| 4 | +[GitHub |
| 5 | +alerts](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts): |
| 6 | + |
| 7 | +```md |
| 8 | +> [!NOTE] |
| 9 | +> Lorem ipsum |
| 10 | +``` |
| 11 | + |
| 12 | +```md |
| 13 | +> [!TIP] |
| 14 | +> Lorem ipsum |
| 15 | +``` |
| 16 | + |
| 17 | +```md |
| 18 | +> [!IMPORTANT] |
| 19 | +> Lorem ipsum |
| 20 | +``` |
| 21 | + |
| 22 | +```md |
| 23 | +> [!WARNING] |
| 24 | +> Lorem ipsum |
| 25 | +``` |
| 26 | + |
| 27 | +```md |
| 28 | +> [!CAUTION] |
| 29 | +> Lorem ipsum |
| 30 | +``` |
| 31 | + |
| 32 | +## Custom marker |
| 33 | + |
| 34 | +We have extended support similar to [how alerts work in |
| 35 | +Obsidian](https://help.obsidian.md/callouts) (where they are called "callouts"). |
| 36 | +The marker can be a custom multi-word string, like this: |
| 37 | + |
| 38 | +```md |
| 39 | +> [!CUSTOM MARKER] |
| 40 | +> Lorem ipsum |
| 41 | +``` |
| 42 | + |
| 43 | +By default, the above alert (with an arbitrary marker) is styled like `[!NOTE]`. |
| 44 | +This matches Obsidian's default behavior. If you want to style this separately, |
| 45 | +see [customizing fallback alert](#customizing-fallback-alert). |
| 46 | + |
| 47 | +## Custom title |
| 48 | + |
| 49 | +Alert title can optionally be set with the following extended syntax: |
| 50 | + |
| 51 | +```md |
| 52 | +> [!NOTE] A custom title |
| 53 | +> Lorem ipsum |
| 54 | +``` |
| 55 | + |
| 56 | +Additionally, custom titles for markers can be set in the configuration: |
| 57 | + |
| 58 | +```json |
| 59 | +{ |
| 60 | + "alertOptions": { |
| 61 | + "titles": { |
| 62 | + "note": "A custom title" |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +With the above example, `[!NOTE]` would *always* be rendered with the title *A |
| 69 | +custom title*. |
| 70 | + |
| 71 | +## Case sensitivity |
| 72 | + |
| 73 | +Marker names are matched case-insensitively, meaning `[!CUSTOM MARKER]`, |
| 74 | +`[!custom marker]` and `[!Custom Marker]` refer to the same type of alert. |
| 75 | + |
| 76 | +In the same way, all keys in `alertOptions.icons` and `alertOptions.titles` are |
| 77 | +case-insensitive. |
| 78 | + |
| 79 | +## Configuring alert icons |
| 80 | + |
| 81 | +Set custom icons for alerts by marker type like this: |
| 82 | + |
| 83 | +```json |
| 84 | +{ |
| 85 | + "alertOptions": { |
| 86 | + "icons": { |
| 87 | + "custom": "bell" |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +When set as a string, the icon is interpreted to be a valid |
| 94 | +[octicon](https://primer.style/octicons/) name. |
| 95 | + |
| 96 | +This would set the octicon [`bell`](https://primer.style/octicons/icon/bell-16/) |
| 97 | +for alert |
| 98 | +`[!CUSTOM]`. |
| 99 | + |
| 100 | +### Advanced icon configuration |
| 101 | + |
| 102 | +To use icons other than octicons, the value can be set as a path to an svg |
| 103 | +file, for example: |
| 104 | + |
| 105 | +Absolute path: |
| 106 | + |
| 107 | +- `"custom": "/home/user/.config/vivify/icons/flower.svg"` |
| 108 | + |
| 109 | +Home as tilde: |
| 110 | + |
| 111 | +- `"custom": "~/.config/vivify/icons/flower.svg"` |
| 112 | + |
| 113 | +Path relative to Vivify config directory: |
| 114 | + |
| 115 | +- `"custom": "./icons/flower.svg"` |
| 116 | + |
| 117 | +Even a raw svg string can be set in the configuration: |
| 118 | + |
| 119 | +- `"custom": "<svg> ... </svg>"` |
| 120 | + |
| 121 | +## Customizing alert colors |
| 122 | + |
| 123 | +Colors should be customized in your custom stylesheet (via the `"styles"` option |
| 124 | +in the [config](customization.md)). |
| 125 | + |
| 126 | +To set any color to a custom alert type: |
| 127 | + |
| 128 | +```css |
| 129 | +.alert-custom { --color: #00ff00; } |
| 130 | +``` |
| 131 | + |
| 132 | +The left-side border, title icon, and title text will be colored as `--color`. |
| 133 | + |
| 134 | +The CSS class is fully lowercased and in `kebab-case`. So for a marker with a |
| 135 | +multi-word name, this is how you'd set the color: |
| 136 | + |
| 137 | +```css |
| 138 | +.alert-my-multi-word-name { --color: #00ff00; } |
| 139 | +``` |
| 140 | + |
| 141 | +Instead of coming up with a new hex color, you may want to match to one of the |
| 142 | +default alerts' colors. Use one of these CSS variables: |
| 143 | + |
| 144 | +- `--alert-note` |
| 145 | +- `--alert-tip` |
| 146 | +- `--alert-important` |
| 147 | +- `--alert-warning` |
| 148 | +- `--alert-caution` |
| 149 | + |
| 150 | +For example: |
| 151 | + |
| 152 | +```css |
| 153 | +.alert-custom { --color: var(--alert-important); } |
| 154 | +``` |
| 155 | + |
| 156 | +## Examples |
| 157 | + |
| 158 | +Here are a few practical examples to achieve some types of alerts that have |
| 159 | +default styles in Obsidian, but not on GitHub: |
| 160 | + |
| 161 | +- `[!TODO]` |
| 162 | +- `[!QUESTION]` |
| 163 | +- `[!EXAMPLE]` |
| 164 | +- `[!SUCCESS]` |
| 165 | +- `[!FAILURE]` |
| 166 | + |
| 167 | +```json |
| 168 | +{ |
| 169 | + "alertOptions": { |
| 170 | + "icons": { |
| 171 | + "todo": "check-circle", |
| 172 | + "question": "question", |
| 173 | + "example": "list-unordered", |
| 174 | + "success": "check", |
| 175 | + "failure": "x" |
| 176 | + } |
| 177 | + } |
| 178 | +} |
| 179 | +``` |
| 180 | + |
| 181 | +```css |
| 182 | +.alert-todo { --color: var(--alert-note); } |
| 183 | +.alert-question { --color: var(--alert-warning); } |
| 184 | +.alert-example { --color: var(--alert-important); } |
| 185 | +.alert-success { --color: var(--alert-tip); } |
| 186 | +.alert-failure { --color: var(--alert-caution); } |
| 187 | +``` |
| 188 | + |
| 189 | +## Customizing fallback alert |
| 190 | + |
| 191 | +Any custom alert that hasn't been configured will have the same icon and color |
| 192 | +as `[!NOTE]`. If you want a whole separate color and icon for unconfigured |
| 193 | +alerts, use these options: |
| 194 | + |
| 195 | +```json |
| 196 | +{ |
| 197 | + "alertOptions": { |
| 198 | + "fallbackIcon": "alert" |
| 199 | + } |
| 200 | +} |
| 201 | +``` |
| 202 | + |
| 203 | +> [!NOTE] |
| 204 | +> `"fallbackIcon"` is a separate option outside of the `"icons"` table, but |
| 205 | +> accepts the same type of icon value as the [icon |
| 206 | +> customization](#configuring-alert-icons). |
| 207 | +
|
| 208 | +For the color, any alert that doesn't have a "known" marker gets a CSS class as |
| 209 | +`.fallback-alert`. So, to customize the color: |
| 210 | + |
| 211 | +```css |
| 212 | +.fallback-alert { --color: #ff0000; } |
| 213 | +``` |
0 commit comments