Mercurial > cgi-bin > hgweb.cgi > curlyq
comparison curlyq @ 27:70e75dd07e03
Add --ligatures mode.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sat, 17 Oct 2020 14:19:27 -0700 |
parents | 3264788aa0c8 |
children | d5bf9985b5c4 |
comparison
equal
deleted
inserted
replaced
26:3264788aa0c8 | 27:70e75dd07e03 |
---|---|
31 INSEC = '"' | 31 INSEC = '"' |
32 | 32 |
33 # For --tex option | 33 # For --tex option |
34 TEX_SUBST = [ ("---", "—"), ("--", "–"), ("...", "…") ] | 34 TEX_SUBST = [ ("---", "—"), ("--", "–"), ("...", "…") ] |
35 | 35 |
36 # For --ligatures option | |
37 LIG_SUBST = [ ("ffi", "\ufb03"), ("ffl", "\ufb04"), ("ff", "\ufb00"), | |
38 ("fi", "\ufb01"), ("fl", "\ufb02") ] | |
39 | |
36 # C l a s s e s | 40 # C l a s s e s |
37 | 41 |
38 class SafeWorkspace(Workspace): | 42 class SafeWorkspace(Workspace): |
39 def __getitem__(self, key): | 43 def __getitem__(self, key): |
40 try: | 44 try: |
53 ws.append(line) | 57 ws.append(line) |
54 if line == "" or line == "\n": | 58 if line == "" or line == "\n": |
55 if args.force: uncurl(ws) | 59 if args.force: uncurl(ws) |
56 curler.feed() | 60 curler.feed() |
57 if args.backtick: fims(ws) | 61 if args.backtick: fims(ws) |
58 if args.tex: tex(ws) | 62 if args.tex: gsuba(ws, TEX_SUBST) |
63 if args.ligatures: gsuba(ws, LIG_SUBST) | |
59 output_fp.write(str(ws)) | 64 output_fp.write(str(ws)) |
60 ws.clear() | 65 ws.clear() |
61 if line == "": | 66 if line == "": |
62 break | 67 break |
63 | 68 |
71 break | 76 break |
72 ws.append(line) | 77 ws.append(line) |
73 if args.force: uncurl(ws) | 78 if args.force: uncurl(ws) |
74 curler.feed() | 79 curler.feed() |
75 if args.backtick: fims(ws) | 80 if args.backtick: fims(ws) |
76 if args.tex: tex(ws) | 81 if args.tex: gsuba(ws, TEX_SUBST) |
82 if args.ligatures: gsuba(ws, LIG_SUBST) | |
77 output_fp.write(str(ws)) | 83 output_fp.write(str(ws)) |
78 ws.clear() | 84 ws.clear() |
79 | 85 |
80 def html(): | 86 def html(): |
81 global input_fp, output_fp | 87 global input_fp, output_fp |
114 if pos < 0: | 120 if pos < 0: |
115 break | 121 break |
116 buf[pos:pos+olen] = repl | 122 buf[pos:pos+olen] = repl |
117 pos += delta | 123 pos += delta |
118 | 124 |
119 def tex(buf): | 125 def gsuba(buf, subs): |
120 global TEX_SUBST | 126 for i in subs: |
121 for i in TEX_SUBST: | |
122 gsub(buf, i[0], i[1]) | 127 gsub(buf, i[0], i[1]) |
123 | 128 |
124 # M a i n P r o g r a m | 129 # M a i n P r o g r a m |
125 | 130 |
126 # Parse arguments | 131 # Parse arguments |
128 description='Make straight quotes curly.', prog=MYNAME) | 133 description='Make straight quotes curly.', prog=MYNAME) |
129 group = parser.add_mutually_exclusive_group() | 134 group = parser.add_mutually_exclusive_group() |
130 parser.add_argument("--backtick", action="store_true", help="Use backticks on input for ft/in/min/sec.") | 135 parser.add_argument("--backtick", action="store_true", help="Use backticks on input for ft/in/min/sec.") |
131 group.add_argument("--flowed", action="store_true", help="Input is flowed text.") | 136 group.add_argument("--flowed", action="store_true", help="Input is flowed text.") |
132 group.add_argument("--html", action="store_true", help="Input is HTML.") | 137 group.add_argument("--html", action="store_true", help="Input is HTML.") |
138 group.add_argument("--ligatures", action="store_true", help="Use ff, fi, fl, ffi, ffl ligatures.") | |
133 group.add_argument("--uncurl", action="store_true", help="Uncurl quotes instead of curling them.") | 139 group.add_argument("--uncurl", action="store_true", help="Uncurl quotes instead of curling them.") |
134 parser.add_argument("--force", action="store_true", help="Force all quotes to straight ones first.") | 140 parser.add_argument("--force", action="store_true", help="Force all quotes to straight ones first.") |
135 parser.add_argument("--icoding", default="UTF-8", help="Input encoding (default UTF-8).") | 141 parser.add_argument("--icoding", default="UTF-8", help="Input encoding (default UTF-8).") |
136 parser.add_argument("--inplace", action="store_true", help="Edit file in-place.") | 142 parser.add_argument("--inplace", action="store_true", help="Edit file in-place.") |
137 parser.add_argument("--ocoding", default="UTF-8", help="Output encoding (default UTF-8).") | 143 parser.add_argument("--ocoding", default="UTF-8", help="Output encoding (default UTF-8).") |