Skip to content

Commit 32afd4f

Browse files
Copilotneongreen
andcommitted
Add GitHub Actions workflow and integration documentation for treefmt and dprint
Co-authored-by: neongreen <1523306+neongreen@users.noreply.github.com>
1 parent 75266f2 commit 32afd4f

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: markdown-format
2+
3+
on:
4+
push:
5+
paths:
6+
- 'markdown-format/**'
7+
pull_request:
8+
paths:
9+
- 'markdown-format/**'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: '1.24.7'
23+
24+
- name: Run tests
25+
working-directory: markdown-format
26+
run: go test -v

markdown-format/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,92 @@ It has multiple sentences.
5959
Let's format it!
6060
```
6161

62+
## Integration with Formatting Tools
63+
64+
### treefmt
65+
66+
[treefmt](https://github.com/numtide/treefmt) is a universal code formatter that runs multiple formatters with one command.
67+
68+
To integrate markdown-format with treefmt, you'll need to create a wrapper script since markdown-format outputs to stdout rather than formatting files in place.
69+
70+
1. Create a wrapper script (e.g., `markdown-format-inplace.sh`):
71+
72+
```bash
73+
#!/bin/bash
74+
# Wrapper script to make markdown-format work in-place for treefmt
75+
76+
MARKDOWN_FORMAT="./markdown-format/markdown-format"
77+
78+
for file in "$@"; do
79+
if [ -f "$file" ]; then
80+
temp_file=$(mktemp)
81+
"$MARKDOWN_FORMAT" "$file" > "$temp_file"
82+
mv "$temp_file" "$file"
83+
fi
84+
done
85+
```
86+
87+
2. Make the wrapper script executable:
88+
89+
```bash
90+
chmod +x markdown-format-inplace.sh
91+
```
92+
93+
3. Add to your `treefmt.toml`:
94+
95+
```toml
96+
[formatter.markdown-format]
97+
command = "./markdown-format-inplace.sh"
98+
options = []
99+
includes = ["*.md"]
100+
```
101+
102+
4. Run treefmt:
103+
104+
```bash
105+
treefmt
106+
```
107+
108+
### dprint
109+
110+
[dprint](https://dprint.dev/) is a pluggable and configurable code formatter.
111+
112+
Since markdown-format uses a custom sentence-per-line format, you'll need to use dprint's process plugin or create a custom wrapper. Here's how to integrate using a process-based approach:
113+
114+
1. Create a wrapper script that handles dprint's stdin/stdout protocol (e.g., `dprint-markdown-format.sh`):
115+
116+
```bash
117+
#!/bin/bash
118+
# Wrapper script for dprint integration
119+
120+
# Read from stdin, format, and output to stdout
121+
/path/to/markdown-format -
122+
```
123+
124+
2. Add to your `dprint.json`:
125+
126+
```json
127+
{
128+
"plugins": [
129+
"https://plugins.dprint.dev/exec-0.5.0.json@checksum"
130+
],
131+
"exec": {
132+
"commands": [{
133+
"command": "./dprint-markdown-format.sh",
134+
"exts": ["md"]
135+
}]
136+
}
137+
}
138+
```
139+
140+
Note: The exact configuration may vary depending on your dprint version. Refer to the [dprint documentation](https://dprint.dev/plugins/) for the latest plugin configuration format.
141+
142+
3. Run dprint:
143+
144+
```bash
145+
dprint fmt
146+
```
147+
62148
## License
63149

64150
MIT License - See LICENSE file in the repository root.

0 commit comments

Comments
 (0)