Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.2 KB
Raw Blame
// SiYuan - https://github.com/siyuan-note/siyuan
// Copyright (c) 2020-present, b3log.org
// SPDX-License-Identifier: AGPL-3.0-or-later

package av

import (
	"testing"

	"github.com/88250/lute/html"
)

func TestValueTextRichEscapedContentRoundTrip(t *testing.T) {
	for _, mark := range []string{"em", "strong", "s", "mark", "sup", "sub", "u", "code", "kbd", "text", "a em"} {
		t.Run(mark, func(t *testing.T) {
			const content = `<vitae> & &lt; "quote"`
			value := &ValueText{Rich: &ValueTextRich{
				Spec: ValueTextRichSpec, Format: ValueTextRichFormatKramdown,
				Content: `<span data-type="` + mark + `" data-href="https://example.com">` + html.EscapeHTMLStr(content) + `</span>`,
			}}
			for i := range 3 {
				if err := value.NormalizeRichContent(); err != nil {
					t.Fatal(err)
				}
				if value.Content != content {
					t.Fatalf("round %d: want %q, got %q, source %q", i, content, value.Content, value.Rich.Content)
				}
			}
		})
	}
	value := &ValueText{Rich: &ValueTextRich{Spec: ValueTextRichSpec, Format: ValueTextRichFormatKramdown, Content: "*<vitae>*"}}
	if err := value.NormalizeRichContent(); err != nil || value.Content != "<vitae>" {
		t.Fatalf("Markdown content lost: %q, %v", value.Content, err)
	}
}