diff options
| author | Zach DeCook <zachdecook@librem.one> | 2021-02-25 13:27:05 -0500 |
|---|---|---|
| committer | Zach DeCook <zachdecook@librem.one> | 2021-02-25 13:27:05 -0500 |
| commit | 75e5751b312a711085313be491a02fb25ea3aff7 (patch) | |
| tree | 3cf343f377f94e6cc71f19826c5c8e2fa4268909 /usfm2gmi.py | |
| parent | a26dfe5edcb02eaf801d0e629eaee8a49a764e6e (diff) | |
| download | usfm2gmi-75e5751b312a711085313be491a02fb25ea3aff7.tar.gz | |
script: change to be gemini-specific
Diffstat (limited to 'usfm2gmi.py')
| -rwxr-xr-x | usfm2gmi.py | 37 |
1 files changed, 37 insertions, 0 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() |
