Skip to content

Commit

Permalink
6.1.0
Browse files Browse the repository at this point in the history
Close #56 - non-code block admonitions may now be created without a title
  • Loading branch information
valentine195 committed Jun 23, 2021
1 parent 91f2dc9 commit 07450ae
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,32 @@ content

This will create the appropriate admonition type, embed the content, and give it the supplied title.

### Titles

Titles should be placed after the admonition block. Currently, markdown in titles is not supported.

An empty title can be created by either placing two spaces after the admonition type:

```
!!! ad-<type>
content
--- admonition
```

or by placing empty double quotes:

```
!!! ad-<type> ""
content
--- admonition
```

### Collapsible

A collapsible admonition may be created using the following syntax:

```
Expand All @@ -394,9 +420,9 @@ content

### Caveats

1. Changes to the admonition content after render require the cache to be cleared. The note must be closed and re-opened (and sometimes, a different note must be opened first).
1. Changes to the admonition after render require the cache to be cleared. The note must be closed and re-opened (and sometimes, a different note must be opened first).
1. This is _all_ changes, including the admonition type, title, content, even whether or not a collapsible admonition is open or closed initially.
2. Nested admonitions are not currently supported.
3. Empty titles are not currently supported.

If you experience any bugs using this setting, please create an issue and I will look into them.

Expand Down Expand Up @@ -457,6 +483,7 @@ No additional features are planned at this time. If there is a feature missing t
# Version History

## 6.0.0

- Added ability to define admonitions without using a code block
- Added `.admonition-plugin` class to top level element
- Add command to "Insert Admonition" with a modal chooser
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-admonition",
"name": "Admonition",
"version": "6.0.2",
"version": "6.1.0",
"minAppVersion": "0.11.0",
"description": "Admonition block-styled content for Obsidian.md",
"author": "Jeremy Valentine",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-admonition",
"version": "6.0.2",
"version": "6.1.0",
"description": "Admonition block-styled content for Obsidian.md",
"main": "main.js",
"scripts": {
Expand Down
24 changes: 21 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ export default class ObsidianAdmonition
const elementMap: Map<Element, MarkdownRenderChild> = new Map();
const idMap: Map<string, MarkdownRenderChild> = new Map();
this.registerMarkdownPostProcessor(async (el, ctx) => {
if (!this.data.enableMarkdownProcessor) return;
if (END_REGEX.test(el.textContent) && push) {
push = false;
const lastElement = createDiv();
Expand Down Expand Up @@ -409,18 +410,35 @@ export default class ObsidianAdmonition
child.onload = async () => {
const source = el.textContent;

const [, col, type, title] = source.match(TYPE_REGEX) ?? [];
let [
,
col,
type,
title = type[0].toUpperCase() +
type.slice(1).toLowerCase()
]: string[] = source.match(TYPE_REGEX) ?? [];

if (!type) return;
let collapse;
if (/\?{3,}/.test(col)) {
collapse = /\+/.test(col) ? "open" : "closed";
}

if (
(title.trim() === "" || title === '""') &&
collapse !== undefined &&
collapse !== "none"
) {
title =
type[0].toUpperCase() + type.slice(1).toLowerCase();
new Notice(
"An admonition must have a title if it is collapsible."
);
}

const admonitionElement = await getAdmonitionElementAsync(
type,
title?.trim() ??
type[0].toUpperCase() + type.slice(1).toLowerCase(),
title.trim(),
this.admonitions[type].icon,
this.admonitions[type].color,
collapse
Expand Down
2 changes: 1 addition & 1 deletion src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export async function getAdmonitionElementAsync(
admonition.id = id;
}

if (title && title.length) {
if (title && title.trim().length) {
//
// Title structure
// <div|summary>.admonition-title
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"4.3.1": "0.12.0",
"4.4.2": "0.12.2",
"5.0.3": "0.12.2",
"6.0.2": "0.12.4"
"6.1.0": "0.12.4"
}

0 comments on commit 07450ae

Please sign in to comment.