Mercurial > cgi-bin > hgweb.cgi > curlyq
changeset 27:70e75dd07e03
Add --ligatures mode.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sat, 17 Oct 2020 14:19:27 -0700 |
parents | 3264788aa0c8 |
children | a1cda4ff6d4b |
files | curlyq |
diffstat | 1 files changed, 11 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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).")