Skip to content

Commit e2938e1

Browse files
authored
Add Markdown linting to CI (hellt#19)
* Surround md headers with spacing to resolve MD022 * Resolve several markdown warnings in README.md * line length MD013 * lists surrounded by blank lines MD032 * bare URL MD034 * Resolve curl long line MD013 in README.md * Add step to Codespace method in README.md * Resolve markdown line length MD013 * Add newline to output to appease markdownlint MD047 * Resolve more long lines in README.md * Resolve linting issues in CONTRIBUTING.md * headers surrounded by blank lines MD022 * long lines MD013 * changing long lines manifested MD032 * changed unordered to ordered list in Dev section MD007 * Remove inline HTML/image to lint README.md * long line warning * inline HTML warning * Change "a first" to "the first" in README.md * Resolve bare URLs - MD034 * Add Node.js packages directory to .gitignore * Fix string format to use double quotes * Add markdownlint-cli2 config * Add npm (Node.js) packaging for markdownlint-cli2 * Add markdown linting Action to cicd.yml * Update cicd.yml - test depends on mdlint * Fix mdlint path for test files in cicd.yml * Update goal comment in cicd.yml * Revert "Add Node.js packages directory to .gitignore" This reverts commit 84fc5b0. * Revert "Add npm (Node.js) packaging for markdownlint-cli2" This reverts commit 722977c. * Move file globbing to .markdownlint-cli2.yaml
1 parent 2da12ad commit e2938e1

File tree

18 files changed

+313
-158
lines changed

18 files changed

+313
-158
lines changed

.github/workflows/cicd.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ on:
1111
types: ["created"]
1212

1313
# GOAL:
14-
# - run ruff job on pushes to main branch or v* tag
15-
# - run ruff job on PRs against main branch
16-
# - run ruff job on Release creation
17-
# - run test job on pushes to main branch or v* tag
18-
# - run test job on PRs against main branch
19-
# - run test job on Release creation
20-
# - run docker job on the above events when the triggered actor is the repo owner
21-
# - run docker job on Release creation (ex: maybe a maintainer that isn't repo owner)
14+
# on pushes to main branch or v* tag
15+
# - ruff, mdlint, test
16+
# on PRs against main branch
17+
# - ruff, mdlint, test
18+
# on Release creation
19+
# - ruff, mdlint, test
20+
# on the above events when the triggered actor is the repo owner
21+
# - docker
22+
# on Release creation (ex: maybe a maintainer that isn't repo owner)
23+
# - docker
2224

2325
jobs:
2426
ruff:
@@ -39,10 +41,21 @@ jobs:
3941
args: "format --check --diff"
4042
changed-files: "true"
4143

44+
mdlint:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Check out repository code
48+
uses: actions/checkout@v4
49+
50+
- name: Run markdownlint-cli2
51+
uses: DavidAnson/markdownlint-cli2-action@v17
52+
# file globbing configured in .markdownlint-cli2.yaml
53+
4254
test:
4355
runs-on: ubuntu-latest
4456
needs:
4557
- "ruff"
58+
- "mdlint"
4659
strategy:
4760
matrix:
4861
python-version: ["3.9", "3.10", "3.11", "3.12"]

.markdownlint-cli2.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
default: true
3+
4+
config:
5+
6+
globs:
7+
- '*.{md,markdown}'
8+
- 'tests/*/*.{md,markdown}'
9+
...

CONTRIBUTING.md

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
A couple of quick items:
66

7-
1. To avoid duplicate issues and PRs, [please search open issue and pull requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/filtering-and-searching-issues-and-pull-requests) before submitting a new one.
8-
1. The general expectation is to [submit a GitHub issue](https://help.github.com/en/github/managing-your-work-on-github/creating-an-issue) to receive feedback before submitting a pull request (PR) with changes.
7+
1. To avoid duplicate issues and PRs, [please search open issue and pull requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/filtering-and-searching-issues-and-pull-requests)
8+
before submitting a new one.
9+
10+
1. The general expectation is to [submit a GitHub issue](https://help.github.com/en/github/managing-your-work-on-github/creating-an-issue)
11+
to receive feedback before submitting a pull request (PR) with changes.
12+
913
* _This will help ensure ideas align with the project scope._
10-
1. Unit tests should accompany [Pull Requests (PRs)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) **whenever possible**. :point_left:
11-
* This could mean adding additional tests to an existing unit test file or creating a new one.
14+
15+
1. Unit tests should accompany [Pull Requests (PRs)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)
16+
**whenever possible**. :point_left:
17+
18+
* This could mean adding additional tests to an existing unit test file or
19+
creating a new one.
1220

1321
## Ways to Contribute
1422

@@ -21,23 +29,38 @@ A couple of quick items:
2129

2230
## Testing Framework
2331

24-
For minimal dependencies, the "batteries included" [Python `unittest` framework](https://docs.python.org/3/library/unittest.html) is utilized. (Other testing frameworks could be considered should additional testing features be needed.)
32+
For minimal dependencies, the "batteries included" [Python `unittest` framework](https://docs.python.org/3/library/unittest.html)
33+
is utilized. (Other testing frameworks could be considered should additional
34+
testing features be needed.)
2535

2636
## Development Process
37+
2738
>
2839
> This section consists of suggestions.
2940
30-
It is recommended to verify tests are successful before making any code changes. From there make your changes and run the unit tests to validate there is not code regression.
41+
It is recommended to verify tests are successful before making any code changes.
42+
From there make your changes and run the unit tests to validate there is not
43+
code regression.
44+
45+
1. [Create a fork of this project](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo)
46+
47+
* If you have an existing fork of this project be sure [to synchronize it](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork)!
48+
49+
1. From the `main` branch of your fork, [create a feature branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository)
3150

32-
* [Create a fork of this project](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo)
33-
* If you have an existing fork of this project be sure [to synchronize it](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork)!
34-
* From the `main` branch of your fork, [create a feature branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository)
35-
* Validate [test cases run successfully](#running-unit-tests) before any changes are made
36-
* Make modifications
37-
* Re-test with the existing unit tests against the modified codebase
38-
* Add any additional unit tests to improve testing coverage
39-
* Re-run the unit tests to confirm they run successfully
40-
* When you are satisfied with the changes and it is ready for review, [submit a Pull Request (PR)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
51+
1. Validate [test cases run successfully](#running-unit-tests) before any
52+
changes are made
53+
54+
1. Make modifications
55+
56+
1. Re-test with the existing unit tests against the modified codebase
57+
58+
1. Add any additional unit tests to improve testing coverage
59+
60+
1. Re-run the unit tests to confirm they run successfully
61+
62+
1. When you are satisfied with the changes and it is ready for review,
63+
[submit a Pull Request (PR)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
4164

4265
## Running Unit Tests
4366

@@ -47,12 +70,16 @@ Choose one of the below testing commands methods that suits your needs.
4770
> The commands below are to be run from the top level of the project.
4871
4972
1. Discover and run unit tests
73+
5074
* `python -m unittest discover`
5175

5276
1. Verbose version of unit test discovery
77+
5378
* `python -m unittest discover -v`
5479

5580
1. Discover unit tests in specific directory (in this case, `tests`) with verbosity
81+
5682
* `python -m unittest discover -s tests -v`
5783

58-
:bulb: For additional `unittest` command line options, refer to the [official Python unittest documentation](https://docs.python.org/3/library/unittest.html#command-line-interface).
84+
:bulb: For additional `unittest` command line options, refer to the
85+
[official Python unittest documentation](https://docs.python.org/3/library/unittest.html#command-line-interface).

README.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A script to sort footnotes in a markdown file.
44

5-
Reads a Markdown file passed as a first argument and sorts footnotes.
5+
Reads a Markdown file passed as the first argument and sorts footnotes.
66
The reference links will be numbered in
77
the order they appear in the text and placed at the bottom
88
of the file.
@@ -11,11 +11,7 @@ Based on <https://github.com/derdennis/sort-markdown-footnotes>
1111

1212
Inspired by <http://www.leancrew.com/all-this/2012/09/tidying-markdown-reference-links/>
1313

14-
15-
16-
https://github.com/user-attachments/assets/2ccb1782-1d85-499c-ba09-3be94c34a591
17-
18-
14+
[Example video](https://github.com/user-attachments/assets/2ccb1782-1d85-499c-ba09-3be94c34a591)
1915

2016
## How to use?
2117

@@ -28,37 +24,55 @@ https://github.com/user-attachments/assets/2ccb1782-1d85-499c-ba09-3be94c34a591
2824
1. Or download the script and put it in your `$PATH`:
2925

3026
```bash
31-
curl -sL https://raw.githubusercontent.com/hellt/markdown-footnote-sorter/main/fnsort.py \
27+
curl -sL \
28+
https://raw.githubusercontent.com/hellt/markdown-footnote-sorter/main/fnsort.py\
3229
> ~/.local/bin/fnsort.py
3330
3431
fnsort.py path/to/doc.md
3532
```
3633

37-
1. Or run the container in a [Codespace](https://docs.github.com/en/codespaces/overview):sparkles: via the GitHub UI:
34+
1. Or from the GitHub UI, run the container in a :sparkles:[Codespace](https://docs.github.com/en/codespaces/overview):
35+
3836
* From this project's main page, click **Code**, then **Codespace**.
39-
* Choose **Create codespace on <branch_name>** to [create a codespace](https://docs.github.com/en/codespaces/developing-in-a-codespace/creating-a-codespace-for-a-repository#creating-a-codespace-for-a-repository) with the default resources (currently 2 CPU, 8 GB RAM, 32 GB Storage).
40-
<img alt="create codespace button" title="create codespace button" src="https://docs.github.com/assets/cb-49943/mw-1440/images/help/codespaces/who-will-pay.webp" width="275px"/>
37+
* Choose **Create codespace on &lt;branch_name&gt;**
38+
39+
This [creates a codespace](https://docs.github.com/en/codespaces/developing-in-a-codespace/creating-a-codespace-for-a-repository#creating-a-codespace-for-a-repository)
40+
with the default resources (currently 2 CPU, 8 GB RAM, 32 GB Storage).
41+
42+
* :rocket: Run fnsort on your markdown file:
4143
4244
```bash
4345
/app/fnsort.py path/to/doc.md
4446
```
4547
4648
> [!IMPORTANT]
47-
> Keep in mind there are [monthly limits measured in core hours](https://docs.github.com/en/billing/managing-billing-for-your-products/managing-billing-for-github-codespaces/about-billing-for-github-codespaces#monthly-included-storage-and-core-hours-for-personal-accounts) and to [stop your codespace](https://docs.github.com/en/codespaces/developing-in-a-codespace/stopping-and-starting-a-codespace):stop_sign: when you're not using it to conserve your monthly core hours allowance.
49+
> Keep in mind there are
50+
> [monthly limits measured in core hours](https://docs.github.com/en/billing/managing-billing-for-your-products/managing-billing-for-github-codespaces/about-billing-for-github-codespaces#monthly-included-storage-and-core-hours-for-personal-accounts)
51+
and to
52+
[stop your codespace](https://docs.github.com/en/codespaces/developing-in-a-codespace/stopping-and-starting-a-codespace)
53+
:stop_sign: when you're not using it to conserve your monthly core hours
54+
allowance.
4855

4956
## Command Line Arguments
57+
5058
### --adjacent
51-
Adjacent inline references that are not separated by other characters become problematic (by default).
52-
This option adds spacing between those inline references so they are properly identified during sorting.
59+
60+
Adjacent inline references that are not separated by other characters become
61+
problematic (by default).
62+
This option adds spacing between those inline references so they are properly
63+
identified during sorting.
5364

5465
`fnsort.py path/to/doc.md --adjacent`
5566

5667
### --keepnames
68+
5769
Retain or keep inline reference and footnote names.
5870
This prevents the default behavior of replacing the names with numbers.
5971
Footnotes at the end of the markdown are **still sorted**.
6072

6173
`fnsort.py path/to/doc.md --keepnames`
6274

6375
## Contributing
64-
For information about contributing to this project, see the [contributing guidelines](CONTRIBUTING.md).
76+
77+
For information about contributing to this project, see the
78+
[contributing guidelines](CONTRIBUTING.md).

fnsort.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ def sort_footnotes(text, args):
139139
# Rewrite the footnote-links with the new footnote-reference numbers.
140140
text = link.sub(lambda m: replace_reference(m, order), text)
141141

142-
return text
142+
# Append newline to EOL to appease markdownlint
143+
return f"{text}\n"
143144

144145

145146
def main():

tests/adjacent/adjacent.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
11
# Wrens
22

33
## Overview
4+
45
Wrens [^4][^7] are a family of brown birds of which there are 88 species.
56

67
## Size
7-
Wrens are medium-small to very small birds. The Eurasian wren is among the smallest birds in its range, while the smaller species from the Americas are among the smallest passerines in that part of the world.[^1]
8+
9+
Wrens are medium-small to very small birds. The Eurasian wren is among the
10+
smallest birds in its range, while the smaller species from the Americas are
11+
among the smallest passerines in that part of the world.[^1]
812

913
## Coloration
10-
The dominating colors of their plumage are generally drab, composed of gray, brown, black, and white, and most species show some barring, especially on the tail or wings[^1].
14+
15+
The dominating colors of their plumage are generally drab, composed of gray,
16+
brown, black, and white, and most species show some barring, especially on the
17+
tail or wings[^1].
1118

1219
## Diet
13-
Wrens are primarily insectivorous, eating insects, spiders and other small invertebrates, but many species also eat vegetable matter and some eat small frogs and lizards[^4][^7].
20+
21+
Wrens are primarily insectivorous, eating insects, spiders and other small
22+
invertebrates, but many species also eat vegetable matter and some eat small
23+
frogs and lizards[^4][^7].
1424

1525
## Species
26+
1627
### Eurasian Wren
17-
![Eurasian wren](https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Ein_neugieriger_Zaunk%C3%B6nig.jpg/240px-Ein_neugieriger_Zaunk%C3%B6nig.jpg)[^3]
1828

19-
The Eurasian wren is the only species of wren found outside the Americas, as restricted to Europe, Asia, and northern Africa.[^2]
29+
![Eurasian wren](https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Ein_neugieriger_Zaunk%C3%B6nig.jpg/240px-Ein_neugieriger_Zaunk%C3%B6nig.jpg)
30+
Credit:[^3]
31+
32+
The Eurasian wren is the only species of wren found outside the Americas, as
33+
restricted to Europe, Asia, and northern Africa.[^2]
2034

21-
The Eurasian wren has been recorded wading into shallow water to catch small fish and tadpoles[^6] .
35+
The Eurasian wren has been recorded wading into shallow water to catch small
36+
fish and tadpoles[^6] .
2237

2338
The most common call of the Eurasian is a sharp repeated "tic-tic-tic"[^5].
2439

25-
[^4]: https://en.wikipedia.org/wiki/Wren
26-
[^7]: https://www.allaboutbirds.org/guide/browse/shape/Wrens
27-
[^1]: https://en.wikipedia.org/wiki/Wren#Description
28-
[^5]: https://en.wikipedia.org/wiki/Eurasian_wren#Vocalizations
29-
[^2]: https://en.wikipedia.org/wiki/Wren#Distribution_and_habitat
30-
[^6]: https://en.wikipedia.org/wiki/Wren#Behavior_and_ecology
31-
[^3]: https://en.wikipedia.org/wiki/File:Ein_neugieriger_Zaunk%C3%B6nig.jpg
40+
[^4]: <https://en.wikipedia.org/wiki/Wren>
41+
[^7]: <https://www.allaboutbirds.org/guide/browse/shape/Wrens>
42+
[^1]: <https://en.wikipedia.org/wiki/Wren#Description>
43+
[^5]: <https://en.wikipedia.org/wiki/Eurasian_wren#Vocalizations>
44+
[^2]: <https://en.wikipedia.org/wiki/Wren#Distribution_and_habitat>
45+
[^6]: <https://en.wikipedia.org/wiki/Wren#Behavior_and_ecology>
46+
[^3]: <https://en.wikipedia.org/wiki/File:Ein_neugieriger_Zaunk%C3%B6nig.jpg>
Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
11
# Wrens
22

33
## Overview
4+
45
Wrens [^1] [^2] are a family of brown birds of which there are 88 species.
56

67
## Size
7-
Wrens are medium-small to very small birds. The Eurasian wren is among the smallest birds in its range, while the smaller species from the Americas are among the smallest passerines in that part of the world. [^3]
8+
9+
Wrens are medium-small to very small birds. The Eurasian wren is among the
10+
smallest birds in its range, while the smaller species from the Americas are
11+
among the smallest passerines in that part of the world. [^3]
812

913
## Coloration
10-
The dominating colors of their plumage are generally drab, composed of gray, brown, black, and white, and most species show some barring, especially on the tail or wings [^3].
14+
15+
The dominating colors of their plumage are generally drab, composed of gray,
16+
brown, black, and white, and most species show some barring, especially on the
17+
tail or wings [^3].
1118

1219
## Diet
13-
Wrens are primarily insectivorous, eating insects, spiders and other small invertebrates, but many species also eat vegetable matter and some eat small frogs and lizards [^1] [^2].
20+
21+
Wrens are primarily insectivorous, eating insects, spiders and other small
22+
invertebrates, but many species also eat vegetable matter and some eat small
23+
frogs and lizards [^1] [^2].
1424

1525
## Species
26+
1627
### Eurasian Wren
17-
![Eurasian wren](https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Ein_neugieriger_Zaunk%C3%B6nig.jpg/240px-Ein_neugieriger_Zaunk%C3%B6nig.jpg) [^4]
1828

19-
The Eurasian wren is the only species of wren found outside the Americas, as restricted to Europe, Asia, and northern Africa. [^5]
29+
![Eurasian wren](https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Ein_neugieriger_Zaunk%C3%B6nig.jpg/240px-Ein_neugieriger_Zaunk%C3%B6nig.jpg)
30+
Credit: [^4]
31+
32+
The Eurasian wren is the only species of wren found outside the Americas, as
33+
restricted to Europe, Asia, and northern Africa. [^5]
2034

21-
The Eurasian wren has been recorded wading into shallow water to catch small fish and tadpoles [^6] .
35+
The Eurasian wren has been recorded wading into shallow water to catch small
36+
fish and tadpoles [^6] .
2237

2338
The most common call of the Eurasian is a sharp repeated "tic-tic-tic" [^7].
2439

25-
[^1]: https://en.wikipedia.org/wiki/Wren
26-
[^2]: https://www.allaboutbirds.org/guide/browse/shape/Wrens
27-
[^3]: https://en.wikipedia.org/wiki/Wren#Description
28-
[^4]: https://en.wikipedia.org/wiki/File:Ein_neugieriger_Zaunk%C3%B6nig.jpg
29-
[^5]: https://en.wikipedia.org/wiki/Wren#Distribution_and_habitat
30-
[^6]: https://en.wikipedia.org/wiki/Wren#Behavior_and_ecology
31-
[^7]: https://en.wikipedia.org/wiki/Eurasian_wren#Vocalizations
40+
[^1]: <https://en.wikipedia.org/wiki/Wren>
41+
[^2]: <https://www.allaboutbirds.org/guide/browse/shape/Wrens>
42+
[^3]: <https://en.wikipedia.org/wiki/Wren#Description>
43+
[^4]: <https://en.wikipedia.org/wiki/File:Ein_neugieriger_Zaunk%C3%B6nig.jpg>
44+
[^5]: <https://en.wikipedia.org/wiki/Wren#Distribution_and_habitat>
45+
[^6]: <https://en.wikipedia.org/wiki/Wren#Behavior_and_ecology>
46+
[^7]: <https://en.wikipedia.org/wiki/Eurasian_wren#Vocalizations>

0 commit comments

Comments
 (0)