diff --git a/.github/workflows/build-epub.yml b/.github/workflows/build-epub.yml index cac6afff..e8a34792 100644 --- a/.github/workflows/build-epub.yml +++ b/.github/workflows/build-epub.yml @@ -42,7 +42,8 @@ jobs: run: | mkdir -p epub/brf pandoc epub/git-going-with-github.epub -f epub -t plain -o /tmp/book.txt - python3 scripts/build-brf.py /tmp/book.txt epub/brf/git-going-with-github.brf + python3 scripts/build-brf.py /tmp/book.txt epub/brf/git-going-with-github.brf --code ueb + python3 scripts/build-brf.py /tmp/book.txt epub/brf/git-going-with-github-ebae.brf --code ebae ls -lh epub/brf/ - name: Upload EPUB artifact diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 8df332da..cda79560 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -43,7 +43,8 @@ jobs: - name: Build BRF run: | pandoc epub/git-going-with-github.epub -f epub -t plain -o /tmp/book.txt - python3 scripts/build-brf.py /tmp/book.txt epub/git-going-with-github.brf + python3 scripts/build-brf.py /tmp/book.txt epub/git-going-with-github.brf --code ueb + python3 scripts/build-brf.py /tmp/book.txt epub/git-going-with-github-ebae.brf --code ebae - name: Create GitHub Release uses: softprops/action-gh-release@v2 @@ -61,7 +62,9 @@ jobs: | **EPUB** | E-readers, Apple Books, Voice Dream, DAISY players | | **Word (.docx)** | Windows screen readers (JAWS, NVDA), Microsoft Word | | **BRF** | Braille displays and embossers (UEB Grade 2) | + | **BRF, EBAE** | The same, in English Braille American Edition Grade 2, the US code before UEB | files: | epub/git-going-with-github.epub epub/git-going-with-github.docx epub/git-going-with-github.brf + epub/git-going-with-github-ebae.brf diff --git a/scripts/build-brf.py b/scripts/build-brf.py index 522a9e4d..2f0ce9a0 100644 --- a/scripts/build-brf.py +++ b/scripts/build-brf.py @@ -1,13 +1,22 @@ #!/usr/bin/env python3 """ Convert plain text to BRF (Braille Ready Format) using liblouis. -No TTS required — this is pure text-to-braille-dots translation. +No TTS required: this is pure text-to-braille-dots translation. -Usage: python3 build-brf.py input.txt output.brf +Usage: python3 build-brf.py input.txt output.brf [--code ueb|ebae] + +--code ueb Unified English Braille, grade 2 (the default) +--code ebae English Braille American Edition, grade 2: the pre-UEB US code, + for readers who prefer it (issue #174) """ import sys import louis +TABLES = { + "ueb": "en-ueb-g2.ctb", + "ebae": "en-us-g2.ctb", +} + # NABCC (North American Braille Computer Code) lookup table. # Maps 6-dot braille cell bitmask (0-63) to ASCII character. # bit 0=dot1, bit1=dot2, bit2=dot3, bit3=dot4, bit4=dot5, bit5=dot6 @@ -29,8 +38,17 @@ def unicode_braille_to_brf(text): def main(): - input_file = sys.argv[1] if len(sys.argv) > 1 else "/tmp/book.txt" - output_file = sys.argv[2] if len(sys.argv) > 2 else "output.brf" + args = sys.argv[1:] + code = "ueb" + if "--code" in args: + i = args.index("--code") + if i + 1 >= len(args) or args[i + 1] not in TABLES: + sys.exit("--code must be one of: " + ", ".join(TABLES)) + code = args[i + 1] + del args[i:i + 2] + table = TABLES[code] + input_file = args[0] if len(args) > 0 else "/tmp/book.txt" + output_file = args[1] if len(args) > 1 else "output.brf" with open(input_file, encoding="utf-8", errors="replace") as f: lines = f.read().split("\n") @@ -39,7 +57,7 @@ def main(): for line in lines: if line.strip(): try: - braille = louis.translateString(["en-ueb-g2.ctb"], line) + braille = louis.translateString([table], line) brf_lines.append(unicode_braille_to_brf(braille)) except Exception: brf_lines.append(line[:80]) @@ -50,7 +68,7 @@ def main(): with open(output_file, "w", encoding="ascii", errors="replace") as f: f.write(output) - print(f"BRF written: {len(output):,} bytes, {len(brf_lines):,} lines") + print(f"BRF written ({code.upper()}, {table}): {len(output):,} bytes, {len(brf_lines):,} lines") if __name__ == "__main__":