Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
73 lines
2.6 KiB
Go
73 lines
2.6 KiB
Go
package grammaratur_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
htmltomarkdown "github.com/JohannesKaufmann/html-to-markdown/v2"
|
|
"github.com/gomarkdown/markdown"
|
|
"pageswiki/internal/compiler"
|
|
"pageswiki/internal/grammaratur"
|
|
"pageswiki/internal/render"
|
|
)
|
|
|
|
func TestLegacyMarkdownCompatibility(t *testing.T) {
|
|
for _, source := range []string{
|
|
"", "# Heading\n\n本文", "{{children:/guide}}", "- one\n- two\n",
|
|
"```python\nprint('hello')\n```", "[link](/path)\n\n",
|
|
"<p data-custom='keep'>raw HTML</p>",
|
|
"```{=html}\n<figure data-x='1'>source</figure>\n```",
|
|
} {
|
|
t.Run(source, func(t *testing.T) {
|
|
want := string(markdown.ToHTML([]byte(source), nil, nil))
|
|
if got := grammaratur.MarkdownToHTML(source); got != want {
|
|
t.Fatalf("dialect changed: %q want %q", got, want)
|
|
}
|
|
if got := render.Markdown(source); got != want {
|
|
t.Fatalf("render entry changed: %q want %q", got, want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLegacyHTMLAndAuthoringCompatibility(t *testing.T) {
|
|
for _, source := range []string{"", "<h1>Heading</h1>", "<p>{{children}}</p>", "<!--retain--><figure data-custom='keep'><figcaption>Caption</figcaption></figure>", "<script>never execute</script>"} {
|
|
want, err := htmltomarkdown.ConvertString(source)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, convert := range []func(string) (string, error){grammaratur.HTMLToMarkdown, compiler.HTMLToMarkdown} {
|
|
got, err := convert(source)
|
|
if err != nil || got != want {
|
|
t.Fatalf("ordinary conversion changed: %q %v", got, err)
|
|
}
|
|
}
|
|
protected, err := grammaratur.HTMLToMarkdownAuthoring(source)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
compat, err := compiler.HTMLToMarkdownAuthoring(source)
|
|
if err != nil || protected != compat {
|
|
t.Fatal("authoring facade changed", err)
|
|
}
|
|
if compiler.MarkdownAuthoringHTML(compat) != grammaratur.MarkdownAuthoringHTML(protected) {
|
|
t.Fatal("protected render facade changed")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAuthoringIsExplicitAndNotASanitizer(t *testing.T) {
|
|
const source = "```{=html}\n<script>untrusted()</script>\n```"
|
|
if strings.Contains(grammaratur.MarkdownToHTML(source), "<script>") {
|
|
t.Fatal("ordinary conversion opted into authoring")
|
|
}
|
|
if got := grammaratur.MarkdownAuthoringHTML(source); got != "<script>untrusted()</script>" {
|
|
t.Fatalf("authoring removed source: %q", got)
|
|
}
|
|
// Authorization, macro expansion and sanitization stay in the projection
|
|
// layer. Grammaratur returns source, not HTML trusted for a browser sink.
|
|
if got := grammaratur.MarkdownToHTML("{{children}}"); !strings.Contains(got, "{{children}}") {
|
|
t.Fatal("macro unexpectedly expanded")
|
|
}
|
|
}
|