Skip to content

Preserve Markdown callout blockquote lines in docbuilder style docstring formatting#756

Open
qgallouedec wants to merge 4 commits intohuggingface:mainfrom
qgallouedec:allow-cite
Open

Preserve Markdown callout blockquote lines in docbuilder style docstring formatting#756
qgallouedec wants to merge 4 commits intohuggingface:mainfrom
qgallouedec:allow-cite

Conversation

@qgallouedec
Copy link
Copy Markdown
Member

@qgallouedec qgallouedec commented Feb 25, 2026

from doc_builder.style_doc import style_docstring


test_docstring = """Function description

Params:
    x (`int`): This is x.

> [!NOTE]
> This is a note.
> This is still part of the note.
"""

print(style_docstring(test_docstring, 119)[0])

Before this PR:

$ python demo.py 
Function description

Params:
    x (`int`): This is x.

> [!NOTE]
> This is a note. > This is still part of the note.

After this PR:

$ python demo.py 
Function description

Params:
    x (`int`): This is x.

> [!NOTE]
> This is a note.
> This is still part of the note.

Copy link
Copy Markdown
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

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

Thanks! Much better.

Just a question: are we sure that the regex does not match unintended text?

@qgallouedec
Copy link
Copy Markdown
Member Author

I'm not an expert in regex, but let me look into it.

@qgallouedec
Copy link
Copy Markdown
Member Author

The only case I can think of is

text = """Shell snippet written outside fenced code:

> This is just a normal quote line that is intentionally very very very very very very very very very very very very long and would usually be wrapped.
"""
print(style_docstring(text, 119)[0])

where we would like to get something like

Shell snippet written outside fenced code:

> This is just a normal quote line that is intentionally very very very very very
> very very very very very very very long and would usually be wrapped.

but we get

Shell snippet written outside fenced code:

> This is just a normal quote line that is intentionally very very very very very very very very very very very very long and would usually be wrapped.

which is not a big deal I think, cause before this PR:

Shell snippet written outside fenced code:

> This is just a normal quote line that is intentionally very very very very
very very very very very very very very long and would usually be wrapped.

@qgallouedec
Copy link
Copy Markdown
Member Author

Addressed here: #757

Copy link
Copy Markdown
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

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

Looks good 👍

# Re pattern that matches blockquote tip markers: > [!NOTE], > [!TIP], > [!IMPORTANT], > [!WARNING], > [!CAUTION]
_re_blockquote_tip = re.compile(r"^\s*> \[!(?:NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$")
# Re pattern that catches markdown blockquote lines.
_re_blockquote_tip = re.compile(r"^\s*>\s?.*$")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
_re_blockquote_tip = re.compile(r"^\s*>\s?.*$")
_re_blockquote = re.compile(r"^\s*>\s?.*$")

(nit) (not catching only tips anymore)

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