Skip to content

Commit e67961f

Browse files
taylorarndtCopilot
andcommitted
fix: move BRF Python script to scripts/build-brf.py to avoid YAML issues
Heredoc with backslashes/quotes in YAML breaks parsing. Move the python3-louis braille translation to scripts/build-brf.py and call it from the workflow step. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 50e2444 commit e67961f

2 files changed

Lines changed: 58 additions & 35 deletions

File tree

.github/workflows/build-epub.yml

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,8 @@ jobs:
4141
continue-on-error: true
4242
run: |
4343
mkdir -p epub/brf
44-
# Pandoc extracts plain text from EPUB
4544
pandoc epub/git-going-with-github.epub -f epub -t plain -o /tmp/book.txt
46-
# Python + liblouis translates text → Grade 2 braille → NABCC ASCII BRF (no TTS, pure text)
47-
python3 - <<'EOF'
48-
import louis, sys
49-
50-
NABCC = ' A1B\'K2L@CIF/MSP"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\0Z7(_?W]#Y)='
51-
52-
def to_brf(ub):
53-
out = []
54-
for ch in ub:
55-
c = ord(ch)
56-
if 0x2800 <= c <= 0x283F:
57-
out.append(NABCC[c - 0x2800])
58-
else:
59-
out.append(ch if c < 128 else ' ')
60-
return ''.join(out)
61-
62-
with open('/tmp/book.txt', encoding='utf-8', errors='replace') as f:
63-
lines = f.read().split('\n')
64-
65-
brf = []
66-
for line in lines:
67-
if line.strip():
68-
try:
69-
brf.append(to_brf(louis.translateString(['en-ueb-g2.ctb'], line)))
70-
except Exception:
71-
brf.append(line[:80])
72-
else:
73-
brf.append('')
74-
75-
out = '\n'.join(brf)
76-
with open('epub/brf/git-going-with-github.brf', 'w', encoding='ascii', errors='replace') as f:
77-
f.write(out)
78-
print(f"BRF written: {len(out)} bytes, {len(brf)} lines")
79-
EOF
45+
python3 scripts/build-brf.py /tmp/book.txt epub/brf/git-going-with-github.brf
8046
ls -lh epub/brf/
8147
8248
- name: Upload EPUB artifact

scripts/build-brf.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Convert plain text to BRF (Braille Ready Format) using liblouis.
4+
No TTS required — this is pure text-to-braille-dots translation.
5+
6+
Usage: python3 build-brf.py input.txt output.brf
7+
"""
8+
import sys
9+
import louis
10+
11+
# NABCC (North American Braille Computer Code) lookup table.
12+
# Maps 6-dot braille cell bitmask (0-63) to ASCII character.
13+
# bit 0=dot1, bit1=dot2, bit2=dot3, bit3=dot4, bit4=dot5, bit5=dot6
14+
NABCC = " A1B'K2L@CIF/MSP\"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\0Z7(_?W]#Y)="
15+
16+
17+
def unicode_braille_to_brf(text):
18+
"""Convert Unicode braille characters (U+2800-U+283F) to NABCC ASCII."""
19+
out = []
20+
for ch in text:
21+
code = ord(ch)
22+
if 0x2800 <= code <= 0x283F:
23+
out.append(NABCC[code - 0x2800])
24+
elif code < 128:
25+
out.append(ch)
26+
else:
27+
out.append(" ")
28+
return "".join(out)
29+
30+
31+
def main():
32+
input_file = sys.argv[1] if len(sys.argv) > 1 else "/tmp/book.txt"
33+
output_file = sys.argv[2] if len(sys.argv) > 2 else "output.brf"
34+
35+
with open(input_file, encoding="utf-8", errors="replace") as f:
36+
lines = f.read().split("\n")
37+
38+
brf_lines = []
39+
for line in lines:
40+
if line.strip():
41+
try:
42+
braille = louis.translateString(["en-ueb-g2.ctb"], line)
43+
brf_lines.append(unicode_braille_to_brf(braille))
44+
except Exception:
45+
brf_lines.append(line[:80])
46+
else:
47+
brf_lines.append("")
48+
49+
output = "\n".join(brf_lines)
50+
with open(output_file, "w", encoding="ascii", errors="replace") as f:
51+
f.write(output)
52+
53+
print(f"BRF written: {len(output):,} bytes, {len(brf_lines):,} lines")
54+
55+
56+
if __name__ == "__main__":
57+
main()

0 commit comments

Comments
 (0)