From bc0c745a936d795da261c0c7afe0bbaefb881327 Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Tue, 19 Jul 2022 12:33:51 +0100 Subject: [PATCH] Harmonise manual versions and add auto-formatting tool for Zint.org.uk website --- docs/Makefile | 2 +- docs/manual.pmd | 2 + docs/zint_org_uk.py | 399 ++++++++++++++++++++++++++++++++++++++++++++ docs/zint_org_uk.sh | 10 ++ 4 files changed, 412 insertions(+), 1 deletion(-) create mode 100644 docs/zint_org_uk.py create mode 100755 docs/zint_org_uk.sh diff --git a/docs/Makefile b/docs/Makefile index ff508365..46233922 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -7,7 +7,7 @@ SOURCE = manual.pmd OUT_PDF = manual.pdf OUT_TXT = manual.txt -HIGHLIGHT_THEME = pygments.theme +HIGHLIGHT_THEME = vs.theme INC_HEADER_PDF = inc_header_pdf.tex INC_BEFORE_BODY_PDF = inc_before_body_pdf.tex INCLUDES_PDF = $(INC_HEADER_PDF) $(INC_BEFORE_BODY_PDF) diff --git a/docs/manual.pmd b/docs/manual.pmd index ff9204ef..f648ad2e 100644 --- a/docs/manual.pmd +++ b/docs/manual.pmd @@ -4008,6 +4008,8 @@ countries. Mac and macOS are trademarks of Apple Inc., registered in the U.S. and other countries. +The Zint logo derived from "SF Planetary Orbiter" font by ShyFoundary + Zint.org.uk website design and hosting provided by Robert Elliott. ## 7.2 Patent Issues diff --git a/docs/zint_org_uk.py b/docs/zint_org_uk.py new file mode 100644 index 00000000..18058dcc --- /dev/null +++ b/docs/zint_org_uk.py @@ -0,0 +1,399 @@ +# Works out which tags should influence indentation and puts them on their own line +def isolate_tag(tag): + global stage + + indentable_tag = True + for keyword in indent_skip: + if keyword in tag: + indentable_tag = False + + if '': + tag_buffer = tag_buffer.replace("\n", " ") + isolate_tag(tag_buffer) + tag = False + text_buffer = "" + +f.close() +manual = stage +stage = "" + +print("Adjusting HTML") +# Change the guts of the HTML tags +in_dd = False +to_remove = False +remove_next = False +span_literal = False +for c in manual: + if c == '<': + # Remove "{#tbl:" table identifiers + if '{#tbl:' in text_buffer: + text_buffer = text_buffer[text_buffer.index('tag=') + 7:-3] + text_buffer = text_buffer.replace('\n', ' ') + text_buffer = '\n' + text_buffer + '\n' + + # Remove "{@tabl:" table references + if 'tbl:' in text_buffer: + text_buffer = '' + + stage += text_buffer + tag = True + tag_buffer = "" + to_remove = False + + if (tag): + tag_buffer += c + else: + text_buffer += c + + if c == '>': + # Remove some tags which aren't needed on website + if 'span' in tag_buffer: + to_remove = True + + if 'div' in tag_buffer: + to_remove = True + + if '"): + in_dd = True + if (tag_buffer == ""): + in_dd = False + + if (in_dd and tag_buffer == '

'): + to_remove = True + + if (in_dd and tag_buffer == '

'): + to_remove = True + + # Remove attributes for some tags + if '' + span_literal = True + + if tag_buffer == '' and span_literal: + tag_buffer = '' + span_literal = False + + if not to_remove: + stage += tag_buffer + tag = False + text_buffer = "" + +manual = stage +stage = "" + +print("Removing empty lines") +# Remove blank lines unless in between
 and 
+last_char = '' +in_pre = False +for c in manual: + if c == '<': + tag = True + tag_buffer = "" + + if (tag): + tag_buffer += c + else: + text_buffer += c + + if c == '>': + if ("': + indentable_tag = True + for keyword in indent_skip: + if keyword in tag_buffer: + indentable_tag = False + + # Protect the indentation in
 segments
+        if ('
+            if (indentation == 1):
+                if (' section has it's own class
+            if (indentation == 1) and (' section has it's own class
+            if (indentation == 1) and (' data and split into output files
+out_filenames = ['chapter1.html', 'chapter2.html', 'chapter3.html', 'chapter4.html', 'chapter5.html',
+                 'chapter6.0.html', 'chapter6.1.html', 'chapter6.2.html', 'chapter6.3.html', 'chapter6.4.html',
+                 'chapter6.5.html', 'chapter6.6.html', 'chapter6.7.html', 'chapter7.html', 'appendixa.html', 'appendixb.html']
+page = 0
+print("Writing... ", out_filenames[page])
+f = open(out_filenames[page], "w")
+h2_tag = False
+for c in manual:
+    if c == '<':
+        if h2_tag == False:
+            stage += text_buffer
+        tag = True
+        tag_buffer = ""
+    
+    if (tag):
+        tag_buffer += c
+    else:
+        text_buffer += c
+        
+    if c == '>':
+        if '':
+            f.write(stage)
+            f.close()
+            stage = ""
+            page += 1
+            print("Writing... ", out_filenames[page])
+            f = open(out_filenames[page], "w")
+        else:
+            stage += tag_buffer
+        tag = False
+        text_buffer = ""
+
+f.write(stage)
+f.close()
diff --git a/docs/zint_org_uk.sh b/docs/zint_org_uk.sh
new file mode 100755
index 00000000..d7e19661
--- /dev/null
+++ b/docs/zint_org_uk.sh
@@ -0,0 +1,10 @@
+#/bin/sh
+
+rm -r ./HTML
+pandoc -o manual.html manual.pmd
+python3 zint_org_uk.py
+rm ./chapter6.0.html
+mkdir HTML
+mv chapter*.html ./HTML
+mv appendix*.html ./HTML
+cd ./HTML