package render
import (
"strings"
"testing"
)
func TestHTML_BasicMarkdown(t *testing.T) {
got := HTML("Hello **world**")
if !strings.Contains(got, "<strong>world</strong>") {
t.Fatalf("expected bold, got %q", got)
}
}
func TestHTML_FootnoteReference(t *testing.T) {
// Regression for commit a3b1e52: nested footnotes used to panic because
// the inline parser recursed into the definition block.
src := "See the note[^a].\n\n[^a]: nested [^b]\n[^b]: bottom\n"
got := HTML(src)
if !strings.Contains(got, "footnote") {
t.Fatalf("missing footnote markup in %q", got)
}
}
func TestSummary_TruncatesAtParagraph(t *testing.T) {
body := "First para.\n\nSecond para that should be dropped."
got := Summary(body)
if got != "First para." {
t.Fatalf("Summary: got %q want %q", got, "First para.")
}
}
func TestSummary_StripsInlineMarkdown(t *testing.T) {
got := Summary("A link to [the docs](https://example.com) and `code`.")
for _, frag := range []string{"[", "]", "(", ")", "`"} {
if strings.Contains(got, frag) {
t.Errorf("summary still contains %q: %q", frag, got)
}
}
}
func TestExpand_UnknownShortcodeIsVerbatim(t *testing.T) {
src := "before {{ unknown foo=1 }} after"
if got := Expand(src); got != src {
t.Fatalf("unknown code should pass through, got %q", got)
}
}
func TestExpand_FigureBuildsHTML(t *testing.T) {
src := `{{ figure src="/x.png" alt="x pic" }}caption{{ /figure }}`
got := Expand(src)
if !strings.Contains(got, `<figure>`) {
t.Fatalf("expected figure tag, got %q", got)
}
if !strings.Contains(got, `alt="x pic"`) {
t.Fatalf("expected alt attribute, got %q", got)
}
}
func TestExpand_YoutubeMissingIDFallsThrough(t *testing.T) {
src := `{{ youtube }}`
if got := Expand(src); got != src {
t.Fatalf("youtube without id should pass through, got %q", got)
}
}
func TestParseHead_QuotedArg(t *testing.T) {
name, args := parseHead(`figure src="/a b.png" alt="two words"`)
if name != "figure" {
t.Fatalf("name: %q", name)
}
if args["alt"] != "two words" {
t.Fatalf("alt: %q", args["alt"])
}
if args["src"] != "/a b.png" {
t.Fatalf("src: %q", args["src"])
}
}
func TestExpand_PairedNoteEscapesHTML(t *testing.T) {
src := `{{ note }}<script>alert(1)</script>{{ /note }}`
got := Expand(src)
if strings.Contains(got, "<script>") {
t.Fatalf("expected script to be escaped, got %q", got)
}
}
func TestHTML_CodeBlockPreservesIndent(t *testing.T) {
src := "```go\n\tfmt.Println(\"x\")\n```\n"
got := HTML(src)
if !strings.Contains(got, "\tfmt.Println") {
t.Fatalf("lost indent: %q", got)
}
}