Convert usfm bibles into gemtext (python library/utility)
script: change to be gemini-specific
| -rwxr-xr-x | usfm2gmi.py | 37 | ||||
| -rwxr-xr-x | zachusfm.py | 11 |
2 files changed, 37 insertions, 11 deletions
diff --git a/usfm2gmi.py b/usfm2gmi.py new file mode 100755 index 0000000..9b976ab --- /dev/null +++ b/usfm2gmi.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +import fileinput + +def printf(string): + print(string,end='') + +def convert(line): + """Convert a string to a list of tuples, each a token""" + split = line.split() + out = '' + if len(split) == 0: + return out + if split[0] == '\\s': + return '\n## ' + ' '.join(split[1:]) + skip = 0 + for word in split: + if skip > 0: + skip = skip - 1 + continue + if word in ['\\v', '\\c']: + skip = 1 + elif word == '\\p': + out += '\n' + else: + out += word + ' ' + return out + +def main(): + """Read usfm from stdin, output gemtext to stdout + ./usfm2gmi <in.usfm >out.md + """ + for line in fileinput.input(): + gmi = convert(line) + printf(gmi) + +if __name__ == '__main__': + main() diff --git a/zachusfm.py b/zachusfm.py deleted file mode 100755 index b3f942e..0000000 --- a/zachusfm.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python3 -import sys - -def main(argv): - """Read usfm from stdin, output to stdout in specified format - ./zachusfm md <in.usfm >out.md - """ - print('') - -if __name__ == '__main__': - main(sys.argv) |