summaryrefslogtreecommitdiff
path: root/src/md.py
diff options
context:
space:
mode:
authorArturs Artamonovs <dos21h@gmail.com>2023-02-03 14:52:53 +0000
committerArturs Artamonovs <dos21h@gmail.com>2023-02-03 14:52:53 +0000
commit11eb2fc7f8e80bbaca30dfadf5c3552e8953a74b (patch)
tree1d824cf07442327f51dde5b6fd207d0e84b1ac24 /src/md.py
parentecd9e407916a8aa264a9e5added59f3edb1e7de0 (diff)
downloadmd-site-11eb2fc7f8e80bbaca30dfadf5c3552e8953a74b.tar.gz
md-site-11eb2fc7f8e80bbaca30dfadf5c3552e8953a74b.zip
Update the py to use pygments
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