From f3c760c25f5270424ded2fd55765da3d20d167ba Mon Sep 17 00:00:00 2001 From: Logan Saso Date: Sun, 4 Oct 2020 15:29:20 -0700 Subject: [PATCH] #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 --- .../create_highlighted_versions.py | 30 ++- .../highlighted/Plaintext/plaintext.txt | 178 ++++++++++++++++++ tests/syntax-tests/source/Plaintext/README.md | 10 + .../syntax-tests/source/Plaintext/bat_options | 1 + .../source/Plaintext/plaintext.txt | Bin 0 -> 436 bytes 5 files changed, 213 insertions(+), 6 deletions(-) create mode 100644 tests/syntax-tests/highlighted/Plaintext/plaintext.txt create mode 100644 tests/syntax-tests/source/Plaintext/README.md create mode 100644 tests/syntax-tests/source/Plaintext/bat_options create mode 100644 tests/syntax-tests/source/Plaintext/plaintext.txt diff --git a/tests/syntax-tests/create_highlighted_versions.py b/tests/syntax-tests/create_highlighted_versions.py index c03a0742..b82cc8cd 100755 --- a/tests/syntax-tests/create_highlighted_versions.py +++ b/tests/syntax-tests/create_highlighted_versions.py @@ -16,6 +16,17 @@ BAT_OPTIONS = [ "--italic-text=always", ] +SKIP_FILENAMES = [ + "LICENSE.md", + "README.md", + "bat_options", +] + + +def get_extra_options(source): + with open(path.join(source, "bat_options"), "r") as f: + return list(map(lambda x: x.rstrip(), f.readlines())) + def create_highlighted_versions(output_basepath): root = os.path.dirname(os.path.abspath(__file__)) @@ -31,16 +42,23 @@ def create_highlighted_versions(output_basepath): env.pop("BAT_TABS", None) env["COLORTERM"] = "truecolor" # make sure to output 24bit colors - bat_output = subprocess.check_output( - ["bat"] + BAT_OPTIONS + [source], stderr=subprocess.PIPE, env=env, - ) - - source_dirname = path.basename(path.dirname(source)) + source_dirpath = path.dirname(source) + source_dirname = path.basename(source_dirpath) source_filename = path.basename(source) - if source_filename == "LICENSE.md": + if source_filename in SKIP_FILENAMES: continue + options = BAT_OPTIONS.copy() + # If a directory is empty, `files` could possibly be 0-length + if path.exists(path.join(source_dirpath, "bat_options")): + options += get_extra_options(source_dirpath) + + bat_output = subprocess.check_output( + ["bat"] + options + [source], + stderr=subprocess.PIPE, env=env, + ) + output_dir = path.join(output_basepath, source_dirname) output_path = path.join(output_dir, source_filename) diff --git a/tests/syntax-tests/highlighted/Plaintext/plaintext.txt b/tests/syntax-tests/highlighted/Plaintext/plaintext.txt new file mode 100644 index 00000000..807728e1 --- /dev/null +++ b/tests/syntax-tests/highlighted/Plaintext/plaintext.txt @@ -0,0 +1,178 @@ +␀␊ +\u{1}␊ +\u{2}␊ +\u{3}␊ +\u{4}␊ +\u{5}␊ +\u{6}␊ +␇␊ +␈␊ +├──┤␊ +␊ +␊ +\u{b}␊ +\u{c}␊ +␊ +\u{e}␊ +\u{f}␊ +\u{10}␊ +\u{11}␊ +\u{12}␊ +\u{13}␊ +\u{14}␊ +\u{15}␊ +\u{16}␊ +\u{17}␊ +\u{18}␊ +\u{19}␊ +\u{1a}␊ +␛␊ +\u{1c}␊ +\u{1d}␊ +\u{1e}␊ +\u{1f}␊ +·␊ +!␊ +"␊ +#␊ +$␊ +%␊ +&␊ +'␊ +(␊ +)␊ +*␊ ++␊ +,␊ +-␊ +.␊ +/␊ +0␊ +1␊ +2␊ +3␊ +4␊ +5␊ +6␊ +7␊ +8␊ +9␊ +:␊ +;␊ +<␊ +=␊ +>␊ +?␊ +@␊ +A␊ +B␊ +C␊ +D␊ +E␊ +F␊ +G␊ +H␊ +I␊ +J␊ +K␊ +L␊ +M␊ +N␊ +O␊ +P␊ +Q␊ +R␊ +S␊ +T␊ +U␊ +V␊ +W␊ +X␊ +Y␊ +Z␊ +[␊ +\␊ +]␊ +^␊ +_␊ +`␊ +a␊ +b␊ +c␊ +d␊ +e␊ +f␊ +g␊ +h␊ +i␊ +j␊ +k␊ +l␊ +m␊ +n␊ +o␊ +p␊ +q␊ +r␊ +s␊ +t␊ +u␊ +v␊ +w␊ +x␊ +y␊ +z␊ +{␊ +|␊ +}␊ +~␊ +\u{7f}␊ +\u{80}␊ +\u{81}␊ +\u{82}␊ +\u{83}␊ +\u{84}␊ +\u{85}␊ +\u{86}␊ +\u{87}␊ +\u{88}␊ +\u{89}␊ +\u{8a}␊ +\u{8b}␊ +\u{8c}␊ +\u{8d}␊ +\u{8e}␊ +\u{8f}␊ +\u{90}␊ +\u{91}␊ +\u{92}␊ +\u{93}␊ +\u{94}␊ +\u{95}␊ +\u{96}␊ +\u{97}␊ +\u{98}␊ +\u{99}␊ +\u{9a}␊ +\u{9b}␊ +\u{9c}␊ +\u{9d}␊ +\u{9e}␊ +\u{9f}␊ +\u{a0}␊ +\u{a1}␊ +\u{a2}␊ +\u{a3}␊ +\u{a4}␊ +\u{a5}␊ +\u{a6}␊ +\u{a7}␊ +\u{a8}␊ +\u{a9}␊ +\u{aa}␊ +\u{ab}␊ +\u{ac}␊ +\u{ad}␊ +\u{ae}␊ +␊ +Here's·a·line·with·multiple·characters. diff --git a/tests/syntax-tests/source/Plaintext/README.md b/tests/syntax-tests/source/Plaintext/README.md new file mode 100644 index 00000000..95679324 --- /dev/null +++ b/tests/syntax-tests/source/Plaintext/README.md @@ -0,0 +1,10 @@ +This text file was generated with the following script. Certain invalid characters were removed manually: + +```python +with open("plaintext.txt", "w"): + for i in range(0x10FFFF): + try: + f.write(chr(i) + "\n") + except: + pass +``` diff --git a/tests/syntax-tests/source/Plaintext/bat_options b/tests/syntax-tests/source/Plaintext/bat_options new file mode 100644 index 00000000..e5dd9b4e --- /dev/null +++ b/tests/syntax-tests/source/Plaintext/bat_options @@ -0,0 +1 @@ +--show-all diff --git a/tests/syntax-tests/source/Plaintext/plaintext.txt b/tests/syntax-tests/source/Plaintext/plaintext.txt new file mode 100644 index 0000000000000000000000000000000000000000..42da1207d3c89516d0bc2968d328f229d1f5eb79 GIT binary patch literal 436 zcmV~$g<4Yq7ywW^j(&FMH8H{NPVDZ$Ij?Ry5Vs)~c6WCt=0p5X<~c32)Jkh@wAD^~ z9dtw|o#~>hZo2ECr(SyNqpyDY8(^S81{-3i#4y8+Fw!WaRTyKeamJfqqDoaJnQV%w zrkQSrnP!=7j=AQUZ-IptS!{`=mRW9vm8z|>+8S%Ev)%?9ZL--GTWz!54m<6#+a7!E zvtNw^G7ic*Bz4#kIeAANQ&6kUarI6pDk*DlQlnE&JL9Z#nw)n*TojkYWpPDZ71zXd zaYNh`x5RC6N8A5uf%KdM!Xg8#C!2Ud=#I=XYoaR z72m{n@k2C=pW>JJE&hnV;vdy%F|8;inWT`fOOwWYIhWKn6w3MfLYicAnPMhePK%|= E|0=(9C;$Ke literal 0 HcmV?d00001