package doc
import (
"strings"
"testing"
)
// A GFM table must come out inside .table-scroll. Without the wrapper a table of
// bare URLs cannot shrink to its grid column and paints over the document's
// table-of-contents rail.
func TestTableIsWrappedForScrolling(t *testing.T) {
src := "| Date | URL |\n|---|---|\n| 2026-07-21 | https://example.com/a |\n"
html := renderMD(t, src).HTML
if !strings.Contains(html, `<div class="table-block"><div class="table-scroll"><table>`) {
t.Errorf("table not wrapped:\n%s", html)
}
if !strings.Contains(html, "</table></div></div>") {
t.Errorf("wrapper not closed:\n%s", html)
}
// The rows still go through goldmark's own renderer.
if !strings.Contains(html, "<thead>") || !strings.Contains(html, "<td>") {
t.Errorf("table body lost:\n%s", html)
}
}
func TestRenderInline(t *testing.T) {
r := NewRenderer()
cases := []struct {
name string
in string
want string
}{
{"wikilink", "[[eatonphil-bookclub]]",
`<a class="wikilink" href="/p/eatonphil-bookclub">eatonphil-bookclub</a>`},
{"pdf attachment", "[[paper.pdf]]",
`<a class="wikilink" href="/assets/paper.pdf">paper.pdf</a>`},
{"several values", "[[alpha]], [[beta]]",
`<a class="wikilink" href="/p/alpha">alpha</a>, <a class="wikilink" href="/p/beta">beta</a>`},
{"bare url is autolinked", "https://example.com/x",
`<a href="https://example.com/x">https://example.com/x</a>`},
{"unresolved link stays visible", "[[missing-thing]]",
`<span class="wikilink-missing" title="unresolved link: missing-thing">missing-thing</span>`},
{"plain text", "want-to-read", "want-to-read"},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if got := r.RenderInline([]byte(c.in), "specs", fakeResolver{}); got != c.want {
t.Errorf("RenderInline(%q)\n got: %s\nwant: %s", c.in, got, c.want)
}
})
}
}