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

Add GitHub style alerts / admonitions #519

Merged
merged 3 commits into from
Jan 19, 2025
Merged

Conversation

digitalmoksha
Copy link
Collaborator

@digitalmoksha digitalmoksha commented Jan 17, 2025

This adds support for GitHub style alerts, such as

> [!NOTE]
> Coming very soon

Note

Coming very soon

All the types are supported, NOTE, TIP, IMPORTANT, WARNING, and CAUTION

A couple enhancements have been made:

  1. you can use them anywhere a blockquote can be used, such as in a list item. So this will work:

    - item one
    
      > [!note]
      > Coming soon
    
  2. you can override the title that's displayed by putting text after the trigger. For example:

    > [!note] Exciting news!
    > Coming soon
    

    Instead of showing "Note" as the title, it will show "Exciting news!"

Related to #472

@digitalmoksha digitalmoksha self-assigned this Jan 17, 2025
Copy link
Contributor

Command Mean [ms] Min [ms] Max [ms] Relative
./bench.sh ./comrak-c97de7e 316.6 ± 2.7 314.3 325.4 2.90 ± 0.04
./bench.sh ./comrak-main 318.5 ± 1.8 316.8 323.6 2.92 ± 0.04
./bench.sh ./pulldown-cmark 109.2 ± 1.4 108.4 115.9 1.00
./bench.sh ./cmark-gfm 118.4 ± 13.1 113.2 181.0 1.08 ± 0.12
./bench.sh ./markdown-it 501.3 ± 15.7 481.3 543.8 4.59 ± 0.16

Run on Fri Jan 17 01:36:04 UTC 2025

Also allows overriding the title by specifying a string
after the alert syntax.
@digitalmoksha
Copy link
Collaborator Author

This is fully working. Just need to

  • add an option to enable it
  • add a couple more tests, including for sourcepos

Copy link
Owner

@kivikakk kivikakk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! (Minor change: XML attribute needs to be quoted.)

src/xml.rs Outdated Show resolved Hide resolved
Co-authored-by: Talya Connor <[email protected]>
@digitalmoksha
Copy link
Collaborator Author

I did run fuzzing with all_options with no problems. I tried quadratic and there was quickly a failure. But that happens on the current main, so it's not due to this PR.

@digitalmoksha digitalmoksha merged commit 428ad9a into main Jan 19, 2025
38 checks passed
@digitalmoksha digitalmoksha deleted the bw-admonmition-blocks branch January 19, 2025 03:29
mfontanini added a commit to mfontanini/presenterm that referenced this pull request Jan 23, 2025
This adds supports for markdown alerts (github/gitlab style) as support
for these was recently added to comrak. This for now looks close a block
quote except it also contains a title colored the same color as the
vertical bar prefix that shows up on the left of the block quote.

See kivikakk/comrak#519 and
kivikakk/comrak#521 for syntax but basically
this:

```markdown
> [!note]
> this is a note

> [!tip]
> this is a tip

> [!important]
> this is important

> [!warning]
> this is warning!

> [!caution]
> this advises caution!

>>> [!note] other title
ez
multiline
>>>
```

Renders like this:


![image](https://github.com/user-attachments/assets/219024ae-b635-4bf2-87ba-e252b64ebd67)
@nicoburns
Copy link
Contributor

Just wanted to express my appreciation for this feature! Sometimes open source is awesome: I just bump my comrak version (+enable the option) and suddenly I have support for this feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants