-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add batch export functionality for markdown to PDF using Typora…
… on MacOS
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
# Will export all markdown files to PDF files using Typora on MacOS | ||
# Find all markdown files (both .md and .markdown extensions) and sort them | ||
find . -type f \( -name "*.md" -o -name "*.markdown" \) | sort | while read -r file; do | ||
# Skip files in .git directory | ||
if [[ "$file" == *".git"* ]]; then | ||
continue | ||
fi | ||
|
||
# Skip blacklisted files | ||
if [[ "$file" == *"README.md"* || | ||
"$file" == *"CONTRIBUTING.md"* || | ||
"$file" == *"mle_div.md"* || | ||
"$file" == *"mmcs/interpretions/src"* ]]; then | ||
continue | ||
fi | ||
|
||
echo "Processing: $file" | ||
./export-pdf.sh "$file" | ||
done | ||
|
||
echo "All markdown files have been processed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
# Will export a markdown file to a PDF file using Typora on MacOS | ||
|
||
# Get the input markdown file path | ||
md_file="$(realpath "$1")" | ||
# Construct the PDF file path by replacing .md with .pdf | ||
pdf_file="${md_file%.md}.pdf" | ||
|
||
# Check if PDF exists and remove it | ||
if [ -f "$pdf_file" ]; then | ||
echo "Removing existing PDF file: $pdf_file" | ||
rm "$pdf_file" | ||
fi | ||
|
||
# Export to PDF using Typora | ||
echo "Exporting $md_file" | ||
osascript typora-export-pdf.applescript "$md_file" | ||
echo "Exported to $pdf_file" | ||
# Check PDF file | ||
ls -lh "$pdf_file" | ||
|
||
# Open the PDF file if flag is set | ||
if [ "$2" == "open" ]; then | ||
echo "Opening $pdf_file" | ||
open "$pdf_file" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# For Typora on MacOS | ||
on run {inputFile} | ||
tell application "Typora" | ||
activate | ||
open inputFile | ||
tell application "System Events" | ||
|
||
-- Wait for Typora window to be ready | ||
delay 1 | ||
repeat until (exists window 1 of process "Typora") | ||
delay 0.1 | ||
end repeat | ||
|
||
-- Export to PDF | ||
delay 1 | ||
keystroke "p" using {command down, control down} | ||
|
||
-- Wait for save dialog | ||
delay 1 | ||
repeat until (exists sheet 1 of window 1 of process "Typora") | ||
delay 0.1 | ||
end repeat | ||
|
||
-- Confirm save | ||
delay 1 | ||
keystroke return | ||
|
||
-- Wait until save dialog disappears | ||
delay 1 | ||
repeat until not (exists sheet 1 of window 1 of process "Typora") | ||
delay 0.1 | ||
end repeat | ||
end tell | ||
|
||
close front window -- Close the current file | ||
end tell | ||
end run |