on master help sign in
#1244 Use [].copy and path.exists instead of more cumbersome solutions

#1244 Slightly optimized create_highlighted_versions.py so that it won't walk the source path when it should be skipping the file #1244 Updated README.md in plaintext source folder #1244 Added extra option loading from `bat_options` file in directory and significantly reduced size of plaintext source #1244 Updated create_highlighted_versions.py to ignore README.md files and use the --show-all option for manually-defined binary files #1244 Updated plaintext file with command bat -A --no-config --style=plain --color=always --theme='1337' --italic-text=always src/Plaintext/plaintext.txt > highlighted/Plaintext/plaintext.txt #1244 Added example plaintext file

commitf3c760c25f5270424ded2fd55765da3d20d167ba authorLogan Saso <logansaso+tech@gmail.com> dateSun 4 Oct 2020, 15:29 (6 years ago) parent24fe946
5 files changed+213−6
tests/syntax-tests/create_highlighted_versions.py+24−6 tests/syntax-tests/highlighted/Plaintext/plaintext.txt+178 tests/syntax-tests/source/Plaintext/README.md+10 tests/syntax-tests/source/Plaintext/bat_options+1 tests/syntax-tests/source/Plaintext/plaintext.txt
tests/syntax-tests/create_highlighted_versions.py+24−6
@@ -16,6 +16,17 @@ BAT_OPTIONS = [
1616 "--italic-text=always",
1717]
1818
19+SKIP_FILENAMES = [
20+ "LICENSE.md",
21+ "README.md",
22+ "bat_options",
23+]
24+
25+
26+def get_extra_options(source):
27+ with open(path.join(source, "bat_options"), "r") as f:
28+ return list(map(lambda x: x.rstrip(), f.readlines()))
29+
1930
2031def create_highlighted_versions(output_basepath):
2132 root = os.path.dirname(os.path.abspath(__file__))
@@ -31,16 +42,23 @@ def create_highlighted_versions(output_basepath):
3142 env.pop("BAT_TABS", None)
3243 env["COLORTERM"] = "truecolor" # make sure to output 24bit colors
3344
34− bat_output = subprocess.check_output(
35− ["bat"] + BAT_OPTIONS + [source], stderr=subprocess.PIPE, env=env,
36− )
37−
38− source_dirname = path.basename(path.dirname(source))
45+ source_dirpath = path.dirname(source)
46+ source_dirname = path.basename(source_dirpath)
3947 source_filename = path.basename(source)
4048
41− if source_filename == "LICENSE.md":
49+ if source_filename in SKIP_FILENAMES:
4250 continue
4351
52+ options = BAT_OPTIONS.copy()
53+ # If a directory is empty, `files` could possibly be 0-length
54+ if path.exists(path.join(source_dirpath, "bat_options")):
55+ options += get_extra_options(source_dirpath)
56+
57+ bat_output = subprocess.check_output(
58+ ["bat"] + options + [source],
59+ stderr=subprocess.PIPE, env=env,
60+ )
61+
4462 output_dir = path.join(output_basepath, source_dirname)
4563 output_path = path.join(output_dir, source_filename)
4664
tests/syntax-tests/highlighted/Plaintext/plaintext.txtnew file+178
@@ -0,0 +1,178 @@
1+␀␊
2+\u{1}␊
3+\u{2}␊
4+\u{3}␊
5+\u{4}␊
6+\u{5}␊
7+\u{6}␊
8+␇␊
9+␈␊
10+├──┤␊
11+␊
12+␊
13+\u{b}␊
14+\u{c}␊
15+␊
16+\u{e}␊
17+\u{f}␊
18+\u{10}␊
19+\u{11}␊
20+\u{12}␊
21+\u{13}␊
22+\u{14}␊
23+\u{15}␊
24+\u{16}␊
25+\u{17}␊
26+\u{18}␊
27+\u{19}␊
28+\u{1a}␊
29+␛␊
30+\u{1c}␊
31+\u{1d}␊
32+\u{1e}␊
33+\u{1f}␊
34+·␊
35+!␊
36+"␊
37+#␊
38+$␊
39+%␊
40+&␊
41+'␊
42+(␊
43+)␊
44+*␊
45++␊
46+,␊
47+-␊
48+.␊
49+/␊
50+0␊
51+1␊
52+2␊
53+3␊
54+4␊
55+5␊
56+6␊
57+7␊
58+8␊
59+9␊
60+:␊
61+;␊
62+<␊
63+=␊
64+>␊
65+?␊
66+@␊
67+A␊
68+B␊
69+C␊
70+D␊
71+E␊
72+F␊
73+G␊
74+H␊
75+I␊
76+J␊
77+K␊
78+L␊
79+M␊
80+N␊
81+O␊
82+P␊
83+Q␊
84+R␊
85+S␊
86+T␊
87+U␊
88+V␊
89+W␊
90+X␊
91+Y␊
92+Z␊
93+[␊
94+\␊
95+]␊
96+^␊
97+_␊
98+`␊
99+a␊
100+b␊
101+c␊
102+d␊
103+e␊
104+f␊
105+g␊
106+h␊
107+i␊
108+j␊
109+k␊
110+l␊
111+m␊
112+n␊
113+o␊
114+p␊
115+q␊
116+r␊
117+s␊
118+t␊
119+u␊
120+v␊
121+w␊
122+x␊
123+y␊
124+z␊
125+{␊
126+|␊
127+}␊
128+~␊
129+\u{7f}␊
130+\u{80}␊
131+\u{81}␊
132+\u{82}␊
133+\u{83}␊
134+\u{84}␊
135+\u{85}␊
136+\u{86}␊
137+\u{87}␊
138+\u{88}␊
139+\u{89}␊
140+\u{8a}␊
141+\u{8b}␊
142+\u{8c}␊
143+\u{8d}␊
144+\u{8e}␊
145+\u{8f}␊
146+\u{90}␊
147+\u{91}␊
148+\u{92}␊
149+\u{93}␊
150+\u{94}␊
151+\u{95}␊
152+\u{96}␊
153+\u{97}␊
154+\u{98}␊
155+\u{99}␊
156+\u{9a}␊
157+\u{9b}␊
158+\u{9c}␊
159+\u{9d}␊
160+\u{9e}␊
161+\u{9f}␊
162+\u{a0}␊
163+\u{a1}␊
164+\u{a2}␊
165+\u{a3}␊
166+\u{a4}␊
167+\u{a5}␊
168+\u{a6}␊
169+\u{a7}␊
170+\u{a8}␊
171+\u{a9}␊
172+\u{aa}␊
173+\u{ab}␊
174+\u{ac}␊
175+\u{ad}␊
176+\u{ae}␊
177+␊
178+Here's·a·line·with·multiple·characters.
tests/syntax-tests/source/Plaintext/README.mdnew file+10
@@ -0,0 +1,10 @@
1+This text file was generated with the following script. Certain invalid characters were removed manually:
2+
3+```python
4+with open("plaintext.txt", "w"):
5+ for i in range(0x10FFFF):
6+ try:
7+ f.write(chr(i) + "\n")
8+ except:
9+ pass
10+```
tests/syntax-tests/source/Plaintext/bat_optionsnew file+1
@@ -0,0 +1 @@
1+--show-all
tests/syntax-tests/source/Plaintext/plaintext.txtnew file

Binary file not shown.