Skip to content
quarry Artifact [fc50e2c4f3]
Login

Artifact [fc50e2c4f3]

Artifact fc50e2c4f3164cd2cd9d9964ea4aeae1baaa0cfc58aa34868477a380b2d58c14:


package markup

import (
	"strings"
	"testing"
)

// A table written straight under a line of text is part of that
// paragraph, as fossil reads it, so the markdown in its cells renders.
// Only the blocks fossil has stay raw.
func TestHTMLUnderAParagraphLineKeepsItsMarkdown(t *testing.T) {
	under := "the formula:\n<table>\n<tr>\n<td>`x`<sub>`2`</sub></td>\n</tr>\n</table>\n"
	out, err := Render([]byte(under), nil)
	if err != nil {
		t.Fatal(err)
	}
	if strings.Contains(string(out), "`") || !strings.Contains(string(out), "<code>x</code>") {
		t.Errorf("table under a paragraph line kept its backticks:\n%s", out)
	}
	if !strings.Contains(string(out), "<table>") {
		t.Errorf("the table is gone:\n%s", out)
	}

	// Apart from the text, fossil still reads a table as a paragraph:
	// only <html>, <pre>, <script>, comments and <hr> open a block.
	apart := "the formula:\n\n<table>\n<tr>\n<td>`x`</td>\n</tr>\n</table>\n"
	out, err = Render([]byte(apart), nil)
	if err != nil {
		t.Fatal(err)
	}
	if !strings.Contains(string(out), "<td><code>x</code></td>") {
		t.Errorf("a table after a blank line kept its backticks:\n%s", out)
	}

	pre := "<pre>\n`x` *y*\n</pre>\n"
	out, err = Render([]byte(pre), nil)
	if err != nil {
		t.Fatal(err)
	}
	if !strings.Contains(string(out), "`x` *y*") {
		t.Errorf("a <pre> block was rendered as markdown:\n%s", out)
	}
}