diff options
| author | kj_sh604 | 2026-03-12 23:30:44 -0400 |
|---|---|---|
| committer | kj_sh604 | 2026-03-12 23:30:44 -0400 |
| commit | eef8961b63c3d0940ad1ee80040cb140f9ac5973 (patch) | |
| tree | 18663ee20221a7595919eb4c21f371a623ed5d57 /src | |
| parent | ca95b6bf2ae7bce20bb6a2d91651c86fd27c596a (diff) | |
feat: syntax highlighting toggle and more options
Diffstat (limited to 'src')
| -rw-r--r-- | src/app.py | 28 | ||||
| -rw-r--r-- | src/templates/index.html | 12 |
2 files changed, 27 insertions, 13 deletions
@@ -43,9 +43,9 @@ VALID_PAPER_SIZES = { "ledgerpaper", "tabloid", "statement", "flsa", } -VALID_MARGINS = {"0.25in", "0.5in", "0.75in", "1in", "1.25in", "1.5in", "1.75in"} +VALID_MARGINS = {"0.25in", "0.35in", "0.5in", "0.75in", "1in", "1.25in", "1.5in", "1.75in"} -VALID_LINE_SPACINGS = {"1", "1.5", "2"} +VALID_LINE_SPACINGS = {"1", "1.15", "1.5", "2"} # css page dimensions for each paper size PAPER_CSS = { @@ -75,10 +75,9 @@ PAPER_CSS = { "flsa": "8.5in 13in", } -MARKDOWN_EXTENSIONS = [ +MARKDOWN_BASE_EXTENSIONS = [ "tables", "fenced_code", - "codehilite", "nl2br", "sane_lists", "smarty", @@ -284,12 +283,18 @@ li {{ # pdf conversion -def markdown_to_html(source): +def markdown_to_html(source, enable_syntax_highlighting=True): """convert markdown text to an html fragment""" + extensions = list(MARKDOWN_BASE_EXTENSIONS) + extension_configs = {} + if enable_syntax_highlighting: + extensions.append("codehilite") + extension_configs = MARKDOWN_EXT_CONFIG + return markdown( source, - extensions=MARKDOWN_EXTENSIONS, - extension_configs=MARKDOWN_EXT_CONFIG, + extensions=extensions, + extension_configs=extension_configs, ) @@ -352,7 +357,7 @@ def convert_with_reportlab(source_markdown, output_path, paper_size, margin, } margin_map = { - "0.25in": 0.25 * inch, "0.5in": 0.5 * inch, "0.75in": 0.75 * inch, + "0.25in": 0.25 * inch, "0.35in": 0.35 * inch, "0.5in": 0.5 * inch, "0.75in": 0.75 * inch, "1in": 1.0 * inch, "1.25in": 1.25 * inch, "1.5in": 1.5 * inch, "1.75in": 1.75 * inch, } @@ -442,9 +447,10 @@ def convert_with_reportlab(source_markdown, output_path, paper_size, margin, def generate_pdf(source_markdown, output_path, paper_size, margin, - font_family, line_spacing, show_page_numbers): + font_family, line_spacing, show_page_numbers, + enable_syntax_highlighting): """convert markdown to pdf. always produces a file.""" - body_html = markdown_to_html(source_markdown) + body_html = markdown_to_html(source_markdown, enable_syntax_highlighting) css = build_pdf_css(paper_size, margin, font_family, line_spacing, show_page_numbers) full_html = build_full_html(body_html, css) @@ -526,6 +532,7 @@ def create_app(): request.form.get("line_spacing", ""), "1", VALID_LINE_SPACINGS, ) show_page_numbers = request.form.get("page_numbers") == "on" + disable_syntax_highlighting = request.form.get("disable_syntax_highlighting") == "on" output_name = f"{APP_NAME}_{int(time.time())}_{random_hex()}.pdf" output_path = GENERATED_DIR / output_name @@ -538,6 +545,7 @@ def create_app(): font_family, line_spacing, show_page_numbers, + not disable_syntax_highlighting, ) if not ok: diff --git a/src/templates/index.html b/src/templates/index.html index a9501e9..6643d35 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -86,9 +86,10 @@ <label for="margin">Margins</label> <select id="margin" name="margin"> - <option value="0.25in">Ultra Narrow (0.25 in)</option> - <option value="0.5in">Very Narrow (0.5 in)</option> - <option value="0.75in">Narrow (0.75 in)</option> + <option value="0.25in">Tight (0.25 in)</option> + <option value="0.35in">Slim (0.35 in)</option> + <option value="0.5in">Half (0.5 in)</option> + <option value="0.75in">3/4ths (0.75 in)</option> <option value="1in" selected>Standard (1.0 in)</option> <option value="1.25in">Comfortable (1.25 in)</option> <option value="1.5in">Wide (1.5 in)</option> @@ -108,6 +109,7 @@ <label for="line_spacing">Line spacing</label> <select id="line_spacing" name="line_spacing"> <option value="1" selected>Single (1.0)</option> + <option value="1.15">Relaxed (1.15)</option> <option value="1.5">One-and-a-half (1.5)</option> <option value="2">Double (2.0)</option> </select> @@ -115,6 +117,10 @@ <label> <input type="checkbox" name="page_numbers" value="on" checked /> show page numbers </label> + + <label> + <input type="checkbox" name="disable_syntax_highlighting" value="on" /> disable syntax highlighting for code blocks + </label> </section> <button id="convert-button" type="submit">generate pdf</button> |
