# HG changeset patch # User David Barts # Date 1602969567 25200 # Node ID 70e75dd07e03eaac2d9a982f452ca9a02e872bfb # Parent 3264788aa0c8f771b22f7706d56b744df7285ddd Add --ligatures mode. diff -r 3264788aa0c8 -r 70e75dd07e03 curlyq --- a/curlyq Sun Mar 22 08:32:52 2020 -0700 +++ b/curlyq Sat Oct 17 14:19:27 2020 -0700 @@ -33,6 +33,10 @@ # For --tex option TEX_SUBST = [ ("---", "—"), ("--", "–"), ("...", "…") ] +# For --ligatures option +LIG_SUBST = [ ("ffi", "\ufb03"), ("ffl", "\ufb04"), ("ff", "\ufb00"), + ("fi", "\ufb01"), ("fl", "\ufb02") ] + # C l a s s e s class SafeWorkspace(Workspace): @@ -55,7 +59,8 @@ if args.force: uncurl(ws) curler.feed() if args.backtick: fims(ws) - if args.tex: tex(ws) + if args.tex: gsuba(ws, TEX_SUBST) + if args.ligatures: gsuba(ws, LIG_SUBST) output_fp.write(str(ws)) ws.clear() if line == "": @@ -73,7 +78,8 @@ if args.force: uncurl(ws) curler.feed() if args.backtick: fims(ws) - if args.tex: tex(ws) + if args.tex: gsuba(ws, TEX_SUBST) + if args.ligatures: gsuba(ws, LIG_SUBST) output_fp.write(str(ws)) ws.clear() @@ -116,9 +122,8 @@ buf[pos:pos+olen] = repl pos += delta -def tex(buf): - global TEX_SUBST - for i in TEX_SUBST: +def gsuba(buf, subs): + for i in subs: gsub(buf, i[0], i[1]) # M a i n P r o g r a m @@ -130,6 +135,7 @@ 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("--ligatures", action="store_true", help="Use ff, fi, fl, ffi, ffl ligatures.") group.add_argument("--uncurl", action="store_true", help="Uncurl quotes instead of curling them.") parser.add_argument("--force", action="store_true", help="Force all quotes to straight ones first.") parser.add_argument("--icoding", default="UTF-8", help="Input encoding (default UTF-8).")