diff --git a/src/directives/admonitions.ts b/src/directives/admonitions.ts
index 4511929..28d1752 100644
--- a/src/directives/admonitions.ts
+++ b/src/directives/admonitions.ts
@@ -27,11 +27,16 @@ class BaseAdmonition extends Directive {
map: data.map,
block: true
})
- adToken.attrSet("class", "admonition")
- if (this.title)
+ if (data.options.class?.length >= 1) {
+ // Custom class information must go first for styling
+ // For example, `class=tip, kind=seealso` should be styled as a `tip`
+ adToken.attrSet("class", data.options.class.join(" "))
+ adToken.attrJoin("class", "admonition")
+ } else {
+ adToken.attrSet("class", "admonition")
+ }
+ if (this.title) {
adToken.attrJoin("class", this.title.toLowerCase().replace(/ /g, ""))
- if (data.options.class) {
- adToken.attrJoin("class", data.options.class.join(" "))
}
newTokens.push(adToken)
diff --git a/src/directives/main.ts b/src/directives/main.ts
index 848b85f..05bf374 100644
--- a/src/directives/main.ts
+++ b/src/directives/main.ts
@@ -182,11 +182,7 @@ export default function directiveToData(
;[body, options, bodyOffset] = parseDirectiveOptions(body, directive)
}
let args: string[] = []
- if (
- !directive.required_arguments &&
- !directive.optional_arguments &&
- !Object.keys(options).length
- ) {
+ if (!directive.required_arguments && !directive.optional_arguments) {
if (firstLine) {
bodyOffset = 0
body = [firstLine].concat(body)
diff --git a/tests/fixtures/directives.admonitions.md b/tests/fixtures/directives.admonitions.md
new file mode 100644
index 0000000..cf77b69
--- /dev/null
+++ b/tests/fixtures/directives.admonitions.md
@@ -0,0 +1,216 @@
+Admonition:
+.
+```{admonition} This is a **title**
+An example of an admonition with custom _title_.
+```
+.
+
+.
+
+Note on split lines:
+.
+```{note} An example
+of an admonition on two lines.
+```
+.
+
+.
+
+[FIX] Note on a single line [See #154](https://github.com/executablebooks/MyST-Parser/issues/154)
+.
+```{danger} An example of an admonition on a single line.
+```
+.
+
+.
+
+Admonition with overridding class name
+.
+```{admonition} This is a title
+:class: tip
+An example of a `tip` with a custom _title_.
+```
+.
+
+.
+
+nested-admonition
+.
+````{note} This is a note
+```{warning} This is a nested warning
+```
+````
+.
+
+.
+
+`attention` admonition:
+.
+```{attention}
+An example of a attention admonition.
+```
+.
+ An example of a attention admonition. An example of a caution admonition. An example of a danger admonition. An example of an error admonition. An example of a hint admonition. An example of an important admonition. An example of a note admonition. An example of a tip admonition. An example of a warning admonition. See other things here! Not a title
+See other things here! Not a title See other things here! Some content See other things here! This is a note This is a nested warning