summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xapp.py4
-rwxr-xr-xdatabase.py2
-rwxr-xr-xparser.py33
-rw-r--r--pyproject.toml2
-rw-r--r--templates/thought.html.j26
-rw-r--r--uv.lock8
6 files changed, 30 insertions, 25 deletions
diff --git a/app.py b/app.py
index 610cf8a..ce48130 100755
--- a/app.py
+++ b/app.py
@@ -19,7 +19,7 @@ def get_correct_article_headers(db:database.Database, title):
if title in [i[0] for i in db_headers]:
out = []
for i in db_headers:
- if i != title:
+ if i[0] != title:
out.append(i)
return out + [("index", "/~")]
else:
@@ -69,7 +69,7 @@ def get_thought():
thought_id = flask.request.args.get("id", type=int)
with database.Database() as db:
try:
- title, datetime, redirect, category_name, parsed, headers= parser.get_thought_from_id(db, thought_id)
+ title, datetime, redirect, category_name, parsed, headers = parser.get_thought_from_id(db, thought_id)
except TypeError:
flask.abort(404)
return
diff --git a/database.py b/database.py
index 61c2947..34945a0 100755
--- a/database.py
+++ b/database.py
@@ -18,7 +18,7 @@ class Database:
def get_header_links(self):
cursor = self.__connection.cursor()
- cursor.execute("SELECT name, link FROM headerLinks;")
+ cursor.execute("SELECT name, link FROM headerLinks ORDER BY name;")
return cursor.fetchall()
def get_image(self, imageName):
diff --git a/parser.py b/parser.py
index 860845f..4e62c1f 100755
--- a/parser.py
+++ b/parser.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
@@ -14,15 +16,18 @@ import parser
import shutil
import sys
-ENV = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'))
-
class MyRenderer(mistune.HTMLRenderer):
- def block_code(self, code, info=None):
- if not info:
- return '\n<pre><code>{}</code></pre>\n'.format(houdini.escape_html(code.strip()))
- lexer = get_lexer_by_name(info, stripall=True)
- formatter = HtmlFormatter()
- return highlight(code, lexer, formatter)
+ def blockcode(self, text, lang):
+ try:
+ lexer = get_lexer_by_name(lang, stripall=True)
+ except ClassNotFound:
+ lexer = None
+
+ if lexer:
+ formatter = HtmlFormatter()
+ return highlight(text, lexer, formatter)
+
+ return '\n<pre><code>{}</code></pre>\n'.format(houdini.escape_html(text.strip()))
def block_quote(self, content):
content = content[3:-5]
@@ -38,7 +43,7 @@ class MyRenderer(mistune.HTMLRenderer):
def heading(self, text, level):
hash_ = urllib.parse.quote_plus(text)
- return "<h%d id='%s'>%s <a class='header_linker' href='#%s'>[#]</a></h%d>\n" % (
+ return "<h%d id='%s'>%s <a class='header_linker' href='#%s'>[#]</a></h%d>" % (
level, hash_, text, hash_, level
)
@@ -69,7 +74,7 @@ def get_headers(html):
headers = []
thesmallestlevel = 7
- for node in root.xpath('//h1|//h2|//h3|//h4|//h5//h6'):
+ for node in root.xpath('//h1|//h2|//h3|//h4|//h5|//h6'):
level = int(node.tag[-1])
if level < thesmallestlevel:
thesmallestlevel = level
@@ -81,10 +86,10 @@ def get_headers(html):
headers = [(i[0], i[1] - thesmallestlevel, i[2]) for i in headers]
md_template = jinja2.Template("""
- {% for text, depth, link in contents %}
- {{ " " * depth }} - [{{ text }}]({{ link }})
- {% endfor %}
- """)
+{% for text, depth, link in contents %}
+{{ " " * depth }} - [{{ text }}]({{ link }})
+{% endfor %}
+ """)
return mistune.html(md_template.render(contents = headers))
diff --git a/pyproject.toml b/pyproject.toml
index 5eab0bf..bab9dcf 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -9,7 +9,7 @@ dependencies = [
"houdini-py>=0.1.0",
"jinja2==3.1.4",
"lxml>=5.3.1",
- "mistune==3.0.2",
+ "mistune==2.0.3",
"pastescript==3.2.0",
"pygments>=2.19.1",
"waitress>=3.0.2",
diff --git a/templates/thought.html.j2 b/templates/thought.html.j2
index a6953e2..9310d85 100644
--- a/templates/thought.html.j2
+++ b/templates/thought.html.j2
@@ -5,13 +5,13 @@
{% if contents_html != "" %}
<h5>contents:</h5>
<div id="contents">
- {{ contents_html|safe}}
+ {{ contents_html|safe }}
</div>
{% endif %}
- <h5>this category:<h5>
+ <h5>this category:</h5>
<ul>
<li><b><a href="{{'/thoughts#'+category.replace(' ', '_')}}">{{category}}</a></b></li>
</ul>
</aside>
- {{md_html|safe}}
+ {{ md_html|safe }}
{% endblock %}
diff --git a/uv.lock b/uv.lock
index eb1df2a..08ba00d 100644
--- a/uv.lock
+++ b/uv.lock
@@ -130,11 +130,11 @@ wheels = [
[[package]]
name = "mistune"
-version = "3.0.2"
+version = "2.0.3"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/ef/c8/f0173fe3bf85fd891aee2e7bcd8207dfe26c2c683d727c5a6cc3aec7b628/mistune-3.0.2.tar.gz", hash = "sha256:fc7f93ded930c92394ef2cb6f04a8aabab4117a91449e72dcc8dfa646a508be8", size = 90840 }
+sdist = { url = "https://files.pythonhosted.org/packages/26/83/2d67393cbb535b9ed7a7e42e944c255380f32835be6bcd86840f2c6f5b00/mistune-2.0.3.tar.gz", hash = "sha256:d7605b46b6156b53b7d52a465202b29a6f00f4ea4130ad5d25e9d5547d6b7e50", size = 75763 }
wheels = [
- { url = "https://files.pythonhosted.org/packages/f0/74/c95adcdf032956d9ef6c89a9b8a5152bf73915f8c633f3e3d88d06bd699c/mistune-3.0.2-py3-none-any.whl", hash = "sha256:71481854c30fdbc938963d3605b72501f5c10a9320ecd412c121c163a1c7d205", size = 47958 },
+ { url = "https://files.pythonhosted.org/packages/37/7f/3cfa697f14943e7ffd9a1d864ac857ebe269813228dc00ebbf28ed6cea43/mistune-2.0.3-py2.py3-none-any.whl", hash = "sha256:e3964140c0775535fba50bd616fe180920044a64bc21850253267b07bff89924", size = 24518 },
]
[[package]]
@@ -229,7 +229,7 @@ requires-dist = [
{ name = "houdini-py", specifier = ">=0.1.0" },
{ name = "jinja2", specifier = "==3.1.4" },
{ name = "lxml", specifier = ">=5.3.1" },
- { name = "mistune", specifier = "==3.0.2" },
+ { name = "mistune", specifier = "==2.0.3" },
{ name = "pastescript", specifier = "==3.2.0" },
{ name = "pygments", specifier = ">=2.19.1" },
{ name = "waitress", specifier = ">=3.0.2" },