This repository was archived by the owner on Apr 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
117 lines (95 loc) · 3.72 KB
/
justfile
File metadata and controls
117 lines (95 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
run:
cd splitter && cargo run
convert_pdf_to_markdown:
#!/usr/bin/env bash
# Check if pdftotext is available
if ! command -v pdftotext &> /dev/null; then
echo "Error: pdftotext is not installed. Please install poppler-utils:"
echo " Ubuntu/Debian: sudo apt-get install poppler-utils"
echo " macOS: brew install poppler"
echo " Arch: sudo pacman -S poppler"
exit 1
fi
# Create output directory if it doesn't exist
mkdir -p out_md
# Check if there are any PDF files
if ! ls out_pdf/*.pdf 1> /dev/null 2>&1; then
echo "No PDF files found in out_pdf/ directory."
echo "Run 'just run' first to generate PDF files."
exit 1
fi
echo "Converting PDF files to markdown..."
converted=0
for pdf in out_pdf/*.pdf; do
if [ -f "$pdf" ]; then
basename=$(basename "$pdf" .pdf)
echo "Processing: $pdf"
# Extract text and add basic markdown formatting
{
echo "# ${basename//_/ }"
echo ""
pdftotext "$pdf" -
} > "out_md/${basename}.md"
if [ $? -eq 0 ]; then
echo "✓ Converted to out_md/${basename}.md"
((converted++))
else
echo "✗ Failed to convert $pdf"
fi
fi
done
echo ""
echo "Conversion complete: $converted files processed"
convert_markdown_to_pdf:
#!/usr/bin/env bash
# Create output directory if it doesn't exist
mkdir -p out_pdf
# Check if there are any markdown files in answers directory
if ! ls answers/*.md 1> /dev/null 2>&1; then
echo "No markdown files found in answers/ directory."
exit 1
fi
echo "Converting markdown files from answers/ to PDF..."
converted=0
for md in answers/*.md; do
if [ -f "$md" ]; then
basename=$(basename "$md" .md)
# Remove the extra .md extension if it exists (for .md.md files)
basename=${basename%.md}
echo "Processing: $md"
success=false
echo Method 2: Try pandoc with different engines
if [ "$success" = false ] && command -v pandoc &> /dev/null; then
if pandoc "$md" -o "out_pdf/${basename}.pdf" --pdf-engine=wkhtmltopdf 2>/dev/null; then
success=true
elif pandoc "$md" -o "out_pdf/${basename}.pdf" --pdf-engine=weasyprint 2>/dev/null; then
success=true
elif pandoc "$md" -o "out_pdf/${basename}.pdf" 2>/dev/null; then
success=true
fi
fi
# Method 3: Generate simple text-based PDF using enscript + ps2pdf
if [ "$success" = false ] && command -v enscript &> /dev/null && command -v ps2pdf &> /dev/null; then
temp_ps="/tmp/${basename}.ps"
if enscript -p "$temp_ps" "$md" 2>/dev/null && ps2pdf "$temp_ps" "out_pdf/${basename}.pdf" 2>/dev/null; then
success=true
fi
rm -f "$temp_ps"
fi
if [ "$success" = true ]; then
echo "✓ Converted to out_pdf/${basename}.pdf"
((converted++))
else
echo "✗ Failed to convert $md - try installing: wkhtmltopdf, pandoc, or enscript+ghostscript"
fi
fi
done
echo ""
echo "Conversion complete: $converted files processed"
if [ $converted -eq 0 ]; then
echo ""
echo "Installation suggestions:"
echo " Ubuntu/Debian: sudo apt-get install wkhtmltopdf"
echo " macOS: brew install wkhtmltopdf"
echo " Arch: sudo pacman -S wkhtmltopdf"
fi