decktile 0.2.3__tar.gz → 0.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. {decktile-0.2.3 → decktile-0.2.5}/PKG-INFO +10 -3
  2. {decktile-0.2.3 → decktile-0.2.5}/README.md +9 -2
  3. {decktile-0.2.3 → decktile-0.2.5}/pyproject.toml +1 -1
  4. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/parser/ast.py +6 -0
  5. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/parser/markdown.py +16 -2
  6. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/plugins/directives.py +15 -2
  7. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/plugins/fenced.py +1 -1
  8. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/html.py +10 -1
  9. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/ir.py +4 -2
  10. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/seaborn.py +10 -4
  11. {decktile-0.2.3 → decktile-0.2.5}/tests/test_cli.py +17 -0
  12. {decktile-0.2.3 → decktile-0.2.5}/tests/test_html.py +28 -1
  13. {decktile-0.2.3 → decktile-0.2.5}/tests/test_parser.py +10 -0
  14. {decktile-0.2.3 → decktile-0.2.5}/LICENSE +0 -0
  15. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/__init__.py +0 -0
  16. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/__main__.py +0 -0
  17. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/assets/lucide/VENDORED.md +0 -0
  18. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/assets/lucide/lucide.css +0 -0
  19. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/assets/lucide/lucide.ttf +0 -0
  20. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/cli.py +0 -0
  21. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/parser/__init__.py +0 -0
  22. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/plugins/cards.py +0 -0
  23. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/plugins/layouts.py +0 -0
  24. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/plugins/lucide.py +0 -0
  25. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/plugins/lucide_font.py +0 -0
  26. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/__init__.py +0 -0
  27. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/odf/__init__.py +0 -0
  28. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/odf/geometry.py +0 -0
  29. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/odf/shapes.py +0 -0
  30. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/odf/styles.py +0 -0
  31. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/odp.py +0 -0
  32. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/pdf.py +0 -0
  33. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/pdg.py +0 -0
  34. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/templates/base.css +0 -0
  35. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/templates/decktile.js +0 -0
  36. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/render/templates/shell.html +0 -0
  37. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/seaborn_styles/__init__.py +0 -0
  38. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/seaborn_styles/ossummit_europe.py +0 -0
  39. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/theme/__init__.py +0 -0
  40. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/theme/colors.py +0 -0
  41. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/theme/loader.py +0 -0
  42. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/theme/parser.py +0 -0
  43. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/themes/default.css +0 -0
  44. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/themes/kcd_vietnam.css +0 -0
  45. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/themes/kubecon_china.css +0 -0
  46. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/themes/kubecon_japan.css +0 -0
  47. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/themes/ossummit_europe.css +0 -0
  48. {decktile-0.2.3 → decktile-0.2.5}/src/decktile/themes/ossummit_korea.css +0 -0
  49. {decktile-0.2.3 → decktile-0.2.5}/tests/__init__.py +0 -0
  50. {decktile-0.2.3 → decktile-0.2.5}/tests/test_geometry.py +0 -0
  51. {decktile-0.2.3 → decktile-0.2.5}/tests/test_ir.py +0 -0
  52. {decktile-0.2.3 → decktile-0.2.5}/tests/test_odf_shapes.py +0 -0
  53. {decktile-0.2.3 → decktile-0.2.5}/tests/test_odp.py +0 -0
  54. {decktile-0.2.3 → decktile-0.2.5}/tests/test_pdg.py +0 -0
  55. {decktile-0.2.3 → decktile-0.2.5}/tests/test_seaborn_styles.py +0 -0
  56. {decktile-0.2.3 → decktile-0.2.5}/tests/test_video.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: decktile
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Markdown to designed slides: HTML, PDF and editable ODP
5
5
  Author-Email: Reza Jelveh <git@jelveh.me>
6
6
  License: GPL-3.0-or-later
@@ -356,9 +356,9 @@ The arrow block accepts text or images:
356
356
  | col1 | col2 | # pipe table
357
357
  `inline code` # inline code
358
358
  ```language # fenced code block with syntax highlighting
359
+ ```pdg # predictygraph diagram, inline SVG (recommended)
359
360
  ```mermaid # Mermaid diagram, inline SVG
360
361
  ```seaborn # Seaborn chart, inline SVG
361
- ```pdg # predictygraph diagram, inline SVG
362
362
  ```
363
363
 
364
364
  Card/grid `{...}` attributes: bare words are CSS classes (`{metric}` → `.card.metric`),
@@ -387,7 +387,10 @@ No configuration needed - `pdm install` includes the dependency.
387
387
  ## Diagrams (predictygraph)
388
388
 
389
389
  ` ```pdg ` blocks are drawn with [predictygraph](https://pypi.org/project/predictygraph/),
390
- installed with decktile. Nothing else to install. Node classes match decktile tag colours:
390
+ installed with decktile. Nothing else to install. **predictygraph is the recommended
391
+ way to draw diagrams in decktile**, ahead of mermaid: it takes the slide's font and tag
392
+ colours, its layout is predictable and readable, and it can animate
393
+ (see [Animated diagrams](#animated-diagrams) below). Node classes match decktile tag colours:
391
394
 
392
395
  ````markdown
393
396
  ```pdg
@@ -448,6 +451,9 @@ graph LR
448
451
 
449
452
  Renders inline SVG in HTML, PDF in ODP. Uses the `mermaidx` Python package.
450
453
 
454
+ For new diagrams, prefer ` ```pdg ` ([predictygraph](#diagrams-predictygraph)): it
455
+ follows the slide theme and can animate. Mermaid is there for diagrams you already have.
456
+
451
457
  ## Seaborn charts
452
458
 
453
459
  ````markdown
@@ -584,6 +590,7 @@ and all directives.
584
590
 
585
591
  See also: `examples/mermaid_demo.md`, `examples/seaborn_demo.md`,
586
592
  `examples/pdg_demo.md`, `examples/lucide_demo.md`, `examples/timeline_demo.md`.
593
+ `examples/seaborn_demo.md` ends with hand-drawn matplotlib explainer charts from a real talk.
587
594
 
588
595
  ## Pipeline
589
596
 
@@ -327,9 +327,9 @@ The arrow block accepts text or images:
327
327
  | col1 | col2 | # pipe table
328
328
  `inline code` # inline code
329
329
  ```language # fenced code block with syntax highlighting
330
+ ```pdg # predictygraph diagram, inline SVG (recommended)
330
331
  ```mermaid # Mermaid diagram, inline SVG
331
332
  ```seaborn # Seaborn chart, inline SVG
332
- ```pdg # predictygraph diagram, inline SVG
333
333
  ```
334
334
 
335
335
  Card/grid `{...}` attributes: bare words are CSS classes (`{metric}` → `.card.metric`),
@@ -358,7 +358,10 @@ No configuration needed - `pdm install` includes the dependency.
358
358
  ## Diagrams (predictygraph)
359
359
 
360
360
  ` ```pdg ` blocks are drawn with [predictygraph](https://pypi.org/project/predictygraph/),
361
- installed with decktile. Nothing else to install. Node classes match decktile tag colours:
361
+ installed with decktile. Nothing else to install. **predictygraph is the recommended
362
+ way to draw diagrams in decktile**, ahead of mermaid: it takes the slide's font and tag
363
+ colours, its layout is predictable and readable, and it can animate
364
+ (see [Animated diagrams](#animated-diagrams) below). Node classes match decktile tag colours:
362
365
 
363
366
  ````markdown
364
367
  ```pdg
@@ -419,6 +422,9 @@ graph LR
419
422
 
420
423
  Renders inline SVG in HTML, PDF in ODP. Uses the `mermaidx` Python package.
421
424
 
425
+ For new diagrams, prefer ` ```pdg ` ([predictygraph](#diagrams-predictygraph)): it
426
+ follows the slide theme and can animate. Mermaid is there for diagrams you already have.
427
+
422
428
  ## Seaborn charts
423
429
 
424
430
  ````markdown
@@ -555,6 +561,7 @@ and all directives.
555
561
 
556
562
  See also: `examples/mermaid_demo.md`, `examples/seaborn_demo.md`,
557
563
  `examples/pdg_demo.md`, `examples/lucide_demo.md`, `examples/timeline_demo.md`.
564
+ `examples/seaborn_demo.md` ends with hand-drawn matplotlib explainer charts from a real talk.
558
565
 
559
566
  ## Pipeline
560
567
 
@@ -23,7 +23,7 @@ dependencies = [
23
23
  ]
24
24
  requires-python = ">=3.11"
25
25
  readme = "README.md"
26
- version = "0.2.3"
26
+ version = "0.2.5"
27
27
 
28
28
  [project.license]
29
29
  text = "GPL-3.0-or-later"
@@ -185,6 +185,12 @@ class SoftBreak(Inline):
185
185
  pass
186
186
 
187
187
 
188
+ @dataclass
189
+ class Link(Inline):
190
+ href: str = ""
191
+ children: list[Inline] = field(default_factory=list)
192
+
193
+
188
194
  @dataclass
189
195
  class LucideIcon(Inline):
190
196
  name: str = ""
@@ -8,7 +8,7 @@ from markdown_it.token import Token
8
8
  from decktile.parser.ast import (
9
9
  Document, Meta, Slide,
10
10
  Heading, Paragraph, CodeBlock, Card, Grid, Table, Quote, ListNode, AttrNode,
11
- Text, Strong, Emphasis, Strikethrough, CodeSpan, Image, SoftBreak, LucideIcon,
11
+ Text, Strong, Emphasis, Strikethrough, CodeSpan, Image, SoftBreak, LucideIcon, Link,
12
12
  )
13
13
  from decktile.plugins.fenced import extract_fenced, interleave_fences
14
14
  from decktile.plugins.directives import preprocess_directives, extract_attrs, parse_attr_token
@@ -87,7 +87,7 @@ def _parse_slide(content: str) -> Slide:
87
87
  # Extract fenced blocks
88
88
  content, fence_nodes = extract_fenced(content)
89
89
 
90
- md = MarkdownIt("gfm-like", {"breaks": True, "html": True})
90
+ md = MarkdownIt("gfm-like", {"breaks": True, "html": True, "linkify": True})
91
91
  md.use(lucide_plugin)
92
92
  tokens = md.parse(content)
93
93
  nodes = _tokens_to_nodes(tokens)
@@ -267,6 +267,20 @@ def _walk_inline_children(tokens: list) -> list:
267
267
  inner.extend(_token_inline(tokens[i]))
268
268
  i += 1
269
269
  result.append(Strikethrough(children=inner))
270
+ elif t.type == "link_open":
271
+ href = dict(t.attrs or {}).get("href", "")
272
+ i += 1
273
+ depth, inner_tokens = 1, []
274
+ while i < len(tokens):
275
+ if tokens[i].type == "link_open":
276
+ depth += 1
277
+ elif tokens[i].type == "link_close":
278
+ depth -= 1
279
+ if depth == 0:
280
+ break
281
+ inner_tokens.append(tokens[i])
282
+ i += 1
283
+ result.append(Link(href=href, children=_walk_inline_children(inner_tokens)))
270
284
  else:
271
285
  result.extend(_token_inline(t))
272
286
  i += 1
@@ -5,12 +5,25 @@ from decktile.parser.ast import AttrNode, Paragraph, Text, Node
5
5
 
6
6
 
7
7
  def preprocess_directives(content: str) -> str:
8
- """Convert @directive lines to HTML comment markers."""
8
+ """Convert @directive lines to HTML comment markers.
9
+
10
+ Lines inside fenced code blocks (``` or ~~~) are left alone, so a code
11
+ sample can show directive syntax without it being applied.
12
+ """
9
13
  lines = content.split("\n")
10
14
  result = []
15
+ fence = None
11
16
  for line in lines:
12
17
  stripped = line.strip()
13
- if stripped.startswith("@") and not stripped.startswith("@@"):
18
+ m = re.match(r"(`{3,}|~{3,})", stripped)
19
+ if m:
20
+ if fence is None:
21
+ fence = m.group(1)
22
+ elif stripped.startswith(fence) and not stripped[len(fence):].strip():
23
+ fence = None
24
+ result.append(line)
25
+ continue
26
+ if fence is None and stripped.startswith("@") and not stripped.startswith("@@"):
14
27
  parts = stripped[1:].split(" ", 1)
15
28
  typ = parts[0]
16
29
  value = parts[1] if len(parts) > 1 else ""
@@ -9,7 +9,7 @@ from markdown_it import MarkdownIt
9
9
  from decktile.parser.ast import Arrow, Card, CodeBlock, Grid, Node, Notes
10
10
  from decktile.plugins.lucide import lucide_plugin
11
11
 
12
- _CARD_MD = MarkdownIt("gfm-like", {"breaks": False, "html": True})
12
+ _CARD_MD = MarkdownIt("gfm-like", {"breaks": False, "html": True, "linkify": True})
13
13
  _CARD_MD.use(lucide_plugin)
14
14
 
15
15
  _ICON_RE = re.compile(r'\{icon:(\S+)\s*([^}]*)\}')
@@ -1,6 +1,7 @@
1
1
  """HTML renderer for decktile."""
2
2
 
3
3
  import os
4
+ import re
4
5
  import subprocess
5
6
  import tempfile
6
7
  from pathlib import Path
@@ -200,7 +201,7 @@ def _render_elem(e: Elem) -> str:
200
201
  from decktile.plugins.lucide import render_icon
201
202
  name = e.attrs.get("name", e.content)
202
203
  role = e.attrs.get("role", "")
203
- text = f"{_escape(name)}<br><span class=\"role\">{_escape(role)}</span>" if role else _escape(name)
204
+ text = f"{_escape(name)}<br><span class=\"role\">{_link_emails(_escape(role))}</span>" if role else _escape(name)
204
205
  links = []
205
206
  contact_icons = {"github": "git-fork", "twitter": "bird", "email": "mail", "website": "globe"}
206
207
  for key in ("github", "twitter", "email", "linkedin", "website"):
@@ -260,6 +261,14 @@ def _render_mermaid(content: str, svg: str = "", sid: str = "") -> str:
260
261
  return f'<pre class="mermaid-fallback"{sid}><code>{_escape(content)}</code></pre>'
261
262
 
262
263
 
264
+ _EMAIL_RX = re.compile(r"(?<![\w.@/:])([\w.+-]+@[\w-]+(?:\.[\w-]+)+)(?![\w@])")
265
+
266
+
267
+ def _link_emails(escaped: str) -> str:
268
+ """Wrap bare email addresses in already-escaped text with mailto links."""
269
+ return _EMAIL_RX.sub(r'<a href="mailto:\1">\1</a>', escaped)
270
+
271
+
263
272
  def _render_pdg_html(content: str, svg: str = "", sid: str = "", live: str = "") -> str:
264
273
  if svg and live:
265
274
  # animated on screen, still frame in print/PDF (and for the ODP geometry pass)
@@ -13,7 +13,7 @@ from typing import Any
13
13
  from decktile.parser.ast import (
14
14
  Document, Slide, Heading, Paragraph, CodeBlock, Grid, Card,
15
15
  Table, Quote, ListNode, AttrNode, Text, Strong, Emphasis,
16
- Strikethrough, CodeSpan, Image, SoftBreak, LucideIcon, Arrow, Notes, Row,
16
+ Strikethrough, CodeSpan, Image, SoftBreak, LucideIcon, Link, Arrow, Notes, Row,
17
17
  )
18
18
  from decktile.plugins.layouts import KNOWN_LAYOUTS
19
19
  from decktile.theme.parser import parse_theme
@@ -512,6 +512,8 @@ def _render_inline_html(nodes: list) -> str:
512
512
  s += f'<img src="{_escape(n.src)}" alt="{_escape(n.alt)}" decoding="async"{title}>'
513
513
  elif isinstance(n, SoftBreak):
514
514
  s += " "
515
+ elif isinstance(n, Link):
516
+ s += f'<a href="{_escape(n.href)}">{_render_inline_html(n.children)}</a>'
515
517
  elif isinstance(n, LucideIcon):
516
518
  s += _render_lucide_inline(n.name, n.attrs)
517
519
  return s
@@ -529,7 +531,7 @@ def _render_inline_text(nodes: list) -> str:
529
531
  for n in nodes:
530
532
  if isinstance(n, Text):
531
533
  s += n.content
532
- elif isinstance(n, (Strong, Emphasis, Strikethrough)):
534
+ elif isinstance(n, (Strong, Emphasis, Strikethrough, Link)):
533
535
  s += _render_inline_text(n.children)
534
536
  elif isinstance(n, CodeSpan):
535
537
  s += n.content
@@ -104,10 +104,16 @@ def set_theme(name: str) -> None:
104
104
  # 2) CSS theme file (single source of truth for brand colors)
105
105
  css_style = _css_theme_rcparams(name)
106
106
  if css_style:
107
- import matplotlib
108
- matplotlib.use("Agg")
109
- import matplotlib.pyplot as plt
110
- import seaborn as sns
107
+ try:
108
+ import matplotlib
109
+ matplotlib.use("Agg")
110
+ import matplotlib.pyplot as plt
111
+ import seaborn as sns
112
+ except ImportError:
113
+ # charts are optional (decktile[plot]); without them seaborn blocks
114
+ # fall back to code, so the theme has nothing to apply to
115
+ _palette, _style = name, None
116
+ return
111
117
  palette = css_style.pop("seaborn_palette", _DEFAULT_PALETTE)
112
118
  sns.set_theme(style="darkgrid", palette=palette)
113
119
  plt.rcParams.update(css_style)
@@ -47,3 +47,20 @@ def test_main_failing_file_does_not_stop_the_rest(tmp_path):
47
47
  assert result.exit_code == 1
48
48
  assert "bad.md:" in result.output and "missing.md: no such file" in result.output
49
49
  assert (tmp_path / "out" / "good.html").exists()
50
+
51
+
52
+ def test_seaborn_theme_without_chart_libraries(monkeypatch):
53
+ """seaborn_theme in frontmatter must not crash a build when matplotlib isn't installed."""
54
+ import builtins
55
+
56
+ from decktile.render import seaborn as sb
57
+
58
+ real_import = builtins.__import__
59
+
60
+ def no_plot(name, *a, **k):
61
+ if name.split(".")[0] in ("matplotlib", "seaborn"):
62
+ raise ImportError(name)
63
+ return real_import(name, *a, **k)
64
+
65
+ monkeypatch.setattr(builtins, "__import__", no_plot)
66
+ sb.set_theme("default") # must not raise
@@ -39,7 +39,7 @@ def _title_html(md: str) -> str:
39
39
  from decktile.parser.markdown import parse
40
40
  from decktile.render.html import _render_slide
41
41
  from decktile.render.ir import build_ir
42
- return _render_slide(build_ir(parse(md))[0])
42
+ return _render_slide(build_ir(parse(md), base_css(), default_theme())[0])
43
43
 
44
44
 
45
45
  def test_contributor_renders_labelled_and_distinct_from_speaker():
@@ -186,3 +186,30 @@ def test_render_subtitle_inline_markdown():
186
186
  subtitle = html.split('<p class="subtitle"', 1)[1].split("</p>", 1)[0]
187
187
  assert "<code>nvidia.com/gpu</code>" in subtitle
188
188
  assert "`" not in subtitle
189
+
190
+
191
+ def test_bare_emails_and_urls_become_links():
192
+ from decktile.parser.markdown import parse
193
+ from decktile.render.html import _render_elem
194
+ from decktile.render.ir import build_ir
195
+
196
+ md = "## S\n\nMail reza@dynamia.ai or https://decktile.github.io\n\n- in a list reza@dynamia.ai\n"
197
+ html = "".join(_render_elem(e) for e in build_ir(parse(md), base_css(), default_theme())[0].elements)
198
+ assert '<a href="mailto:reza@dynamia.ai">reza@dynamia.ai</a>' in html
199
+ assert '<a href="https://decktile.github.io">https://decktile.github.io</a>' in html
200
+ assert html.count("mailto:") == 2
201
+
202
+
203
+ def test_markdown_link_keeps_its_text():
204
+ from decktile.parser.markdown import parse
205
+ from decktile.render.html import _render_elem
206
+ from decktile.render.ir import build_ir
207
+
208
+ html = "".join(_render_elem(e) for e in build_ir(parse("## S\n\nSee [the docs](https://x.io/d)\n"), base_css(), default_theme())[0].elements)
209
+ assert '<a href="https://x.io/d">the docs</a>' in html
210
+
211
+
212
+ def test_email_in_speaker_role_is_a_link():
213
+ from decktile.render.html import _link_emails
214
+ assert _link_emails("Mail reza@dynamia.ai now") == 'Mail <a href="mailto:reza@dynamia.ai">reza@dynamia.ai</a> now'
215
+ assert _link_emails("https://x.io/a@b") == "https://x.io/a@b"
@@ -173,3 +173,13 @@ def test_group_cards_without_blank_lines_before_paragraph():
173
173
  nodes = parse("---\ntitle: t\n---\n\n" + md + "\nAfter.\n").slides[0].children
174
174
  assert [type(n).__name__ for n in nodes] == ["Grid", "Paragraph"]
175
175
  assert [c.tag for c in nodes[0].children] == ["cyan", "green", "red"]
176
+
177
+
178
+ def test_directive_inside_code_fence_is_left_as_code():
179
+ from decktile.parser.ast import AttrNode
180
+ from decktile.parser.markdown import parse
181
+ md = "## S\n\n```markdown\n@video clip.mp4\n@layout two-col\n```\n"
182
+ slide = parse(md).slides[0]
183
+ assert not any(isinstance(n, AttrNode) for n in slide.children)
184
+ code = [n for n in slide.children if getattr(n, "language", None) == "markdown"]
185
+ assert code and "@video clip.mp4" in code[0].content
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes