diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/md.py | 38 | ||||
-rw-r--r-- | src/templ/base.thtml | 7 |
2 files changed, 37 insertions, 8 deletions
@@ -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 diff --git a/src/templ/base.thtml b/src/templ/base.thtml index 9066a40..0686a13 100644 --- a/src/templ/base.thtml +++ b/src/templ/base.thtml @@ -1,7 +1,3 @@ -<!-- -well if you checking page source, then I realy whant to work in your -company as its looks like you have there smart ppl dos21h~~~gmail~~~com ---> <!doctype html> <html> @@ -9,7 +5,8 @@ company as its looks like you have there smart ppl dos21h~~~gmail~~~com <!-- Optional theme --> <link rel="stylesheet" href="/styles/monokai-sublime.css"> <link rel="stylesheet" href="/styles/main.css"> - <script src="/js/highlight.pack.js"></script> + <link rel="stylesheet" href="/styles/pygments.css"> + <script src="_/js/highlight.pack.js"></script> <script>hljs.initHighlightingOnLoad();</script> <title>{{article.title}}</title> {% if article.keywords %}<meta name="keyword" content="{{article.keywords}}"/>{% endif %} |