Agent skill
pandoc-10-batch-conversion-scripts
Sub-skill of pandoc: 10. Batch Conversion Scripts.
Install this agent skill to your Project
npx add-skill https://github.com/vamseeachanta/workspace-hub/tree/main/.claude/skills/_archive/development/documentation/pandoc/10-batch-conversion-scripts
SKILL.md
10. Batch Conversion Scripts
10. Batch Conversion Scripts
#!/bin/bash
# scripts/batch-convert.sh
# Convert all Markdown files to PDF
set -euo pipefail
# Configuration
INPUT_DIR="${1:-./docs}"
OUTPUT_DIR="${2:-./output}"
TEMPLATE="${3:-}"
# Create output directory
mkdir -p "$OUTPUT_DIR"
# Find and convert all markdown files
find "$INPUT_DIR" -name "*.md" -type f | while read -r file; do
# Get relative path and create output path
relative="${file#$INPUT_DIR/}"
output_file="$OUTPUT_DIR/${relative%.md}.pdf"
output_dir=$(dirname "$output_file")
# Create output subdirectory
mkdir -p "$output_dir"
echo "Converting: $file -> $output_file"
# Build pandoc command
cmd=(pandoc "$file" -o "$output_file"
--pdf-engine=xelatex
--toc
--number-sections
--highlight-style=tango)
# Add template if specified
if [[ -n "$TEMPLATE" ]]; then
cmd+=(--template="$TEMPLATE")
fi
# Execute conversion
"${cmd[@]}"
done
echo "Batch conversion complete!"
echo "Output: $OUTPUT_DIR"
#!/bin/bash
# scripts/convert-to-all-formats.sh
# Convert a document to multiple formats
set -euo pipefail
INPUT_FILE="${1:?Usage: $0 <input.md>}"
BASE_NAME="${INPUT_FILE%.md}"
echo "Converting $INPUT_FILE to multiple formats..."
# PDF
echo " -> PDF"
pandoc "$INPUT_FILE" -o "${BASE_NAME}.pdf" \
--pdf-engine=xelatex \
--toc \
--number-sections
# DOCX
echo " -> DOCX"
pandoc "$INPUT_FILE" -o "${BASE_NAME}.docx" \
--toc
# HTML
echo " -> HTML"
pandoc "$INPUT_FILE" -o "${BASE_NAME}.html" \
--standalone \
--toc \
--embed-resources
# LaTeX
echo " -> LaTeX"
pandoc "$INPUT_FILE" -o "${BASE_NAME}.tex"
# EPUB
echo " -> EPUB"
pandoc "$INPUT_FILE" -o "${BASE_NAME}.epub" \
--toc
echo "Done! Created:"
ls -la "${BASE_NAME}".*
#!/usr/bin/env python3
"""
scripts/smart_convert.py
Smart document converter with configuration file support.
"""
import subprocess
import sys
from pathlib import Path
import yaml
def load_config(config_path: Path) -> dict:
"""Load conversion configuration from YAML."""
with open(config_path) as f:
return yaml.safe_load(f)
def convert_document(
input_file: Path,
output_file: Path,
config: dict
) -> bool:
"""Convert a single document using pandoc."""
cmd = ['pandoc', str(input_file), '-o', str(output_file)]
# Add common options
if config.get('toc'):
cmd.append('--toc')
if toc_depth := config.get('toc_depth'):
cmd.extend(['--toc-depth', str(toc_depth)])
if config.get('number_sections'):
cmd.append('--number-sections')
if template := config.get('template'):
cmd.extend(['--template', template])
if pdf_engine := config.get('pdf_engine'):
cmd.extend(['--pdf-engine', pdf_engine])
if highlight := config.get('highlight_style'):
cmd.extend(['--highlight-style', highlight])
if bibliography := config.get('bibliography'):
cmd.append('--citeproc')
cmd.extend(['--bibliography', bibliography])
if csl := config.get('csl'):
cmd.extend(['--csl', csl])
# Add variables
for key, value in config.get('variables', {}).items():
cmd.extend(['-V', f'{key}={value}'])
# Add filters
for filter_name in config.get('filters', []):
if filter_name.endswith('.lua'):
cmd.extend(['--lua-filter', filter_name])
else:
cmd.extend(['--filter', filter_name])
print(f"Running: {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
print(f"Error: {result.stderr}", file=sys.stderr)
return False
return True
def main():
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} <input.md> <output.pdf> [config.yaml]")
sys.exit(1)
input_file = Path(sys.argv[1])
output_file = Path(sys.argv[2])
config_file = Path(sys.argv[3]) if len(sys.argv) > 3 else None
config = {}
if config_file and config_file.exists():
config = load_config(config_file)
success = convert_document(input_file, output_file, config)
sys.exit(0 if success else 1)
if __name__ == '__main__':
main()
*Content truncated — see parent skill for full reference.*
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
gsd-complete-milestone
Archive completed milestone and prepare for next version
gsd-reapply-patches
Reapply local modifications after a GSD update
gsd-verify-work
Validate built features through conversational UAT
gsd-thread
Manage persistent context threads for cross-session work
clinical-trial-protocol
Generate clinical trial protocols for medical devices or drugs through a modular, waypoint-based architecture with research-only and full protocol modes.
single-cell-rna-qc
Performs quality control on single-cell RNA-seq data (.h5ad or .h5 files) using scverse best practices with MAD-based filtering and comprehensive visualizations.
Didn't find tool you were looking for?