Mercurial > cgi-bin > hgweb.cgi > curlyq
changeset 23:dc30266d4d5b
Add --backtick mode.
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 15 Jan 2020 09:06:55 -0800 |
parents | a771878f6cf4 |
children | f4cc6d8cafe8 |
files | curlyq |
diffstat | 1 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/curlyq Mon Dec 30 08:16:24 2019 -0800 +++ b/curlyq Wed Jan 15 09:06:55 2020 -0800 @@ -25,6 +25,11 @@ CODECS_TO_NAME[codecs.lookup(i)] = i del i +# For feet/inches/min/sec +BACKT = "`" +FTMIN = "'" +INSEC = '"' + # C l a s s e s class SafeWorkspace(Workspace): @@ -46,6 +51,7 @@ if line == "" or line == "\n": if args.force: uncurl(ws) curler.feed() + if args.backtick: fims(ws) output_fp.write(str(ws)) ws.clear() if line == "": @@ -62,6 +68,7 @@ ws.append(line) if args.force: uncurl(ws) curler.feed() + if args.backtick: fims(ws) output_fp.write(str(ws)) ws.clear() @@ -79,12 +86,25 @@ uncurl(ws) output_fp.write(str(ws)) +def fims(buf): + pos = 0 + while True: + pos = buf.find(BACKT) + if pos < 0: + break + if buf[pos+1] == BACKT: + buf[pos:pos+2] = INSEC + else: + buf[pos] = FTMIN + pos += 1 + # M a i n P r o g r a m # Parse arguments parser = argparse.ArgumentParser( description='Make straight quotes curly.', prog=MYNAME) group = parser.add_mutually_exclusive_group() +parser.add_argument("--backtick", action="store_true", help="Use backticks on input for ft/in/min/sec.") group.add_argument("--flowed", action="store_true", help="Input is flowed text.") group.add_argument("--html", action="store_true", help="Input is HTML.") group.add_argument("--uncurl", action="store_true", help="Uncurl quotes instead of curling them.") @@ -99,6 +119,11 @@ except SystemExit: sys.exit(2) +# Sanity check +if args.html and args.backtick: + sys.stderr.write(MYNAME + ": --backtick not supported in --html mode\n") + sys.exit(2) + # Sanity-check codings try: codec = codecs.lookup(args.icoding)