Fix HTML export of markdown (with newlines, tables and other styling preserved)
This commit is contained in:
parent
917e51aa0b
commit
5a54d809ed
4 changed files with 41 additions and 4 deletions
|
|
@ -3,6 +3,7 @@
|
|||
* Update icon again to remove background
|
||||
* Adjust History icon and reorder toolbar items
|
||||
* Try to address checkbox/bullet size issues (again)
|
||||
* Fix HTML export of markdown (with newlines, tables and other styling preserved)
|
||||
|
||||
# 0.5.1
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import datetime as _dt
|
|||
import hashlib
|
||||
import html
|
||||
import json
|
||||
import markdown
|
||||
import re
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
|
@ -440,14 +441,33 @@ class DBManager:
|
|||
'<html lang="en">',
|
||||
'<meta charset="utf-8">',
|
||||
f"<title>{html.escape(title)}</title>",
|
||||
"<style>body{font:16px/1.5 system-ui,Segoe UI,Roboto,Helvetica,Arial,sans-serif;padding:24px;max-width:900px;margin:auto;}",
|
||||
"article{padding:16px 0;border-bottom:1px solid #ddd;} time{font-weight:600;color:#333;} section{margin-top:8px;}</style>",
|
||||
"<style>"
|
||||
"body{font:16px/1.5 system-ui,Segoe UI,Roboto,Helvetica,Arial,sans-serif;"
|
||||
"padding:24px;max-width:900px;margin:auto;}"
|
||||
"article{padding:16px 0;border-bottom:1px solid #ddd;}"
|
||||
"article header time{font-weight:600;color:#333;}"
|
||||
"section{margin-top:8px;}"
|
||||
"table{border-collapse:collapse;margin-top:8px;}"
|
||||
"th,td{border:1px solid #ddd;padding:4px 8px;text-align:left;}"
|
||||
"</style>",
|
||||
"<body>",
|
||||
f"<h1>{html.escape(title)}</h1>",
|
||||
]
|
||||
for d, c in entries:
|
||||
body_html = markdown.markdown(
|
||||
c,
|
||||
extensions=[
|
||||
"extra",
|
||||
"nl2br",
|
||||
],
|
||||
output_format="html5",
|
||||
)
|
||||
|
||||
parts.append(
|
||||
f"<article><header><time>{html.escape(d)}</time></header><section>{c}</section></article>"
|
||||
f"<article>"
|
||||
f"<header><time>{html.escape(d)}</time></header>"
|
||||
f"<section>{body_html}</section>"
|
||||
f"</article>"
|
||||
)
|
||||
parts.append("</body></html>")
|
||||
|
||||
|
|
|
|||
17
poetry.lock
generated
17
poetry.lock
generated
|
|
@ -307,6 +307,21 @@ files = [
|
|||
{file = "iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "markdown"
|
||||
version = "3.10"
|
||||
description = "Python implementation of John Gruber's Markdown."
|
||||
optional = false
|
||||
python-versions = ">=3.10"
|
||||
files = [
|
||||
{file = "markdown-3.10-py3-none-any.whl", hash = "sha256:b5b99d6951e2e4948d939255596523444c0e677c669700b1d17aa4a8a464cb7c"},
|
||||
{file = "markdown-3.10.tar.gz", hash = "sha256:37062d4f2aa4b2b6b32aefb80faa300f82cc790cb949a35b8caede34f2b68c0e"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
docs = ["mdx_gh_links (>=0.2)", "mkdocs (>=1.6)", "mkdocs-gen-files", "mkdocs-literate-nav", "mkdocs-nature (>=0.6)", "mkdocs-section-index", "mkdocstrings[python]"]
|
||||
testing = ["coverage", "pyyaml"]
|
||||
|
||||
[[package]]
|
||||
name = "packaging"
|
||||
version = "25.0"
|
||||
|
|
@ -744,4 +759,4 @@ zstd = ["zstandard (>=0.18.0)"]
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = ">=3.10,<3.14"
|
||||
content-hash = "d5fd8ea759b6bd3f23336930bdce9241659256ed918ec31746787cc86e817235"
|
||||
content-hash = "86db2b4d6498ce9eba7fa9aedf9ce58fec6a63542b5f3bdb3cf6c4067e5b87df"
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ python = ">=3.10,<3.14"
|
|||
pyside6 = ">=6.8.1,<7.0.0"
|
||||
sqlcipher3-wheels = "^0.5.5.post0"
|
||||
requests = "^2.32.5"
|
||||
markdown = "^3.10"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
bouquin = "bouquin.__main__:main"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue