Skip to content

Add support for GitHub-style alert - #158

Open
guoPhineas wants to merge 8 commits into
LiYanan2004:mainfrom
guoPhineas:phg/feature/QuoteAlert
Open

Add support for GitHub-style alert#158
guoPhineas wants to merge 8 commits into
LiYanan2004:mainfrom
guoPhineas:phg/feature/QuoteAlert

Conversation

@guoPhineas

Copy link
Copy Markdown
Contributor

@guoPhineas
guoPhineas force-pushed the phg/feature/QuoteAlert branch from 927b149 to b208496 Compare July 27, 2026 02:43
@guoPhineas

guoPhineas commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author
2026-07-27.10.45.37.mov

Hello,

This PR is ready for review.

I added .markdownQuoteAlertEnabled() to enable this style:

image

Thanks.🤝

@guoPhineas
guoPhineas marked this pull request as ready for review July 27, 2026 03:11
@guoPhineas guoPhineas changed the title [WIP] Add support for GitHub-style alert Add support for GitHub-style alert Jul 27, 2026
@ajram23

ajram23 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Love it. Hope this gets added!

@LiYanan2004

Copy link
Copy Markdown
Owner

Sorry for the delay. Reviewing now!

@LiYanan2004
LiYanan2004 self-requested a review August 12, 2026 12:40
@LiYanan2004

Copy link
Copy Markdown
Owner

@guoPhineas Two issues:

  • MarkdownText does not support this new view modifier (I fixed that)
  • There are some edge cases for GitHub-style alert parsing (added some test cases for you) Please fix and make sure they are all passed)


@Suite("Markdown Quote Alert")
struct MarkdownQuoteAlertTests {
@Test(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This test fails

#expect(renderedBody.contains(fixture.expectedFirstBodyParagraph))
}

@Test(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this test fails

@guoPhineas

guoPhineas commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

@LiYanan2004
Never mind for delay. Thanks for review.

I just fixed the issues you raised. But the test isn't also passed. I speculate that there may be code logic issues with the current testing:

The .multipleParagraphs test appears to have an issue in its body-extraction logic.

For this fixture, Swift Markdown produces the following AST:

  • First Paragraph: [!NOTE] followed by First paragraph.
  • Second Paragraph: Second paragraph.

However, when there is more than one child, the test uses:

bodyChildren = Array(children.dropFirst())

This discards the first paragraph, including First paragraph., and then asserts that the rendered body contains First paragraph.. Those two operations conflict.

The renderer should strip the alert marker/title line from the first paragraph, preserve the remaining inline content, and then append the remaining blockquote children. The implementation now follows that behavior, but the test’s extraction logic would need the same adjustment.

So, I fixed the issue in commit cf6e19a, how about this? It was passed on my Mac.

@LiYanan2004

Copy link
Copy Markdown
Owner

@guoPhineas Here are some edge cases that need to be fixed.

image

@guoPhineas

Copy link
Copy Markdown
Contributor Author

@LiYanan2004

Thank you for your patient review and corrections.

I have just fixed these issues, and all tests have passed.

To test as many edge cases as possible, I used the Markdown text below for testing, and it displayed correctly.

2026-09-02.22.46.22.mov
    # GitHub Alert Test Cases

    ## Valid Alerts

    > [!NOTE]
    > This is a standard note alert.

    > [!TIP]
    > This is a standard tip alert.

    > [!IMPORTANT]
    > This is a standard important alert.

    > [!WARNING]
    > This is a standard warning alert.

    > [!CAUTION]
    > This is a standard caution alert.

    ## Case-Insensitive Markers

    > [!note]
    > This lowercase marker should render as a note.

    > [!Tip]
    > This mixed-case marker should render as a tip.

    > [!important]
    > This lowercase marker should render as important.

    > [!Warning]
    > This mixed-case marker should render as a warning.

    > [!Caution]
    > This mixed-case marker should render as a caution.

    ## Body Layouts

    > [!NOTE]
    > The body starts immediately after the marker.
    > This line belongs to the same paragraph.

    > [!TIP]
    >
    > The body starts after a blank quoted line.

    > [!IMPORTANT]
    > First paragraph.
    >
    > Second paragraph.
    >
    > Third paragraph.

    > [!CAUTION]
    > A body containing **bold text**, *italic text*, `inline code`,
    > [a link](https://github.com), and ~~strikethrough text~~.

    ## Nested Block Content

    > [!NOTE]
    > - First list item
    > - Second list item
    >   - Nested list item

    > [!TIP]
    > 1. First ordered item
    > 2. Second ordered item

    > [!IMPORTANT]
    > > A nested blockquote.
    > >
    > > Another nested blockquote paragraph.

    > [!WARNING]
    > ```swift
    > let warning = "Code block inside an alert"
    > print(warning)
    > ```

    > [!CAUTION]
    > | Column A | Column B |
    > |----------|----------|
    > | Value A  | Value B  |

    ## Marker-Only Alerts

    > [!NOTE]

    > [!TIP]

    > [!IMPORTANT]

    > [!WARNING]

    > [!CAUTION]

    ## Surrounding Whitespace

    >    [!NOTE]   
    > The marker has surrounding whitespace.

    > [!WARNING]   
    > The marker has trailing spaces before the line break.

Thank you.

@guoPhineas

Copy link
Copy Markdown
Contributor Author

Additionally, regarding the following cases, I have looked into them and it seems that they should not be supported. If I am mistaken, please feel free to correct me.

> `[!NOTE]` is the token used to create a GitHub alert.
> Place it on a dedicated line.


> **[!WARNING]** is an example marker.
> This paragraph documents the syntax.

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