Repository: sondregronas/mkdocs-callouts

Issue:
Support for GitHub-flavoured alert types (important, caution)
There are "caution" and "important" types that are not supported in MkDocs. One can convert those to "danger" and "warning" symbol but with a different title. Can this be automatically converted?

There is another plugin that does this: https://github.com/PGijsbers/admonitions?tab=readme-ov-file#limitations

Rational:

The markdown files will be rendered correctly even when exploring on GitHub.

Hints from issue comments:
@sondregronas: I'll look into it. For now you can disable aliases in the plugin and use it in conjunction with what you linked:

```yaml
plugins:
  - callouts:
      aliases: false
```@kiyoon: Thank you.

I guess I can turn off the aliases and make my custom admonitions. It requires a little bit of a CSS setup. @sondregronas: Found some time & just pushed some changes to support this, will push a new release soon.

Let me know if it works or not after updating - tests seem to pass.@kiyoon: This is a very smart fix and I'm impressed by how fast you did it!

I'll let you know soon, once I test this. @kiyoon: It does work very well! Thanks a lot :))@kiyoon: I ended up making my custom admonitions though! If anyone is interested, here is the CSS file.

```css
/*Template taken from mkdocs-material docs, and svg and color taken from github icons*/
:root {
  --md-admonition-icon--important: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"/></svg>');
  --md-admonition-icon--caution: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"/></svg>');
}
.md-typeset .admonition.important,
.md-typeset details.important {
  border-color: rgb(130, 80, 223);
}
.md-typeset .important > .admonition-title,
.md-typeset .important > summary {
  background-color: rgba(130, 80, 223, 0.1);
}
.md-typeset .important > .admonition-title::before,
.md-typeset .important > summary::before {
  background-color: rgb(130, 80, 223);
  -webkit-mask-image: var(--md-admonition-icon--important);
          mask-image: var(--md-admonition-icon--important);
}
.md-typeset .admonition.caution,
.md-typeset details.caution {
  border-color: rgb(207, 34, 46);
}
.md-typeset .caution > .admonition-title,
.md-typeset .caution > summary {
  background-color: rgba(207, 34, 46, 0.1);
}
.md-typeset .caution > .admonition-title::before,
.md-typeset .caution > summary::before {
  background-color: rgb(207, 34, 46);
  -webkit-mask-image: var(--md-admonition-icon--caution);
          mask-image: var(--md-admonition-icon--caution);
}

```

<img width="787" alt="image" src="https://github.com/user-attachments/assets/b1e3fdd7-2465-4c75-b11b-8ecea354275c">
@sondregronas: Looks good!

Solution patch:
diff --git a/pyproject.toml b/pyproject.toml
index 06e47aa..65b2f1c 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
 
 [project]
 name = "mkdocs-callouts"
-version = "1.14.1"
+version = "1.15.0"
 keywords = ["mkdocs", "mkdocs-plugin", "markdown", "callouts", "admonitions", "obsidian"]
 description = "A simple plugin that converts Obsidian style callouts and converts them into mkdocs supported 'admonitions' (a.k.a. callouts)."
 readme = "README.md"
diff --git a/src/mkdocs_callouts/utils.py b/src/mkdocs_callouts/utils.py
index 4b7a096..d1af598 100644
--- a/src/mkdocs_callouts/utils.py
+++ b/src/mkdocs_callouts/utils.py
@@ -87,6 +87,9 @@ def _parse_block_syntax(self, block) -> str:
 
         # Group 3: Callout block type (note, warning, info, etc.) + inline block syntax
         c_type = block.group(3).lower()
+        # Get a clean version of the callout type for the title, if it exists in order
+        # to use it as a fallback if the title is empty & we are using an alias
+        clean_c_type = c_type.split("|")[0].strip()
         c_type = re.sub(r" *\| *(inline|left) *$", " inline", c_type)
         c_type = re.sub(r" *\| *(inline end|right) *$", " inline end", c_type)
         c_type = re.sub(r" *\|.*", "", c_type)
@@ -100,6 +103,10 @@ def _parse_block_syntax(self, block) -> str:
 
         # Group 5: Title, add leading whitespace and quotation marks, if it exists
         title = block.group(5).strip()
+        # If we are using an alias without a title, use the alias
+        # We use startswith to avoid issues with the inline block syntax
+        if not title and not c_type.lower().startswith(clean_c_type.lower()):
+            title = clean_c_type.capitalize()
         title = f' "{title}"' if title else ""
 
         # Construct the new callout syntax ({indent}!!! note "Title")


Test patch:
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 03399ea..1549679 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -146,12 +146,12 @@ def test_aliases_enabled():
 
     # Test alias conversion
     mkdown = '> [!HINT]\n> Text'
-    result = '!!! tip\n\tText'
+    result = '!!! tip "Hint"\n\tText'
     assert (parser.parse(mkdown) == result)
 
     # Test alias conversion with inline block syntax
     mkdown = '> [!HINT | inline]\n> Text'
-    result = '!!! tip inline\n\tText'
+    result = '!!! tip inline "Hint"\n\tText'
     assert (parser.parse(mkdown) == result)
 
     # Test alias conversion where alias is a substring of another alias
@@ -403,3 +403,35 @@ def test_nested_codefences():
 > ```
 ```"""
     assert (convert(mkdown) == mkdown)
+
+
+def test_alias_titles():
+    # Test alias titles
+    mkdown = "> [!cAuTiON]"
+    result = "!!! warning \"Caution\""
+
+    assert (convert(mkdown) == result)
+
+    # Test normal titles
+    mkdown = "> [!WARNING]"
+    result = "!!! warning"
+
+    assert (convert(mkdown) == result)
+
+    # Test with inline block syntax
+    mkdown = "> [!WaRnINg | inline]"
+    result = "!!! warning inline"
+
+    assert (convert(mkdown) == result)
+
+    # Test alias titles with inline block syntax
+    mkdown = "> [!cAuTiON | inline]"
+    result = "!!! warning inline \"Caution\""
+
+    assert (convert(mkdown) == result)
+
+    # Test alias with a title
+    mkdown = "> [!cAuTiON] Title"
+    result = "!!! warning \"Title\""
+
+    assert (convert(mkdown) == result)
\ No newline at end of file