Browse Source

Merge pull request #761 from ozmoroz/hotfix_#602_liquid_tag_python3_str

[liquid_tags] include_code tag Python3 compatibility. Fixes #602
Justin Mayer 8 years ago
parent
commit
b0be1c6fe1
1 changed files with 13 additions and 5 deletions
  1. 13 5
      liquid_tags/include_code.py

+ 13 - 5
liquid_tags/include_code.py

@@ -39,6 +39,7 @@ in the STATIC_PATHS setting, e.g.:
 """
 import re
 import os
+import sys
 from .mdx_liquid_tags import LiquidTags
 
 
@@ -124,11 +125,18 @@ def include_code(preprocessor, tag, markup):
     else:
         lang_include = ''
 
-    source = (open_tag
-              + '\n\n    '
-              + lang_include
-              + '\n    '.join(code.decode(codec).split('\n')) + '\n\n'
-              + close_tag + '\n')
+    if sys.version_info[0] < 3:
+        source = (open_tag
+                  + '\n\n    '
+                  + lang_include
+                  + '\n    '.join(code.decode(codec).split('\n')) + '\n\n'
+                  + close_tag + '\n')
+    else:
+        source = (open_tag
+                  + '\n\n    '
+                  + lang_include
+                  + '\n    '.join(code.split('\n')) + '\n\n'
+                  + close_tag + '\n')
 
     return source