Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Admonitions #309

Closed
KyleKing opened this issue Feb 20, 2022 · 10 comments · Fixed by executablebooks/mdit-py-plugins#53 or KyleKing/mdformat-admon#1
Closed

Support Admonitions #309

KyleKing opened this issue Feb 20, 2022 · 10 comments · Fixed by executablebooks/mdit-py-plugins#53 or KyleKing/mdformat-admon#1
Labels
enhancement New feature or request plugin A plugin should be created or updated

Comments

@KyleKing
Copy link
Contributor

KyleKing commented Feb 20, 2022

Describe the problem/need and solution

Problem

Right now, mdformat breaks indentation for admonitions. Below is a repeatable example based on the first snippet from the admonition documentation

~/Developer > pipx install mdformat-gfm --include-deps
  installed package mdformat-gfm 0.3.5, installed using Python 3.10.2
  These apps are now globally available
    - markdown-it
    - mdformat
done! ✨ 🌟 ✨
~/Developer > pbpaste > ad_test.md
~/Developer > bat ad_test.md
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: ad_test.md
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ !!! type "optional explicit title within double quotes"
   2   │     Any number of other indented markdown elements.
   3   │
   4   │     This is the second paragraph.
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
~/Developer > mdformat ad_test.md
~/Developer > bat ad_test.md
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: ad_test.md
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ !!! type "optional explicit title within double quotes"
   2   │ Any number of other indented markdown elements.
   3   │
   4   │ ```
   5   │ This is the second paragraph.
   6   │ ```
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Solution

admonitions are not part of the CommonMark specification and would be best handled by a plugin (i.e. mdformat-admonition)

I would be happy to try writing one, but I wanted to open an issue first so that I'm not duplicating effort. I saw that there was at least one other issue with admonition problems, but there didn't seem to be any updates since: #53 (#53 (comment))

Benefit

Would be nice to have support for admonitions (particular for mkdocs which uses the markdown extension)

Guide for implementation

No response

Tasks and updates

No response

@KyleKing KyleKing added the enhancement New feature or request label Feb 20, 2022
@hukkin
Copy link
Owner

hukkin commented Feb 20, 2022

Hey thanks for the issue!

Yeah this should be a plugin, and the plugin template you linked should be helpful. The first step, however, is a parser extension for mdformat's Markdown parser (markdown-it-py which is a Python port of the JavaScript markdown-it).

You'll find the existing parser extensions in this collection repository: https://github.com/executablebooks/mdit-py-plugins. I suggest making a PR there (although it's entirely possible that you keep in a separate repo too).

Luckily you don't have to start from scratch: there seems to be a JavaScript version of the parser extension which you can port to Python https://github.com/commenthol/markdown-it-admon (I dont know whether the JS implementation is any good though).

@hukkin hukkin added the plugin A plugin should be created or updated label Feb 20, 2022
@KyleKing
Copy link
Contributor Author

Great! I've got a busy next few weeks, but I'll start on this once I have time!

@lorenzomorandini
Copy link

@KyleKing had any chance to work on this?

@KyleKing
Copy link
Contributor Author

KyleKing commented Sep 2, 2022

Thanks for reminder. I had completed forgotten about this ticket. This is still an issue for me, but haven't had time to work on it

@lyz-code
Copy link

@KyleKing I guess there is still no advance, isn't it?

lyz-code added a commit to lyz-code/blue-book that referenced this issue Nov 24, 2022
…s locally

If you're with the VPN connected, turn it off.

feat(aleph#PDB behaves weird): PDB behaves weird

Sometimes you have two traces at the same time, so each time you run a PDB
command it jumps from pdb trace. Quite confusing. Try to `c` the one you don't
want so that you're left with the one you want. Or put the `pdb` trace in a
conditional that only matches one of both threads.

fix(gitpython): Deprecate tmpdir in favour of tmp_path

feat(pytest#The tmp_path fixture): The tmp_path fixture

You can use the `tmp_path` fixture which will provide a temporary directory
unique to the test invocation, created in the base temporary directory.

`tmp_path` is a `pathlib.Path` object. Here is an example test usage:

```python
def test_create_file(tmp_path):
    d = tmp_path / "sub"
    d.mkdir()
    p = d / "hello.txt"
    p.write_text(CONTENT)
    assert p.read_text() == CONTENT
    assert len(list(tmp_path.iterdir())) == 1
    assert 0
```

fix(pytest#The tmpdir fixture): Deprecate the tmpdir fixture

Warning: Don't use `tmpdir` use `tmp_path` instead because `tmpdir` uses `py`
which is unmaintained and has unpatched vulnerabilities.

feat(python_snippets#Pad integer with zeros): Pad integer with zeros

```python
>>> length = 1
>>> print(f'length = {length:03}')
length = 001
```

feat(elasticsearch#Get documents that match a string): Get documents that match a string

```bash
curl \
    -H 'Content-Type: application/json' \
    -XPOST "https://localhost:9200/_search" \
    -d' { "query": { "query_string": {"query": "test company"} }}'
```

feat(linux_snippets#df and du showing different results): df and du showing different results

Sometimes on a linux machine you will notice that both `df` command (display
free disk space) and `du` command (display disk usage statistics) report
different output. Usually, `df` will output a bigger disk usage than `du`.

The `du` command estimates file space usage, and the `df` command shows file
system disk space usage.

There are many reasons why this could be happening:

* [Disk mounted over data](linux_snippets.md#disk-mounted-over-data)
* [Used deleted files](linux_snippets.md#used-deleted-files)

feat(linux_snippets#Clean up docker data): Clean up docker data

To remove unused `docker` data you can run `docker system prune -a`. This will
remove:

- All stopped containers
- All networks not used by at least one container
- All images without at least one container associated to them
- All build cache

Sometimes that's not enough, and your `/var/lib/docker` directory still weights
more than it should. In those cases:

- Stop the `docker` service.
- Remove or move the data to another directory
- Start the `docker` service.

In order not to loose your persisted data, you need to configure your dockers to
mount the data from a directory that's not within `/var/lib/docker`.

feat(mdformat#issues): Issues

- It doesn't yet
  [support admonitions](hukkin/mdformat#309)
- You can't
  [ignore some files](hukkin/mdformat#359),
  nor
  [some part of the file](hukkin/mdformat#53)
@KyleKing
Copy link
Contributor Author

Yeah, no progress yet

I actually had these tickets open to try to get to it this week, but haven't had time yet with school and holidays here

@KyleKing
Copy link
Contributor Author

KyleKing commented Nov 26, 2022

Submitted a PR! It is a Draft, but I'll finish up and mark it ready for review sometime tomorrow

@KyleKing
Copy link
Contributor Author

And I started the plugin for mdformat-admon here: https://github.com/KyleKing/mdformat-admon

@KyleKing
Copy link
Contributor Author

KyleKing commented Dec 14, 2022

This ticket keeps accidentally closing...but I had some time to make progress today!

If anyone is more familiar with mdformat and can weigh in on my implementation, let me know:

https://github.com/KyleKing/mdformat-admon/blob/main/mdformat_admon/plugin.py

@KyleKing
Copy link
Contributor Author

KyleKing commented Dec 15, 2022

After a long, busy year, I finally have a v0.0.1 release of the admonition plugin!

I will test it in a real world project and will revisit if formats other than !!! will be supported, but I think we can close this issue (third times the charm!) and track any issues around admonition support in: https://github.com/KyleKing/mdformat-admon/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request plugin A plugin should be created or updated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants