From b2074b0f9c3f0def3d6d66ef9b91d69bdd6a19ad Mon Sep 17 00:00:00 2001 From: iximeow Date: Wed, 3 Jan 2018 04:27:49 -0800 Subject: add pandoc styling, adjust template template was indented, resulting in weirdness about
 content.

insert a newline before adding #include'd content

try to decode read lines as utf-8 and report error if any

do *not* try to decode for output, just let python deal with it (writing
  unicode strings causes issues because python may try to write
  multi-byte codepoints by converting to a byte, then throwing due to
  out of range values)
---
 content_template.pandoc | 113 +++++++++++++++++++++++++++++++++++-------------
 generator/generate.py   |  10 +++--
 2 files changed, 89 insertions(+), 34 deletions(-)

diff --git a/content_template.pandoc b/content_template.pandoc
index 589eb25..d748c4a 100644
--- a/content_template.pandoc
+++ b/content_template.pandoc
@@ -14,7 +14,8 @@
       margin: auto;
       width: 80%
     }
-    /* colors pulled from my current terminal config */
+    /* colors pulled from my current terminal config.
+       applicable for aha-rendered ANSI text */
     .codebox .black  { color: #2e3436; }
     .codebox .red    { color: #cc0000; }
     .codebox .green  { color: #4e9a06; }
@@ -31,6 +32,52 @@
       /* terminal background */
       background: #171717;
     }
+
+    /* pandoc's default styling colors pre, but we don't need that */
+    .sourceCode { background-color: transparent; }
+    /*
+       DataTypeTok
+       classes, types, etc
+    */
+    .sourceCode .dt { color: #4e9a06; }
+
+    /*
+       KeyWordTok
+       keywords. if, while, except, ...
+    */
+    .sourceCode .kw { color: #c4a000; }
+
+    /* the following five are usually the same color for any language */
+    /* decimal value, base N value, float */
+    .sourceCode .dv, .sourceCode .bn, .sourceCode .fl { color: #cc0000; }
+    /* strings */
+    .sourceCode .st { color: #cc0000; }
+    /* characters */
+    .sourceCode .ch { color: #cc0000; }
+
+    /* comments */
+    .sourceCode .co { color: #3465a4; }
+    /* other - dunno what this is! */
+    .sourceCode .ot { color: #A57800; }
+    /* alert - dunno what this is but it's pretty red. maybe errors? */
+    .sourceCode .al { color: #CB4B16; font-weight: bold; }
+    /* function names - same as other text for now */
+    .sourceCode .fu { }
+    /* region marker - i think ony applicable for c#-like? */
+    .sourceCode .re { }
+    /* error token - how does this differ from alert? */
+    .sourceCode .er { color: #D30102; font-weight: bold; }
+
+    .header {
+      height: 128px;
+      color: #b0b0ff;
+    }
+
+    .button {
+      float: left;
+      width: 256px;
+      color: #00ff00;
+    }
   
 
   $for(css)$
@@ -43,34 +90,38 @@
     $header-includes$
   $endfor$
   
-  
-    $for(include-before)$
-      $include-before$
-    $endfor$
-    $if(title)$
-    
-

$title$

- $if(subtitle)$ -

$subtitle$

- $endif$ - $for(author)$ -

$author$

- $endfor$ - $if(date)$ -

$date$

- $endif$ -
- $endif$ - $if(toc)$ -
- $toc$ -
- $endif$ -
- $body$ -
- $for(include-after)$ - $include-after$ - $endfor$ - + +
+writing index +main index +
+$for(include-before)$ +$include-before$ +$endfor$ +$if(title)$ +
+

$title$

+$if(subtitle)$ +

$subtitle$

+$endif$ +$for(author)$ +

$author$

+$endfor$ +$if(date)$ +

$date$

+$endif$ +
+$endif$ +$if(toc)$ +
+$toc$ +
+$endif$ +
+$body$ +
+$for(include-after)$ +$include-after$ +$endfor$ + diff --git a/generator/generate.py b/generator/generate.py index 494ad0c..7d64f6e 100644 --- a/generator/generate.py +++ b/generator/generate.py @@ -14,7 +14,7 @@ def replace_references(lines, file_dir): try: f = open(filepath) content = f.read() - result = result + content + result = result + '\n' + content except Exception as err: print("Error reading file {}:{}".format(filepath, str(err))) return None @@ -32,7 +32,11 @@ def replace_references(lines, file_dir): return None else: # just include the line! - result = result + line + try: + result = result + line.decode("utf-8") + except Exception as e: + print("Error processing line {}:\n {}\nError: {}".format(i, line, e)) + return None return result if __name__ == "__main__": @@ -73,7 +77,7 @@ if __name__ == "__main__": if not os.path.isdir(dest_wd): os.makedirs(dest_wd) out_file = open(compiled_dest, 'w') - out_file.write(html.decode('utf-8')) + out_file.write(html) out_file.close() except IOError as ioerr: print("Unknown error writing result: " + str(ioerr)) -- cgit v1.1