Skip to content

Commit

Permalink
Merge pull request #3 from Mara-Li/main
Browse files Browse the repository at this point in the history
feat: inline admonition
  • Loading branch information
sondregronas authored Jul 29, 2022
2 parents 143af9b + b8b8b27 commit 9e8246e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
[![codecov](https://codecov.io/gh/sondregronas/mkdocs-callouts/branch/main/graph/badge.svg?token=N5IDI7Q4NZ)](https://codecov.io/gh/sondregronas/mkdocs-callouts)
[![Buymeacoffee](https://badgen.net/badge/icon/buymeacoffee?icon=buymeacoffee&label)](https://www.buymeacoffee.com/u92RMis)

A simple plugin that converts Obsidian style callouts and converts them into mkdocs supported 'admonitions' (a.k.a. callouts).
A simple plugin that converts Obsidian style callouts and converts them into mkdocs supported ['admonitions'](https://squidfunk.github.io/mkdocs-material/reference/admonitions/) (a.k.a. callouts).

## Setup
Install the plugin using pip:

`pip install mkdocs-callouts`

Activate the plugin in `mkdocs.yml`, note that the markdown_extensions `nl2br`, `admonition` and `pymdownx.details` are required for this plugin to render correctly:
Activate the plugin in `mkdocs.yml`, note that some markdown_extensions are required for this plugin to function correctly:

```yaml
markdown_extensions:
- nl2br
- admonition
- pymdownx.details
- pymdownx.superfences

plugins:
- search
Expand All @@ -43,4 +44,22 @@ and turns it into:
with confidence using Obsidian.
```

### Foldable blocks
Foldable blocks are also supported. (`> [!INFO]- Foldable closed by default`, `> [!INFO]+ Foldable open by default`)

### Inline blocks
To turn a callout block into an inline block you can use the `|left` or `|right` syntax in the type notation like so:
```
> [!INFO|left] -> !!! info inline (alt: [!INFO | left])
> [!INFO|inline] -> !!! info inline
> [!INFO|right] -> !!! info inline end
> [!INFO|inline end] -> !!! info inline end
```

The following also works, but Obsidian may not be able to render the block type properly.
```
> [!INFO inline] --> !!! info inline
> [!INFO inline end] --> !!! info inline end
```
To get more information about inline blocks, or how to add your own custom callout blocks, check the [Material Mkdocs Documentation](https://squidfunk.github.io/mkdocs-material/reference/admonitions/#inline-blocks).
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='mkdocs-callouts',
version='1.4.1',
version='1.5.0',
description="A simple plugin that converts Obsidian style callouts and converts them into mkdocs supported 'admonitions' (a.k.a. callouts).",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
5 changes: 4 additions & 1 deletion src/mkdocs_callouts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ def parse_callout_syntax(line: str) -> str:
indent = block.group(1).count('>')
indent = '\t' * (indent - 1)

# Group 2: Callout block type (note, warning, info, etc.)
# Group 2: Callout block type (note, warning, info, etc.) + inline block syntax
type = block.group(2).lower()
type = re.sub(r' ?\| *(inline|left) *$', ' inline', type)
type = re.sub(r' ?\| *(inline end|right) *$', ' inline end', type)
type = re.sub(r' ?\|.*', '', type)

# Group 3: Foldable callouts
syntax = {'-': '???', '+': '???+', '': '!!!'}
Expand Down
20 changes: 20 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ def test_nested_callouts():
assert (convert(mkdown) == result)


def test_custom_callouts():
mkdown = '> [!CUSTOM] Custom callout\n> Text'
result = '!!! custom "Custom callout"\n\tText'
assert (convert(mkdown) == result)


def test_inline_blocks():
mkdown = '> [!infobox|left]\n> Text'
result = '!!! infobox inline\n\tText'
assert (convert(mkdown) == result)

mkdown = '> [!infobox|right]\n> Text'
result = '!!! infobox inline end\n\tText'
assert (convert(mkdown) == result)

mkdown = '> [!infobox|other] Title\n> Text'
result = '!!! infobox "Title"\n\tText'
assert (convert(mkdown) == result)


def test_folded_callouts():
# Test folded block, closed by default
mkdown = '> [!INFO]- Folded block\n> Folded content'
Expand Down

0 comments on commit 9e8246e

Please sign in to comment.