marimo-dev 0.3.4__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: marimo-dev
3
- Version: 0.3.4
3
+ Version: 0.3.5
4
4
  Summary: Build and publish python packages from marimo notebooks
5
5
  Author: Deufel
6
6
  Author-email: Deufel <MDeufel13@gmail.com>
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "marimo-dev"
7
- version = "0.3.4"
7
+ version = "0.3.5"
8
8
  description = "Build and publish python packages from marimo notebooks"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -1,13 +1,12 @@
1
1
  """Build and publish python packages from marimo notebooks"""
2
- __version__ = '0.3.4'
2
+ __version__ = '0.3.5'
3
3
  __author__ = 'Deufel'
4
4
  from .core import Config, read_config, Kind, Param, Node
5
5
  from .read import inline_doc, parse_params, parse_hash_pipe, parse_class_params, parse_class_methods, parse_ret, src_with_decs, is_export, parse_import, parse_const, parse_export, parse_node, parse_file, read_meta, nb_name, scan
6
6
  from .pkg import clean, write, write_mod, rename, apply_renames, rewrite_imports, write_init
7
- from .docs import nb_path, render_node, render_module_page, render_index_page, html_preview, build_docs, export_wasm, write_nojekyll, Icon, write_highlighter
7
+ from .docs import sanitize_for_js, render_node_with_search, render_module_page_datastar, nb_path, render_index_page, html_preview, build_docs, export_wasm, write_nojekyll, Icon, write_highlighter
8
8
  from .build import build, tidy, nuke, get_pypi_name, extract_import_names, pep723_header, write_llms, bundle, bundle_notebook
9
9
  from .publish import check_credentials, check_pypi_auth, publish
10
- from .cli import main
11
10
  __all__ = [
12
11
  "Config",
13
12
  "Icon",
@@ -28,7 +27,6 @@ __all__ = [
28
27
  "html_preview",
29
28
  "inline_doc",
30
29
  "is_export",
31
- "main",
32
30
  "nb_name",
33
31
  "nb_path",
34
32
  "nuke",
@@ -48,9 +46,10 @@ __all__ = [
48
46
  "read_meta",
49
47
  "rename",
50
48
  "render_index_page",
51
- "render_module_page",
52
- "render_node",
49
+ "render_module_page_datastar",
50
+ "render_node_with_search",
53
51
  "rewrite_imports",
52
+ "sanitize_for_js",
54
53
  "scan",
55
54
  "src_with_decs",
56
55
  "tidy",
@@ -8,8 +8,9 @@ from enum import Enum
8
8
  from dataclasses import dataclass, field
9
9
  import os, sys, subprocess, configparser, shutil
10
10
  from functools import partial
11
- from html_tags import mktag, setup_svg, Tag
11
+ from html_tags import mktag, setup_svg, Tag, to_html
12
12
 
13
+ Form = mktag('form')
13
14
  Link = mktag('link', self_closing=True)
14
15
  icons = {'home': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-house-icon lucide-house"><path d="M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8"/><path d="M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/></svg>', 'pypi': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-blocks-icon lucide-blocks"><path d="M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2"/><rect x="14" y="2" width="8" height="8" rx="1"/></svg>', 'menu': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-menu-icon lucide-menu"><path d="M4 5h16"/><path d="M4 12h16"/><path d="M4 19h16"/></svg>', 'x': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x-icon lucide-x"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>', 'github': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github-icon lucide-github"><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></svg>', 'code': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-code-icon lucide-code"><path d="m16 18 6-6-6-6"/><path d="m8 6-6 6 6 6"/></svg>', 'info': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-info-icon lucide-info"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>', 'calendar': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-calendar1-icon lucide-calendar-1"><path d="M11 14h1v4"/><path d="M16 2v4"/><path d="M3 10h18"/><path d="M8 2v4"/><rect x="3" y="4" width="18" height="18" rx="2"/></svg>', 'circle-x': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-x-icon lucide-circle-x"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>', 'external-link': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-external-link-icon lucide-external-link"><path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/></svg>'}
15
16
  COLORS = {'keyword': '#c792ea', 'string': '#c3e88d', 'builtin': '#82aaff', 'decorator': '#f78c6c', 'comment': '#546e7a', 'number': '#f78c6c', 'punctuation': '#89ddff', 'defname': '#82aaff', 'classname': '#ffcb6b', 'operator': '#89ddff', 'call': '#82aaff', 'fstring': '#c3e88d', 'type': '#ffcb6b'}
@@ -23,68 +24,89 @@ Html, Head, Body, Title, Input, Strong = (mktag(t) for t in
23
24
  Script, Style, Iframe = (mktag(t, mode='raw') for t in
24
25
  'script style iframe'.split())
25
26
 
26
- def nb_path(
27
- mod_name,
28
- root='.'
29
- ):
30
- '''[TODO] '''
31
- cfg = read_config(root)
32
- for f in (Path(root) / cfg.nbs).glob('*.py'):
33
- if nb_name(f, root) == mod_name: return f.relative_to(root)
34
- return None
35
-
36
- def render_node(n, repo_url=None, root='.'):
37
- '''Builds a `node` for docs'''
27
+ def sanitize_for_js(text):
28
+ """Sanitize text for safe embedding in a JS string"""
29
+ return (text
30
+ .replace('\\', ' ') # remove backslashes
31
+ .replace('\n', ' ') # remove newlines
32
+ .replace('\r', ' ') # remove carriage returns
33
+ .replace('"', ' ') # remove double quotes
34
+ .replace("'", ' ') # remove single quotes
35
+ .replace('`', ' ') # remove backticks
36
+ .replace('/', ' ') # remove forward slashes
37
+ )
38
+
39
+ def render_node_with_search(n, repo_url=None, root='.'):
38
40
  t = 'class' if 'class ' in n.src else 'async' if n.src.lstrip().startswith('async ') else 'func'
39
41
  signature = clean(n.src)
40
- node_id = f"code-{n.module}-{n.name}"
41
- nb = nb_path(n.module, root)
42
+ node_id = f"node-{n.module}-{n.name}".replace('.', '-')
43
+ signal_search = f"searchable_{node_id}".replace('-', '_')
44
+ signal_match = f"match_{node_id}".replace('-', '_')
42
45
  tag_colors = {'func': '#10b981', 'async': '#f59e0b', 'class': '#8b5cf6'}
43
46
 
44
- code_lines = [Span(cls="code-line")(line) for line in signature.split('\n')]
47
+ # Sanitize searchable text to be safe in JS string
48
+ raw_text = f"{n.name} {n.module} {t} {n.doc or ''} {signature}"
49
+ searchable_text = sanitize_for_js(raw_text.lower())
50
+
51
+ nb = nb_path(n.module, root)
52
+ repo_url = repo_url or ''
45
53
 
46
54
  def ghbtn(icon, label, url):
47
55
  if not url: return None
48
56
  return A(href=url, target="_blank", cls="gh-link")(
49
57
  Button(cls="gh-btn")(Icon(icon, size=16), label))
50
58
 
51
- tag = Span(cls="tag", style=f"background:{tag_colors.get(t, '#666')};")(t)
52
- mod_name = Span(cls="full-name")(Span(cls="mod")(f"{n.module}."), Span(cls="name")(n.name)) if n.module else Span(cls="full-name name")(n.name)
53
-
54
- copy_btn = Button(cls="copy-btn", onclick=f"navigator.clipboard.writeText(document.getElementById('{node_id}').textContent).then(() => this.textContent = '✓').then(() => setTimeout(() => this.textContent = '📋', 1500))")("📋")
55
59
  source_btn = ghbtn('github', 'Source', f"{repo_url}/blob/master/{nb}#L{n.lineno}" if repo_url and nb and n.lineno else None)
56
- edit_btn = ghbtn('code', 'Edit', f"{repo_url}/edit/master/{nb}" if repo_url and nb else None)
57
- blame_btn = ghbtn('info', 'Blame', f"{repo_url}/blame/master/{nb}#L{n.lineno}" if repo_url and nb and n.lineno else None)
58
- history_btn = ghbtn('calendar', 'History', f"{repo_url}/commits/master/{nb}" if repo_url and nb else None)
59
- issue_btn = ghbtn('circle-x', 'Issue', f"{repo_url}/issues/new?title=Issue%20with%20{n.name}&body={repo_url}/blob/master/{nb}%23L{n.lineno}" if repo_url and nb and n.lineno else None)
60
+ edit_btn = ghbtn('code', 'Edit', f"{repo_url}/edit/master/{nb}" if repo_url and nb else None)
61
+ code_lines = [Span(cls="code-line")(line) for line in signature.split('\n')]
60
62
 
61
- return Article()(
63
+ return Div(
64
+ id=node_id,
65
+ **{
66
+ "data-signals": f'{{"{signal_search}": "{searchable_text}", "{signal_match}": 0}}',
67
+ "data-effect": f'${signal_match} = [...$tags, $search.trim()].filter(t => t.length > 0 && ${signal_search}.toLowerCase().includes(t.toLowerCase())).length',
68
+ "data-show": f'($tags.length === 0 && $search.trim().length === 0) || ${signal_match} > 0',
69
+ "data-style:order": f'($tags.length === 0 && $search.trim().length === 0) ? 0 : -${signal_match}',
70
+ }
71
+ )(
62
72
  Style()("""
63
- me { margin-bottom: 0.75rem; border-radius: 8px; overflow: hidden; background: #1e1e1e; max-width: 100%; }
64
- me .header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; }
65
- me .header-left { display: flex; align-items: center; }
66
- me .header-right { display: flex; align-items: center; gap: 0.5rem; }
67
- me .tag { padding: 0.25rem 0.6rem; border-radius: 4px; font-size: 0.75rem; font-weight: 600; color: white; }
68
- me .full-name { font-weight: 500; font-size: 1rem; margin-left: 0.75rem; }
69
- me .mod { color: #666; }
70
- me .name { color: #e5e5e5; }
71
- me .doc { margin: 0; padding: 0 1rem 0.5rem 1rem; color: #888; font-size: 0.85rem; }
72
- me .gh-btn { display: flex; align-items: center; gap: 0.25rem; background: #333; border: 1px solid #444; color: #ccc; padding: 0.25rem 0.5rem; border-radius: 4px; cursor: pointer; font-size: 0.75rem; }
73
- me .gh-link { text-decoration: none; }
74
- me .copy-btn { background: transparent; border: none; cursor: pointer; font-size: 0.9rem; padding: 0.25rem; }
75
- me pre { background: #1a1a1a; border-top: 1px solid #2a2a2a; margin: 0; padding: 0.5rem 0; }
76
- me code { counter-reset: line; font-size: 0.8rem; line-height: 1.6; color: #ccc; }
77
- me .code-line { display: block; padding-left: 3.5em; white-space: pre-wrap; word-break: break-all; position: relative; }
78
- me .code-line::before { content: counter(line); counter-increment: line; position: absolute; left: 0; width: 2.5em; text-align: right; color: #555; user-select: none; }
73
+ me { margin-bottom:0.75rem; border-radius:8px; overflow:hidden; background:#1e1e1e; position:relative; }
74
+ me .match-badge { position:absolute; top:1rem; right:1rem; background:#3b82f6; color:white; padding:0.25rem 0.75rem; border-radius:9999px; font-size:0.8rem; font-weight:600; }
75
+ me .header { display:flex; align-items:center; justify-content:space-between; padding:0.75rem 1rem; }
76
+ me .header-left { display:flex; align-items:center; gap:0.75rem; }
77
+ me .header-right { display:flex; align-items:center; gap:0.5rem; }
78
+ me .tag { padding:0.25rem 0.6rem; border-radius:4px; font-size:0.75rem; font-weight:600; color:white; }
79
+ me .full-name { font-size:1rem; font-weight:500; }
80
+ me .mod { color:#666; }
81
+ me .name { color:#e5e5e5; }
82
+ me .doc { margin:0; padding:0 1rem 0.5rem; color:#888; font-size:0.85rem; }
83
+ me .gh-btn { display:flex; align-items:center; gap:0.25rem; background:#333; border:1px solid #444; color:#ccc; padding:0.25rem 0.5rem; border-radius:4px; cursor:pointer; font-size:0.75rem; }
84
+ me .gh-link { text-decoration:none; }
85
+ me pre { background:#1a1a1a; border-top:1px solid #2a2a2a; margin:0; padding:0.5rem 0; }
86
+ me code { font-size:0.8rem; line-height:1.6; color:#ccc; counter-reset:line; }
87
+ me .code-line { display:block; padding-left:3.5em; white-space:pre-wrap; word-break:break-all; position:relative; }
88
+ me .code-line::before { content:counter(line); counter-increment:line; position:absolute; left:0; width:2.5em; text-align:right; color:#555; user-select:none; }
79
89
  """),
90
+ Span(cls="match-badge", **{
91
+ "data-show": f'$tags.length > 0 || $search.trim().length > 0',
92
+ "data-text": f'${signal_match}'
93
+ })(),
80
94
  Div(cls="header")(
81
- Div(cls="header-left")(tag, mod_name),
82
- Div(cls="header-right")(copy_btn, source_btn, edit_btn, blame_btn, history_btn, issue_btn)),
95
+ Div(cls="header-left")(
96
+ Span(cls="tag", style=f"background:{tag_colors.get(t,'#666')};")(t),
97
+ Span(cls="full-name")(
98
+ Span(cls="mod")(f"{n.module}."),
99
+ Span(cls="name")(n.name)
100
+ ) if n.module else Span(cls="full-name name")(n.name)
101
+ ),
102
+ Div(cls="header-right")(source_btn, edit_btn)
103
+ ),
83
104
  P(cls="doc")(n.doc) if n.doc else None,
84
- Pre()(Code(cls="language-python", id=node_id)(*code_lines)))
105
+ Pre()(Code(cls="language-python", id=f"code-{node_id}")(*code_lines))
106
+ )
85
107
 
86
- def render_module_page(mod_name, mod_nodes, all_mod_names, meta, root='.'):
87
- '''Builds a Module Page'''
108
+ def render_module_page_datastar(mod_name, mod_nodes, all_mod_names, meta, root='.'):
109
+ """Builds a Module Page with Datastar search"""
88
110
  repo_url = meta.get('urls', {}).get('Repository')
89
111
  exp_nodes = [n for n in mod_nodes if n.kind == Kind.EXP]
90
112
 
@@ -92,53 +114,94 @@ def render_module_page(mod_name, mod_nodes, all_mod_names, meta, root='.'):
92
114
  Script(type="module", src="https://cdn.jsdelivr.net/gh/starfederation/datastar@1.0.0-RC.8/bundles/datastar.js")(),
93
115
  mktag('script', mode='raw')(src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js")(),
94
116
  Script(src="js/highlight.js", type="module")(),
95
- Style()("body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 0; } code { font-family: 'SF Mono', Consolas, monospace; }"),
96
- Title()(f"{mod_name} - {meta['name']}")]
97
-
98
- nav_links = [Li()(A(href="index.html", cls="back-link")("← Index"))] + [
99
- Li()(A(href=f"{m}.html", cls=f"nav-link {'active' if m == mod_name else ''}")(m)) for m in all_mod_names]
100
-
101
- nav = Nav()(
117
+ Title()(f"{mod_name} - {meta['name']}"),
102
118
  Style()("""
103
- me { padding: 1rem; background: #1a1a1a; min-width: 180px; }
104
- me h3 { margin: 0 0 1rem 0; color: #fff; }
105
- me ul { list-style: none; padding: 0; margin: 0; }
106
- me .back-link { color: #888; text-decoration: none; font-size: 0.85rem; }
107
- me .back-link:hover { color: #fff; }
108
- me .nav-link { color: #aaa; text-decoration: none; }
109
- me .nav-link:hover { color: #fff; }
110
- me .nav-link.active { color: #fff; }
111
- me input { width: 100%; padding: 0.5rem; border: 1px solid #333; border-radius: 4px; background: #252525; color: #fff; margin-bottom: 1rem; box-sizing: border-box; }
112
- """),
113
- H3()(meta['name']),
114
- Input(type="text", placeholder="Search...", **{"data-bind": "search"})(),
115
- Ul()(*nav_links))
116
-
117
- header = Header()(
118
- Style()("""
119
- me { padding: 1rem; background: #1e1e1e; border-bottom: 1px solid #333; }
120
- me .header-row { display: flex; align-items: center; justify-content: space-between; }
121
- me h1 { margin: 0; font-size: 1.5rem; color: #fff; }
122
- me .wasm-btn { display: flex; align-items: center; gap: 0.25rem; background: #333; border: 1px solid #444; color: #ccc; padding: 0.5rem 0.75rem; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
123
- me .wasm-link { text-decoration: none; }
124
- """),
125
- Div(cls="header-row")(
126
- H1()(mod_name),
127
- A(href=f"wasm/{mod_name}/index.html", target="_blank", cls="wasm-link")(
128
- Button(cls="wasm-btn")(Icon('external-link', size=16), "Run in Browser"))))
119
+ * { scrollbar-gutter:stable; box-sizing:border-box; }
120
+ body { font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif; margin:0; background:#121212; }
121
+ code { font-family:'SF Mono',Consolas,monospace; }
122
+ .layout { display:flex; height:100vh; }
123
+ .sidenav { width:220px; background:#1a1a1a; padding:1rem; overflow-y:auto; display:flex; flex-direction:column; gap:0.25rem; flex-shrink:0; }
124
+ .sidenav h3 { margin:0 0 0.75rem 0; color:#fff; font-size:0.9rem; text-transform:uppercase; }
125
+ .nav-item { display:flex; align-items:center; justify-content:space-between; padding:0.4rem 0.5rem; border-radius:4px; color:#aaa; text-decoration:none; font-size:0.85rem; }
126
+ .nav-item:hover { background:#252525; color:#fff; }
127
+ .nav-item.active { color:#fff; background:#252525; }
128
+ .nav-badge { background:#3b82f6; color:white; padding:0.1rem 0.4rem; border-radius:9999px; font-size:0.7rem; font-weight:600; }
129
+ .nav-item.disabled { opacity:0.3; pointer-events:none; }
130
+ .main { flex:1; display:flex; flex-direction:column; overflow:hidden; }
131
+ .topbar { display:flex; align-items:center; justify-content:space-between; padding:0.75rem 1rem; background:#1e1e1e; border-bottom:1px solid #2a2a2a; gap:1rem; flex-shrink:0; }
132
+ .topbar h1 { margin:0; font-size:1.25rem; color:#fff; }
133
+ .search-bar { display:flex; gap:0.5rem; align-items:center; }
134
+ .search-bar input { padding:0.5rem 0.75rem; border:1px solid #333; border-radius:4px; background:#252525; color:#fff; font-size:0.9rem; min-width:220px; }
135
+ .search-bar input:focus { outline:2px solid #3b82f6; }
136
+ .btn { padding:0.5rem 0.9rem; background:#3b82f6; color:white; border:none; border-radius:4px; cursor:pointer; font-size:0.85rem; }
137
+ .btn:hover { background:#2563eb; }
138
+ .btn.clear { background:#dc2626; }
139
+ .btn.clear:hover { background:#b91c1c; }
140
+ .content { flex:1; overflow-y:auto; padding:1rem; display:flex; flex-direction:column; }
141
+ .tags-bar { display:flex; gap:0.5rem; flex-wrap:wrap; margin-bottom:0.5rem; min-height:1.5rem; }
142
+ .tag-pill { background:#3b82f6; color:white; padding:0.2rem 0.6rem; border-radius:9999px; font-size:0.8rem; }
143
+ """)
144
+ ]
129
145
 
130
- content = Div()(
131
- Style()("""
132
- me { padding: 1rem; background: #121212; overflow-y: auto; flex: 1; }
133
- """),
134
- *[render_node(n, repo_url, root) for n in exp_nodes])
146
+ nav_links = [
147
+ Li()(A(href="index.html", cls="nav-item")("← Index")),
148
+ *[
149
+ Li()(A(
150
+ href=f"{m}.html",
151
+ cls=f"nav-item {'active' if m == mod_name else ''}",
152
+ )(
153
+ Span()(m),
154
+ Span(cls="nav-badge", **{
155
+ "data-show": "$tags.length > 0 || $search.trim().length > 0",
156
+ "data-text": "0"
157
+ })()
158
+ ))
159
+ for m in all_mod_names
160
+ ]
161
+ ]
135
162
 
136
- body = Body(style="display: flex; height: 100vh; margin: 0; background: #121212;", **{"data-signals": "{search: ''}"})(
137
- nav,
138
- Div(style="flex: 1; display: flex; flex-direction: column;")(header, content))
163
+ body = Body(
164
+ **{"data-signals": '{"search": "", "tags": []}', "style": "margin:0;"}
165
+ )(
166
+ Div(cls="layout")(
167
+ Nav(cls="sidenav")(
168
+ H3()(meta['name']),
169
+ *nav_links
170
+ ),
171
+ Div(cls="main")(
172
+ Div(cls="topbar")(
173
+ H1()(mod_name),
174
+ Form(
175
+ cls="search-bar",
176
+ **{"data-on:submit__prevent": "$search.trim() ? ($tags = [...$tags, $search.trim()], $search = '') : null"}
177
+ )(
178
+ Input(type="text", placeholder="Search... (Enter to add tag)", **{"data-bind": "search"})(),
179
+ Button(cls="btn", type="submit")("Add Tag"),
180
+ Button(cls="btn clear", type="button", **{"data-on:click": "$tags = [], $search = ''"})("Clear")
181
+ )
182
+ ),
183
+ Div(cls="content")(
184
+ Div(cls="tags-bar", **{"data-show": "$tags.length > 0"})(),
185
+ Div(style="display:flex; flex-direction:column;")(
186
+ *[render_node_with_search(n, repo_url, root) for n in exp_nodes]
187
+ )
188
+ )
189
+ )
190
+ )
191
+ )
139
192
 
140
193
  return Html()(Head()(*head_elements), body)
141
194
 
195
+ def nb_path(
196
+ mod_name,
197
+ root='.'
198
+ ):
199
+ '''[TODO] '''
200
+ cfg = read_config(root)
201
+ for f in (Path(root) / cfg.nbs).glob('*.py'):
202
+ if nb_name(f, root) == mod_name: return f.relative_to(root)
203
+ return None
204
+
142
205
  def render_index_page(meta, mods, repo_url=None):
143
206
  mod_names = [name for name, _ in mods]
144
207
  head_elements = [
@@ -199,18 +262,22 @@ def html_preview(width='100%', height='300px'):
199
262
  return _preview
200
263
 
201
264
  def build_docs(root='.'):
202
- '''Builds the static documentation website'''
203
265
  cfg = read_config(root)
204
266
  meta = read_meta(root)
205
267
  _, mods = scan(root)
206
268
  mod_names = [name for name, _ in mods]
207
269
  docs_path = Path(root) / cfg.docs
208
270
  docs_path.mkdir(exist_ok=True)
209
- (docs_path / "index.html").write_text(str(render_index_page(meta, mods)))
271
+
272
+ (docs_path / "index.html").write_text(to_html(render_index_page(meta, mods)))
273
+
210
274
  for mod_name, mod_nodes in mods:
211
- (docs_path / f"{mod_name}.html").write_text(str(render_module_page(mod_name, mod_nodes, mod_names, meta, root)))
275
+ (docs_path / f"{mod_name}.html").write_text(
276
+ to_html(render_module_page_datastar(mod_name, mod_nodes, mod_names, meta, root))
277
+ )
278
+
212
279
  export_wasm(root)
213
- return f"Generated index + {len(mods)} module pages in {docs_path}"
280
+ return f"Generated index + {len(mods)} module pages with Datastar search in {docs_path}"
214
281
 
215
282
  def export_wasm(
216
283
  root='.' # Project Root
@@ -1,25 +0,0 @@
1
- from .build import build, tidy, nuke, bundle
2
- from .publish import publish
3
- from .docs import build_docs
4
- import sys, subprocess
5
- from pathlib import Path
6
-
7
- def main():
8
- if len(sys.argv) < 2: print("Usage: md [build|publish|docs|tidy|nuke]"); sys.exit(1)
9
- cmd = sys.argv[1]
10
- if cmd == 'build':
11
- print(f"Built package at: {build()}")
12
- print(build_docs())
13
- elif cmd == 'publish':
14
- test = '--test' in sys.argv or '-t' in sys.argv
15
- target = "TestPyPI" if test else "PyPI"
16
- if input(f"Publish to {target}? [y/N] ").lower() != 'y': print("Aborted"); sys.exit(0)
17
- publish(test=test)
18
- elif cmd == 'docs': build_docs()
19
- elif cmd == 'tidy': tidy()
20
- elif cmd == 'nuke': nuke()
21
- elif cmd == 'bundle':
22
- name = sys.argv[2] if len(sys.argv) > 2 else None
23
- print(bundle(name=name))
24
-
25
- else: print(f"Unknown command: {cmd}"); sys.exit(1)
File without changes