markdown.star¶
Add or replace sections and badges in Markdown files such as README.md.
| Function | What it does |
|---|---|
has_section |
Reports whether a Markdown file has a heading with this text. |
set_section |
Makes the section under a heading contain the given text. |
ensure_badge |
Adds a badge to a Markdown file, next to the badges it already shows. |
has_section¶
Reports whether a Markdown file has a heading with this text.
Headings of any level match, case is ignored, and headings inside code fences don't count.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
path |
The Markdown file. |
heading |
The heading text, without #. |
Returns: True when the section exists.
Example
set_section¶
Makes the section under a heading contain the given text.
An existing section, found by heading text at any level, has its content replaced up to the next heading of the same or a higher level. A missing section is appended at the end of the file. Headings inside code fences are ignored.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
path |
The Markdown file; created if needed. |
heading |
The heading text, without #. |
body |
The section's content. |
level |
The heading level for a new section. |
replace |
When False, an existing section is left as it is. |
Returns: True when the file changed.
Example
Used in: readme-section
ensure_badge¶
Adds a badge to a Markdown file, next to the badges it already shows.
The badge joins the first run of badges before the first ## section,
wherever it is: under the title, or under a logo. Without one, it goes
under a # title, or at the top. A file that already contains the
badge's text is left alone.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
path |
The Markdown file. |
badge |
One line of Markdown, such as [](...). |
Returns: True when the file changed; False when the badge was there or the file does not exist.
Example
ensure_badge(repo, "README.md", "[](https://github.com/acme/api/actions)")
# returns True
Used in: readme-section