Fix markdown renderer under dashboard subpath #64

Merged
timmy merged 1 commits from timmy/63-resolve-markdown-renderer-under-dashboard-subpath into main 2026-08-06 02:18:28 +00:00
2 changed files with 29 additions and 2 deletions

View File

@ -159,7 +159,7 @@ textarea { resize: vertical; min-height: 120px; }
<div class="footer">Creative AI-imbued UI • stackchain-dashboard</div>
<script src="/static/markdown.js"></script>
<script src="static/markdown.js"></script>
<script src="static/commands.js"></script>
<script>
(function(){

View File

@ -1,9 +1,24 @@
import json
import subprocess
from html.parser import HTMLParser
from pathlib import Path
from urllib.parse import urljoin
RENDERER = Path(__file__).parent.parent / "frontend" / "markdown.js"
FRONTEND = Path(__file__).parent.parent / "frontend"
RENDERER = FRONTEND / "markdown.js"
class ScriptSourceParser(HTMLParser):
def __init__(self):
super().__init__()
self.sources = []
def handle_starttag(self, tag, attrs):
if tag == "script":
source = dict(attrs).get("src")
if source:
self.sources.append(source)
def test_markdown_renderer_escapes_raw_html_before_rendering_heading():
@ -23,3 +38,15 @@ def test_markdown_renderer_escapes_raw_html_before_rendering_heading():
assert result.stdout == (
"<h1>&lt;img src=x onerror=alert(document.domain)&gt;</h1>"
)
def test_markdown_script_resolves_inside_dashboard_subpath():
parser = ScriptSourceParser()
parser.feed((FRONTEND / "index.html").read_text())
markdown_source = next(
source for source in parser.sources if source.endswith("markdown.js")
)
assert urljoin(
"https://forge.alexanderwhitestone.com/dashboard/", markdown_source
) == "https://forge.alexanderwhitestone.com/dashboard/static/markdown.js"