Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .devcontainer/opencode-seed/commands/to-markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ Convert source content into Markdown using MarkItDown.

## Usage

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

## Execution

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

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

3. If output path is provided, report the saved path.
3. If output path is provided, report the saved path(s).
4. If output path is omitted, return the generated Markdown in the response.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ When users ask to read, summarize, or analyze non-Markdown sources (PDF, DOCX, P

Guidelines:
- Prefer `/to-markdown <input> <output.md>` for large inputs.
- If `<input>` is a directory, never use `Read File` on that directory path; run `/to-markdown <input-dir> <output-dir>` instead.
- For small inputs, `/to-markdown <input>` and return inline Markdown is acceptable.
- After conversion, continue analysis using the Markdown output only.
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Use this skill when you need to transform non-Markdown sources (PDF, Office docs

- If output is large, prefer writing to a file and then summarizing key sections.
- Preserve the generated Markdown as an artifact when reproducibility is needed.
- When the input is a directory, pass an output directory and convert files in bulk instead of reading the directory as a file.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,49 @@ INPUT="$1"
OUTPUT="${2:-}"

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

if [ -n "$OUTPUT" ]; then
is_supported_file() {
local path="$1"
case "${path,,}" in
*.pdf|*.doc|*.docx|*.ppt|*.pptx|*.xls|*.xlsx|*.html|*.htm|*.txt|*.csv|*.json|*.xml)
return 0
;;
*)
return 1
;;
esac
}

if [ -d "$INPUT" ]; then
if [ -z "$OUTPUT" ]; then
echo "Input is a directory. Provide an output directory as the second argument." >&2
exit 3
fi

mkdir -p "$OUTPUT"
converted=0

while IFS= read -r -d '' source_file; do
if ! is_supported_file "$source_file"; then
continue
fi

rel_path="${source_file#$INPUT/}"
target_path="$OUTPUT/${rel_path%.*}.md"
mkdir -p "$(dirname "$target_path")"
markitdown "$source_file" > "$target_path"
converted=$((converted + 1))
echo "Saved Markdown: $target_path"
done < <(find "$INPUT" -type f -print0 | sort -z)

if [ "$converted" -eq 0 ]; then
echo "No supported files found in: $INPUT" >&2
exit 4
fi
elif [ -n "$OUTPUT" ]; then
markitdown "$INPUT" > "$OUTPUT"
echo "Saved Markdown: $OUTPUT"
else
Expand Down
Loading