Skip to content

Commit e3766be

Browse files
authored
remove flexdown completely (#6308)
* remove flexdown completely * remove inner precommit * okasdsaodsa * precommit
1 parent f41f9cb commit e3766be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+281
-1058
lines changed

.github/workflows/pre-commit.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,3 @@ jobs:
3434
fetch-tags: true
3535
fetch-depth: 0
3636
- run: uv run pre-commit run --all-files --show-diff-on-failure
37-
- name: Run docs app pre-commit
38-
run: uv run pre-commit run --all-files --show-diff-on-failure --config docs/app/.pre-commit-config.yaml

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ repos:
44
- args:
55
- reflex
66
- tests
7+
- docs/app
8+
- packages
79
id: ruff-format
810
- args:
911
- --fix
1012
- --exit-non-zero-on-fix
11-
exclude: ^(integration/benchmarks/|docs/app/)
13+
exclude: ^integration/benchmarks/
1214
id: ruff-check
1315
repo: https://github.com/astral-sh/ruff-pre-commit
1416
rev: v0.15.6

docs/app/.pre-commit-config.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

docs/app/CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ reflex_docs/ # Main application code
2323
components/ # Reusable UI components
2424
views/ # Shared view components (navbar, footer, cta)
2525
templates/ # Page templates (docpage, mainpage)
26-
docs/ # Markdown documentation (flexdown)
26+
docs/ # Markdown documentation (reflex_docgen)
2727
tests/ # Pytest + Playwright tests
2828
```
2929

@@ -52,5 +52,5 @@ tests/ # Pytest + Playwright tests
5252

5353
## Key conventions
5454

55-
- Docs: flexdown in `docs/`
55+
- Docs: reflex_docgen in `docs/`
5656
- Before committing: `uv run reflex compile` and `uv run pre-commit run --all-files`

docs/app/pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ requires-python = ">=3.10"
66
dependencies = [
77
"email-validator",
88
"fastapi",
9-
"flexdown",
109
"googletrans-py",
11-
"mistletoe",
1210
"openai",
1311
"orjson",
1412
"pandas",

docs/app/reflex_docs/components/button.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from typing import Callable, Literal
22

3-
from reflex_ui_shared.components.icons import get_icon
4-
53
import reflex as rx
4+
from reflex_ui_shared.components.icons import get_icon
65

76
LiteralButtonVariant = Literal[
87
"primary", "success", "destructive", "secondary", "muted"

docs/app/reflex_docs/components/docpage/navbar/buttons/sidebar.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import reflex as rx
12
import reflex_ui as ui
3+
from reflex.style import toggle_color_mode
24
from reflex_ui_shared.components.icons import get_icon
35
from reflex_ui_shared.components.marketing_button import button
46
from reflex_ui_shared.constants import DISCORD_URL, GITHUB_URL, TWITTER_URL
57
from reflex_ui_shared.views.hosting_banner import HostingBannerState
68

7-
import reflex as rx
8-
from reflex.style import toggle_color_mode
9-
109
_DRAWER_LINKS_DOCS = "/docs"
1110
_DRAWER_LINKS_TEMPLATES = "/templates"
1211
_DRAWER_LINKS_BLOG = "/blog"

docs/app/reflex_docs/docgen_pipeline.py

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import types
55
from pathlib import Path
66

7+
import reflex as rx
78
from reflex_base.constants.colors import ColorType
89
from reflex_docgen.markdown import (
910
Block,
@@ -52,15 +53,14 @@
5253
)
5354
from reflex_ui_shared.constants import REFLEX_ASSETS_CDN
5455

55-
import reflex as rx
56-
5756
# ---------------------------------------------------------------------------
58-
# Exec environment — mirrors flexdown's module-based exec mechanism
57+
# Exec environment — mirrors reflex_docgen's module-based exec mechanism
5958
# ---------------------------------------------------------------------------
6059

6160
# One in-memory module per file — all exec blocks within a doc accumulate
6261
# into the same namespace, so later definitions shadow earlier ones cleanly.
6362
_file_modules: dict[str, types.ModuleType] = {}
63+
_executed_blocks: set[tuple[str, str]] = set()
6464

6565
# Register the parent package so pickle can resolve child modules.
6666
_PARENT_PKG = "_docgen_exec"
@@ -83,8 +83,16 @@ def _exec_code(content: str, env: dict, filename: str) -> None:
8383
"""Execute a ``python exec`` code block via an in-memory module.
8484
8585
All exec blocks within the same file share one module so that State
86-
subclass redefinitions shadow correctly.
86+
subclass redefinitions shadow correctly. When the same block is
87+
encountered a second time (e.g. the frontend is evaluated twice —
88+
once for compilation and once on the backend), skip re-execution and
89+
just populate *env* from the cached module namespace.
8790
"""
91+
key = (filename, content)
92+
if key in _executed_blocks:
93+
env.update(_file_modules[filename].__dict__)
94+
return
95+
8896
if filename not in _file_modules:
8997
mod_name = _make_module_name(filename)
9098
module = types.ModuleType(mod_name)
@@ -99,6 +107,7 @@ def _exec_code(content: str, env: dict, filename: str) -> None:
99107
exec(compile(content, filename or "<docgen-exec>", "exec"), module.__dict__)
100108

101109
env.update(module.__dict__)
110+
_executed_blocks.add(key)
102111

103112

104113
# ---------------------------------------------------------------------------
@@ -165,7 +174,7 @@ def _spans_to_plaintext(spans: tuple[Span, ...]) -> str:
165174
class ReflexDocTransformer(DocumentTransformer[rx.Component]):
166175
"""Transforms a reflex_docgen Document into Reflex components.
167176
168-
Mirrors the rendering that the flexdown pipeline produces, so docs from
177+
Mirrors the rendering that the reflex_docgen pipeline produces, so docs from
169178
the parent docs directory look identical to the locally-authored ones.
170179
"""
171180

@@ -503,27 +512,34 @@ def title_comp() -> rx.Component:
503512
),
504513
]
505514

506-
if children:
507-
# Has body content — render as collapsible accordion.
508-
if title_spans:
509-
trigger.append(title_comp())
510-
body = rx.accordion.content(
511-
self._render_children(children),
512-
padding="0px",
513-
margin_top="16px",
514-
)
515-
else:
516-
trigger.append(
517-
rx.box(
518-
self._render_children(children),
519-
class_name="font-[475] !text-secondary-11",
520-
),
521-
)
522-
body = rx.fragment()
515+
if children and title_spans:
516+
# Has heading + body — render as collapsible accordion.
517+
trigger.append(title_comp())
518+
body = rx.accordion.content(
519+
self._render_children(children),
520+
padding="0px",
521+
margin_top="16px",
522+
)
523523
return collapsible_box(trigger, body, color)
524524

525-
# Title only, no body — simple box.
526-
trigger.append(title_comp())
525+
# Title only, or text-only (no heading) — simple non-collapsible box.
526+
if title_spans:
527+
trigger.append(title_comp())
528+
elif children:
529+
# Render inline spans directly — avoid text_block's mb-4 margin.
530+
spans: list[rx.Component | str] = []
531+
for child in children:
532+
if isinstance(child, TextBlock):
533+
spans.extend(_render_spans(child.children))
534+
else:
535+
spans.append(self.transform_block(child))
536+
trigger.append(
537+
rx.box(
538+
*spans,
539+
class_name="font-[475]",
540+
color=f"{rx.color(color, 11)}",
541+
),
542+
)
527543
return rx.vstack(
528544
rx.hstack(
529545
*trigger,
@@ -694,6 +710,13 @@ def render_docgen_document(
694710

695711

696712
def get_docgen_toc(filepath: str | Path) -> list[tuple[int, str]]:
697-
"""Extract TOC headings as (level, text) tuples — same format as flexdown's get_toc."""
713+
"""Extract TOC headings as (level, text) tuples — same format as reflex_docgen's get_toc."""
698714
doc = _parse_doc(filepath)
699715
return [(h.level, _spans_to_plaintext(h.children)) for h in doc.headings]
716+
717+
718+
def render_markdown(text: str) -> rx.Component:
719+
"""Render a plain markdown text string into Reflex components."""
720+
doc = parse_document(text)
721+
transformer = ReflexDocTransformer()
722+
return transformer.transform(doc)

0 commit comments

Comments
 (0)