Pārlūkot izejas kodu

properly set language in include_code

Jake Vanderplas 12 gadi atpakaļ
vecāks
revīzija
92e448340c
1 mainītis faili ar 9 papildinājumiem un 2 dzēšanām
  1. 9 2
      liquid_tags/include_code.py

+ 9 - 2
liquid_tags/include_code.py

@@ -6,7 +6,7 @@ based on the octopress video tag [1]_
 
 Syntax
 ------
-{% include_code path/to/code [Title text] %}
+{% include_code path/to/code [lang:python] [Title text] %}
 
 The "path to code" is specified relative to the ``code`` subdirectory of
 the content directory  Optionally, this subdirectory can be specified in the
@@ -82,8 +82,15 @@ def include_code(preprocessor, tag, markup):
     open_tag = preprocessor.configs.htmlStash.store(open_tag, safe=True)
     close_tag = preprocessor.configs.htmlStash.store(close_tag, safe=True)
 
+    if lang:
+        lang_include = ':::' + lang + '\n    '
+    else:
+        lang_include = ''
+
     source = (open_tag
-              + '\n\n    ' + '\n    '.join(code.split('\n')) + '\n\n'
+              + '\n\n    '
+              + lang_include
+              + '\n    '.join(code.split('\n')) + '\n\n'
               + close_tag + '\n')
 
     return source