summaryrefslogtreecommitdiff
path: root/src/md.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/md.py')
-rwxr-xr-xsrc/md.py38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/md.py b/src/md.py
index 4ab9aa1..14d7930 100755
--- a/src/md.py
+++ b/src/md.py
@@ -8,7 +8,13 @@ import sys
from jinja2 import Environment, PackageLoader, Template, FileSystemLoader
import mistune
-from mistune.util import escape as escape_text
+from mistune.util import escape as escape_text, safe_entity
+
+ENABLE_CODE_HL=True
+#if ENABLE_CODE_HL:
+from pygments import highlight
+from pygments.lexers import get_lexer_by_name
+from pygments.formatters import html
#global name for templates
article = {}#
@@ -30,6 +36,27 @@ class TocAnchorRenderer(mistune.HTMLRenderer):
#return html + '\n'
return html
+ def block_code(self, code: str, info=None) -> str:
+ if ENABLE_CODE_HL:
+ if info:
+ lexer = get_lexer_by_name(info, stripall=True)
+ #formatter = html.HtmlFormatter()
+ formatter = html.HtmlFormatter(linenos=1)
+ return highlight(code, lexer, formatter)
+ return '<pre><code>' + mistune.escape(code) + '</code></pre>'
+ else:
+ #default behaviout from the renderer
+ #html = '<pre><code'
+ #if info is not None:
+ # info = safe_entity(info.strip())
+ #if info:
+ # lang = info.split(None, 1)[0]
+ # html += ' class="language-' + lang + '"'
+ #return html + '>' + escape_text(code) + '</code></pre>\n'
+
+ return ""
+
+
################################################################################
#get first tags and use them to configure some bits
def get_tags(data):
@@ -104,7 +131,8 @@ if len(sys.argv) < 2:
md_fn = sys.argv[1]
#template loader
-loader = FileSystemLoader( "/home/fam/downloads/source/repos/md-site/src/templ" )
+loader = FileSystemLoader( "/home/fam/downloads/source/repos/md-site-py3/src/templ" )
+#loader = FileSystemLoader( "src/templ" )
templ_env = Environment( loader = loader )
t = templ_env.get_template("main.thtml")
@@ -143,4 +171,8 @@ else:
print(t.render( article=article, block = md_rend ))
#print(raw_tags)
-f.close() \ No newline at end of file
+f.close()
+
+# generate style
+# all styles http://help.farbox.com/pygments.html
+# pygmentize -f html -S colorful > syntax.css \ No newline at end of file