All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 1m17s
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
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}") |