vault backup: 2025-12-06 00:29:07
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 1m17s
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 1m17s
This commit is contained in:
46
wip/static.py
Normal file
46
wip/static.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import pathlib
|
||||
from obsidian_parser import Vault
|
||||
import markdown
|
||||
import jinja2
|
||||
|
||||
root_dir = pathlib.Path(__file__).parent
|
||||
vault = Vault(root_dir / ".." / "content")
|
||||
note = vault.get_note("Biokemi/Cellulära processer/Transport över cellmembran/Anteckningar.md")
|
||||
loader = jinja2.FileSystemLoader(root_dir / "templates")
|
||||
env = jinja2.Environment(loader=loader)
|
||||
|
||||
from markdown.preprocessors import Preprocessor
|
||||
import re
|
||||
|
||||
class NoRender(Preprocessor):
|
||||
""" Skip any line with words 'NO RENDER' in it. """
|
||||
def run(self, lines):
|
||||
new_lines = []
|
||||
for line in lines:
|
||||
print(repr(line))
|
||||
m = re.search(r"!\[\[(.*)\]\]", line)
|
||||
if m:
|
||||
print(m.groups())
|
||||
return new_lines
|
||||
|
||||
from markdown.extensions import Extension
|
||||
|
||||
class MyExtension(Extension):
|
||||
def extendMarkdown(self, md):
|
||||
md.preprocessors.register(NoRender(md), 'mypattern', 175)
|
||||
|
||||
m = markdown.Markdown(extensions=[])
|
||||
print(m.registeredExtensions)
|
||||
env.filters["markdown"] = m.convert
|
||||
|
||||
output = root_dir / "test.html"
|
||||
template = env.get_template("base.html")
|
||||
|
||||
with output.open("w", encoding="utf-8") as f:
|
||||
print(note.reading_view)
|
||||
output = template.render(note=note, vault=vault)
|
||||
f.write(output)
|
||||
|
||||
#import webbrowser
|
||||
#webbrowser.open(output.as_uri())
|
||||
#print(f"Written to {output}")
|
||||
Reference in New Issue
Block a user