bruAristimunha commited on
Commit
b7024f0
·
verified ·
1 Parent(s): 03ad70c

Move CSS to global; renderer emits structural HTML only

Browse files
Files changed (1) hide show
  1. docstring_renderer.py +12 -37
docstring_renderer.py CHANGED
@@ -55,9 +55,8 @@ def _replace_badges(text: str) -> str:
55
  # Use rST raw HTML inline pass-through.
56
  return (
57
  f"\n\n.. raw:: html\n\n"
58
- f" <span style=\"display:inline-block;padding:2px 8px;"
59
- f"border-radius:4px;background:{color};color:white;"
60
- f"font-size:11px;font-weight:600;margin-right:4px;\">{label}</span>\n\n"
61
  )
62
 
63
  return _BADGE_RE.sub(repl, text)
@@ -105,45 +104,21 @@ def preprocess_docstring(doc: str) -> str:
105
  return doc
106
 
107
 
108
- _STYLE = """
109
- <style>
110
- .bd-doc { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
111
- sans-serif; line-height: 1.55; color: #1f2937; }
112
- .bd-doc h1, .bd-doc h2, .bd-doc h3 { color: #0072B2; margin-top: 1.2em; }
113
- .bd-doc h1 { font-size: 1.5em; border-bottom: 2px solid #0072B2; padding-bottom: 4px; }
114
- .bd-doc h2 { font-size: 1.2em; }
115
- .bd-doc h3 { font-size: 1.05em; }
116
- .bd-doc pre { background: #f6f8fa; padding: 10px 12px; border-radius: 6px;
117
- font-size: 0.9em; overflow-x: auto; }
118
- .bd-doc code { background: #f0f0f5; padding: 1px 5px; border-radius: 3px;
119
- font-size: 0.9em; }
120
- .bd-doc pre code { background: transparent; padding: 0; }
121
- .bd-doc img { max-width: 480px; display: block; margin: 12px auto;
122
- border-radius: 6px; }
123
- .bd-doc table { border-collapse: collapse; margin: 8px 0; }
124
- .bd-doc th, .bd-doc td { border: 1px solid #d0d7de; padding: 4px 10px;
125
- text-align: left; }
126
- .bd-doc th { background: #f6f8fa; }
127
- .bd-doc .admonition { border-left: 4px solid #0072B2; background: #f0f7ff;
128
- padding: 8px 14px; margin: 12px 0; border-radius: 4px; }
129
- .bd-doc .admonition.important { border-color: #D55E00; background: #fdf6ec; }
130
- .bd-doc .admonition.note { border-color: #009E73; background: #effaf3; }
131
- .bd-doc .admonition-title { font-weight: 600; margin-bottom: 4px; }
132
- .bd-doc dl.field-list { display: grid; grid-template-columns: max-content auto;
133
- gap: 4px 12px; }
134
- .bd-doc dl.field-list dt { font-weight: 600; color: #475569; }
135
- </style>
136
- """
137
 
138
 
139
  def render_docstring_html(doc: str | None) -> str:
140
- """Render an rST docstring to a self-contained HTML fragment.
141
 
142
- Returns a string with embedded <style> + <div class="bd-doc">…</div>.
143
- Failures fall back to a <pre> dump so the Space never blanks out.
 
144
  """
145
  if not doc:
146
- return _STYLE + "<div class='bd-doc'><em>No docstring available.</em></div>"
147
 
148
  processed = preprocess_docstring(doc)
149
  try:
@@ -164,7 +139,7 @@ def render_docstring_html(doc: str | None) -> str:
164
  except SystemMessage as exc: # pragma: no cover — defensive
165
  body = f"<pre>{processed}</pre><p><em>(rST parse error: {exc})</em></p>"
166
 
167
- return _STYLE + f"<div class='bd-doc'>{body}</div>"
168
 
169
 
170
  def get_signature_str(cls: type) -> str:
 
55
  # Use rST raw HTML inline pass-through.
56
  return (
57
  f"\n\n.. raw:: html\n\n"
58
+ f" <span class=\"bd-badge\" style=\"background:{color};\">"
59
+ f"{label}</span>\n\n"
 
60
  )
61
 
62
  return _BADGE_RE.sub(repl, text)
 
104
  return doc
105
 
106
 
107
+ # All visual styling now lives in app.py's GLOBAL_CSS so it's injected
108
+ # once via Blocks(css=...) instead of being re-emitted on every model
109
+ # switch. The renderer just returns the structural HTML wrapped in
110
+ # .bd-doc.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
 
113
  def render_docstring_html(doc: str | None) -> str:
114
+ """Render an rST docstring to an HTML fragment wrapped in ``.bd-doc``.
115
 
116
+ Styling is supplied by app.py's GLOBAL_CSS this function emits
117
+ structural HTML only. Failures fall back to a ``<pre>`` dump so the
118
+ Space never blanks out.
119
  """
120
  if not doc:
121
+ return "<div class='bd-doc'><em>No docstring available.</em></div>"
122
 
123
  processed = preprocess_docstring(doc)
124
  try:
 
139
  except SystemMessage as exc: # pragma: no cover — defensive
140
  body = f"<pre>{processed}</pre><p><em>(rST parse error: {exc})</em></p>"
141
 
142
+ return f"<div class='bd-doc'>{body}</div>"
143
 
144
 
145
  def get_signature_str(cls: type) -> str: