feat(sloppy): add --web-host and --web-port args for web mode
This commit is contained in:
+27
-4
@@ -130,10 +130,20 @@ class MarkdownRenderer:
|
||||
"""Render Markdown text with automatic unindentation."""
|
||||
imgui_md.render_unindented(text)
|
||||
|
||||
def render_code(self, code: str, lang: str = "", context_id: str = "default", block_idx: int = 0) -> None:
|
||||
"""Render a code block directly with syntax highlighting."""
|
||||
# Wrap in fake markdown markers for the internal renderer
|
||||
self._render_code_block(f"```{lang}\n{code}```", context_id, block_idx)
|
||||
def _render_code_block(self, block: str, context_id: str, block_idx: int) -> None:
|
||||
"""Render a code block using TextEditor for syntax highlighting."""
|
||||
lines = block.strip('`').split('\n')
|
||||
lang_tag = lines[0].strip().lower() if lines else ""
|
||||
|
||||
# Heuristic to separate lang tag from code
|
||||
if lang_tag and lang_tag not in self._lang_map and not self._is_likely_lang_tag(lang_tag):
|
||||
lang_tag = ""
|
||||
code = '\n'.join(lines)
|
||||
else:
|
||||
code = '\n'.join(lines[1:]) if len(lines) > 1 else ""
|
||||
|
||||
if not lang_tag:
|
||||
lang_tag = self.detect_language(code)
|
||||
|
||||
# Cache management
|
||||
if len(self._editor_cache) > self._max_cache_size:
|
||||
@@ -166,6 +176,19 @@ class MarkdownRenderer:
|
||||
_set_editor_language(editor, lang_id)
|
||||
self._editor_lang_cache[cache_key] = lang_tag
|
||||
|
||||
# Dynamic height calculation
|
||||
line_count = code.count('\n') + 1
|
||||
line_height = imgui.get_text_line_height()
|
||||
height = (line_count * line_height) + 20
|
||||
height = min(max(height, 40), 500)
|
||||
|
||||
editor.render(f"##code_{context_id}_{block_idx}", a_size=imgui.ImVec2(0, height))
|
||||
|
||||
def render_code(self, code: str, lang: str = "", context_id: str = "default", block_idx: int = 0) -> None:
|
||||
"""Render a code block directly with syntax highlighting."""
|
||||
# Wrap in fake markdown markers for the internal renderer
|
||||
self._render_code_block(f"```{lang}\n{code}```", context_id, block_idx)
|
||||
|
||||
def _is_likely_lang_tag(self, tag: str) -> bool:
|
||||
return bool(re.match(r'^[a-zA-Z0-9+#-]+$', tag)) and len(tag) < 15
|
||||
|
||||
|
||||
Reference in New Issue
Block a user