Created
March 23, 2025 23:25
-
-
Save apsun/b240782cee0f1e1f0298a7fa99620ea8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# add furigana to japanese text and output html | |
# manual edits to output will be preserved | |
# dependency: https://github.com/encody/autoruby | |
# cargo install [email protected] | |
set -euo pipefail | |
if [ "$#" -ne 2 ]; then | |
echo >&2 "usage: $0 in.txt out.html" | |
exit 1 | |
fi | |
in="$1" | |
out="$2" | |
echo "$in" | |
if [ -f "$out" ]; then | |
content="$(sed -n '/<!-- START CONTENT -->/,/<!-- END CONTENT -->/p' "$out")" | |
else | |
content="\ | |
<!-- START CONTENT --> | |
<pre> | |
$(autoruby annotate --format html --include-common "$in") | |
</pre> | |
<!-- END CONTENT -->" | |
fi | |
cat >"$out" <<EOF | |
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<style> | |
body { font-size: x-large; } | |
rt { user-select: none; } | |
body.noruby rt { visibility: hidden; } | |
</style> | |
<script> | |
// Workaround for safari being a piece of shit | |
document.addEventListener("dblclick", (e) => { | |
document.body.className = document.body.className == "noruby" ? "" : "noruby"; | |
}); | |
</script> | |
</head> | |
<body> | |
$content | |
</body> | |
</html> | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment