script-publish.py: Use Unicode horizontal tabs
authorW. Trevor King <wking@tremily.us>
Sun, 13 Jan 2013 13:06:05 +0000 (08:06 -0500)
committerW. Trevor King <wking@tremily.us>
Sun, 13 Jan 2013 13:06:05 +0000 (08:06 -0500)
Replace the ControlCodeMatch instances with textual tabs, since they
are appropriately handled in `<pre>` blocks.

posts/script/script-publish.py

index 4f78ac7525ea8c175da7467f6cfbef45da5acd40..3c3a1ca1017e2573ad77c459ef76cb010bc595a1 100755 (executable)
@@ -470,6 +470,13 @@ class ControlParser (object):
                 chunks[i] = str(chunk, self._encoding)
         return chunks
 
+    def _replace_tabs(self, chunks):
+        for i,chunk in enumerate(chunks):
+            if (isinstance(chunks[i], ControlCodeMatch) and
+                    chunks[i].control_code.name == 'horizontal tab'):
+                chunks[i] = '\t'
+        return chunks
+
     def _merge_adjacent_text(self, chunks):
         i = 1
         while i < len(chunks):
@@ -574,6 +581,7 @@ class ControlParser (object):
     def parse(self, element, text):
         chunks = self._replace_control_codes(text)
         chunks = self._decode_text(chunks)
+        chunks = self._replace_tabs(chunks)
         chunks = self._merge_adjacent_text(chunks)
         chunks = self._remove_operating_system_commands(chunks)
         chunks = self._merge_adjacent_text(chunks)