Skip to content

Commit 41dc643

Browse files
authored
Merge pull request #11 from fjmrytfjsn/fix/to-markdown-directory-input
Handle directory inputs in to-markdown workflow
2 parents 3399fb9 + 8667429 commit 41dc643

4 files changed

Lines changed: 48 additions & 5 deletions

File tree

.devcontainer/opencode-seed/commands/to-markdown.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ Convert source content into Markdown using MarkItDown.
99

1010
## Usage
1111

12-
`/to-markdown <input-path-or-url> [output.md]`
12+
`/to-markdown <input-path-or-url> [output]`
1313

1414
## Execution
1515

1616
1. Parse `$ARGUMENTS` as:
1717
- first token: input path or URL
18-
- optional second token: output file path
18+
- optional second token: output path
19+
2. If input is a directory:
20+
- do not call `Read File` on the directory path
21+
- require output to be a directory path and convert supported files recursively
1922
2. Run:
2023

2124
```bash
2225
bash /home/vscode/.opencode/skills/markitdown-converter/scripts/convert.sh <input> [output]
2326
```
2427

25-
3. If output path is provided, report the saved path.
28+
3. If output path is provided, report the saved path(s).
2629
4. If output path is omitted, return the generated Markdown in the response.

.devcontainer/opencode-seed/instructions/markitdown-converter.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ When users ask to read, summarize, or analyze non-Markdown sources (PDF, DOCX, P
22

33
Guidelines:
44
- Prefer `/to-markdown <input> <output.md>` for large inputs.
5+
- If `<input>` is a directory, never use `Read File` on that directory path; run `/to-markdown <input-dir> <output-dir>` instead.
56
- For small inputs, `/to-markdown <input>` and return inline Markdown is acceptable.
67
- After conversion, continue analysis using the Markdown output only.

.devcontainer/opencode-seed/skills/markitdown-converter/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ Use this skill when you need to transform non-Markdown sources (PDF, Office docs
2525

2626
- If output is large, prefer writing to a file and then summarizing key sections.
2727
- Preserve the generated Markdown as an artifact when reproducibility is needed.
28+
- When the input is a directory, pass an output directory and convert files in bulk instead of reading the directory as a file.

.devcontainer/opencode-seed/skills/markitdown-converter/scripts/convert.sh

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,49 @@ INPUT="$1"
1010
OUTPUT="${2:-}"
1111

1212
if ! command -v markitdown >/dev/null 2>&1; then
13-
echo "markitdown is not installed. Install with: uv tool install markitdown" >&2
13+
echo "markitdown is not installed. Install with: uv tool install 'markitdown[all]'" >&2
1414
exit 2
1515
fi
1616

17-
if [ -n "$OUTPUT" ]; then
17+
is_supported_file() {
18+
local path="$1"
19+
case "${path,,}" in
20+
*.pdf|*.doc|*.docx|*.ppt|*.pptx|*.xls|*.xlsx|*.html|*.htm|*.txt|*.csv|*.json|*.xml)
21+
return 0
22+
;;
23+
*)
24+
return 1
25+
;;
26+
esac
27+
}
28+
29+
if [ -d "$INPUT" ]; then
30+
if [ -z "$OUTPUT" ]; then
31+
echo "Input is a directory. Provide an output directory as the second argument." >&2
32+
exit 3
33+
fi
34+
35+
mkdir -p "$OUTPUT"
36+
converted=0
37+
38+
while IFS= read -r -d '' source_file; do
39+
if ! is_supported_file "$source_file"; then
40+
continue
41+
fi
42+
43+
rel_path="${source_file#$INPUT/}"
44+
target_path="$OUTPUT/${rel_path%.*}.md"
45+
mkdir -p "$(dirname "$target_path")"
46+
markitdown "$source_file" > "$target_path"
47+
converted=$((converted + 1))
48+
echo "Saved Markdown: $target_path"
49+
done < <(find "$INPUT" -type f -print0 | sort -z)
50+
51+
if [ "$converted" -eq 0 ]; then
52+
echo "No supported files found in: $INPUT" >&2
53+
exit 4
54+
fi
55+
elif [ -n "$OUTPUT" ]; then
1856
markitdown "$INPUT" > "$OUTPUT"
1957
echo "Saved Markdown: $OUTPUT"
2058
else

0 commit comments

Comments
 (0)