Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SVG element #314

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions parser/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var (
"output": {},
"progress": {},
"section": {},
"svg": {},
"video": {},
}
)
Expand Down
53 changes: 53 additions & 0 deletions parser/block_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package parser

import (
"bytes"
"testing"

"github.com/gomarkdown/markdown/ast"
)

// Inside HTML, no Markdown is parsed.
func TestHtmlP(t *testing.T) {
input := "<p>*not emph*</p>\n"
p := NewWithExtensions(CommonExtensions)
doc := p.Parse([]byte(input))
var buf bytes.Buffer
ast.Print(&buf, doc)
got := buf.String()
exp := "HTMLBlock '<p>*not emph*</p>'\n"
if got != exp {
t.Errorf("\nInput [%#v]\nExpected[%#v]\nGot [%#v]\n",
input, exp, got)
}
}

// Inside SVG, so the RECT element is passed through.
func TestSVG(t *testing.T) {
input := "<svg><rect> *no emph* </rect></svg>\n"
p := NewWithExtensions(CommonExtensions)
doc := p.Parse([]byte(input))
var buf bytes.Buffer
ast.Print(&buf, doc)
got := buf.String()
exp := "HTMLBlock '<svg><rect> *no emph* </rect></svg>'\n"
if got != exp {
t.Errorf("\nInput [%#v]\nExpected[%#v]\nGot [%#v]\n",
input, exp, got)
}
}

// The RECT element on its own is nothing special, so Markdown is parsed.
func TestRect(t *testing.T) {
input := "<rect> *emph* </rect>\n"
p := NewWithExtensions(CommonExtensions)
doc := p.Parse([]byte(input))
var buf bytes.Buffer
ast.Print(&buf, doc)
got := buf.String()
exp := "Paragraph\n Text\n HTMLSpan '<rect>'\n Text\n Emph\n Text 'emph'\n Text\n HTMLSpan '</rect>'\n"
if got != exp {
t.Errorf("\nInput [%#v]\nExpected[%#v]\nGot [%#v]\n",
input, exp, got)
}
}
Loading