The internal servers have no access to outside package repositories and run Python 3.8/3.9, so the UI moves from hand-drawn curses to Textual 6.2.1 (the last release supporting 3.8.1), vendored with its pure-Python dependencies in vendor/. The launcher puts vendor/ first on sys.path, so a plain checkout runs with no pip and no network. - dsflow/: the single script split into a package (pure moves of the backend sections); action rules moved to ops.py, free of Textual - dsflow/ui/: tabs, detail pane, live sanity-run panel, log viewer, modal dialogs, filter, themes, mouse support - tests/test_ui.py: headless UI tests through Textual's pilot - tools/vendor.py (refresh vendor/), tools/screenshots.py (README images) - README, CLAUDE.md, TODO and the feature doc updated for the new layout, the Python 3.8.1 floor and the vendoring rules Verified: 11 tests green on Python 3.12 and 3.8.20; the shipped file set runs under `python -I -S` on both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
170 lines
4.5 KiB
Python
Vendored
170 lines
4.5 KiB
Python
Vendored
from __future__ import annotations
|
|
|
|
import itertools
|
|
from typing import TYPE_CHECKING, Sequence
|
|
|
|
from markdown_it import MarkdownIt
|
|
from markdown_it.common.utils import escapeHtml
|
|
from markdown_it.rules_block import StateBlock
|
|
|
|
from mdit_py_plugins.utils import is_code_block
|
|
|
|
if TYPE_CHECKING:
|
|
from markdown_it.renderer import RendererProtocol
|
|
from markdown_it.token import Token
|
|
from markdown_it.utils import EnvType, OptionsDict
|
|
|
|
|
|
def myst_block_plugin(md: MarkdownIt) -> None:
|
|
"""Parse MyST targets (``(name)=``), blockquotes (``% comment``) and block breaks (``+++``)."""
|
|
md.block.ruler.before(
|
|
"blockquote",
|
|
"myst_line_comment",
|
|
line_comment,
|
|
{"alt": ["paragraph", "reference", "blockquote", "list", "footnote_def"]},
|
|
)
|
|
md.block.ruler.before(
|
|
"hr",
|
|
"myst_block_break",
|
|
block_break,
|
|
{"alt": ["paragraph", "reference", "blockquote", "list", "footnote_def"]},
|
|
)
|
|
md.block.ruler.before(
|
|
"hr",
|
|
"myst_target",
|
|
target,
|
|
{"alt": ["paragraph", "reference", "blockquote", "list", "footnote_def"]},
|
|
)
|
|
md.add_render_rule("myst_target", render_myst_target)
|
|
md.add_render_rule("myst_line_comment", render_myst_line_comment)
|
|
|
|
|
|
def line_comment(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
|
if is_code_block(state, startLine):
|
|
return False
|
|
|
|
pos = state.bMarks[startLine] + state.tShift[startLine]
|
|
maximum = state.eMarks[startLine]
|
|
|
|
if state.src[pos] != "%":
|
|
return False
|
|
|
|
if silent:
|
|
return True
|
|
|
|
token = state.push("myst_line_comment", "", 0)
|
|
token.attrSet("class", "myst-line-comment")
|
|
token.content = state.src[pos + 1 : maximum].rstrip()
|
|
token.markup = "%"
|
|
|
|
# search end of block while appending lines to `token.content`
|
|
for nextLine in itertools.count(startLine + 1):
|
|
if nextLine >= endLine:
|
|
break
|
|
pos = state.bMarks[nextLine] + state.tShift[nextLine]
|
|
maximum = state.eMarks[nextLine]
|
|
|
|
if state.src[pos] != "%":
|
|
break
|
|
token.content += "\n" + state.src[pos + 1 : maximum].rstrip()
|
|
|
|
state.line = nextLine
|
|
token.map = [startLine, nextLine]
|
|
|
|
return True
|
|
|
|
|
|
def block_break(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
|
if is_code_block(state, startLine):
|
|
return False
|
|
|
|
pos = state.bMarks[startLine] + state.tShift[startLine]
|
|
maximum = state.eMarks[startLine]
|
|
|
|
marker = state.src[pos]
|
|
pos += 1
|
|
|
|
# Check block marker
|
|
if marker != "+":
|
|
return False
|
|
|
|
# markers can be mixed with spaces, but there should be at least 3 of them
|
|
|
|
cnt = 1
|
|
while pos < maximum:
|
|
ch = state.src[pos]
|
|
if ch != marker and ch not in ("\t", " "):
|
|
break
|
|
if ch == marker:
|
|
cnt += 1
|
|
pos += 1
|
|
|
|
if cnt < 3:
|
|
return False
|
|
|
|
if silent:
|
|
return True
|
|
|
|
state.line = startLine + 1
|
|
|
|
token = state.push("myst_block_break", "hr", 0)
|
|
token.attrSet("class", "myst-block")
|
|
token.content = state.src[pos:maximum].strip()
|
|
token.map = [startLine, state.line]
|
|
token.markup = marker * cnt
|
|
|
|
return True
|
|
|
|
|
|
def target(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
|
if is_code_block(state, startLine):
|
|
return False
|
|
|
|
pos = state.bMarks[startLine] + state.tShift[startLine]
|
|
maximum = state.eMarks[startLine]
|
|
|
|
text = state.src[pos:maximum].strip()
|
|
if not text.startswith("("):
|
|
return False
|
|
if not text.endswith(")="):
|
|
return False
|
|
if not text[1:-2]:
|
|
return False
|
|
|
|
if silent:
|
|
return True
|
|
|
|
state.line = startLine + 1
|
|
|
|
token = state.push("myst_target", "", 0)
|
|
token.attrSet("class", "myst-target")
|
|
token.content = text[1:-2]
|
|
token.map = [startLine, state.line]
|
|
|
|
return True
|
|
|
|
|
|
def render_myst_target(
|
|
self: RendererProtocol,
|
|
tokens: Sequence[Token],
|
|
idx: int,
|
|
options: OptionsDict,
|
|
env: EnvType,
|
|
) -> str:
|
|
label = tokens[idx].content
|
|
class_name = "myst-target"
|
|
target = f'<a href="#{label}">({label})=</a>'
|
|
return f'<div class="{class_name}">{target}</div>'
|
|
|
|
|
|
def render_myst_line_comment(
|
|
self: RendererProtocol,
|
|
tokens: Sequence[Token],
|
|
idx: int,
|
|
options: OptionsDict,
|
|
env: EnvType,
|
|
) -> str:
|
|
# Strip leading whitespace from all lines
|
|
content = "\n".join(line.lstrip() for line in tokens[idx].content.split("\n"))
|
|
return f"<!-- {escapeHtml(content)} -->"
|