vault backup: 2025-12-06 00:40:26
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 1m18s
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 1m18s
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import pathlib
|
||||
from obsidian_parser import Vault
|
||||
import markdown
|
||||
import re
|
||||
|
||||
import jinja2
|
||||
from markdown.core import Markdown
|
||||
from markdown.extensions import Extension
|
||||
from markdown.preprocessors import Preprocessor
|
||||
from obsidian_parser import Vault
|
||||
|
||||
|
||||
root_dir = pathlib.Path(__file__).parent
|
||||
vault = Vault(root_dir / ".." / "content")
|
||||
@@ -9,38 +14,37 @@ note = vault.get_note("Biokemi/Cellulära processer/Transport över cellmembran/
|
||||
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. """
|
||||
class ObsidianImage(Preprocessor):
|
||||
def run(self, lines):
|
||||
new_lines = []
|
||||
for line in lines:
|
||||
print(repr(line))
|
||||
m = re.search(r"!\[\[(.*)\]\]", line)
|
||||
if m:
|
||||
print(m.groups())
|
||||
if "|" in m.group(1):
|
||||
img, width = m.group(1).split("|")
|
||||
new_lines.append("<img src='../content/attachments/" + img + "' style='width:" + width + ";'/>")
|
||||
else:
|
||||
new_lines.append("<img src='../content/attachments/" + m.group(1) + "'/>")
|
||||
else:
|
||||
new_lines.append(line)
|
||||
return new_lines
|
||||
|
||||
from markdown.extensions import Extension
|
||||
|
||||
class MyExtension(Extension):
|
||||
def extendMarkdown(self, md):
|
||||
md.preprocessors.register(NoRender(md), 'mypattern', 175)
|
||||
md.preprocessors.register(ObsidianImage(md), 'mypattern', 175)
|
||||
|
||||
m = markdown.Markdown(extensions=[])
|
||||
print(m.registeredExtensions)
|
||||
m = Markdown(extensions=[MyExtension()])
|
||||
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)
|
||||
data = template.render(note=note, vault=vault)
|
||||
f.write(data)
|
||||
|
||||
#import webbrowser
|
||||
#webbrowser.open(output.as_uri())
|
||||
#print(f"Written to {output}")
|
||||
import webbrowser
|
||||
webbrowser.open(output.as_uri())
|
||||
print(f"Written to {output}")
|
||||
Reference in New Issue
Block a user