Skip to content

Commit

Permalink
Add SVG element
Browse files Browse the repository at this point in the history
SVG is now part of HTML 5 and the SVG element a valid top-level
element. The other SVG element, however, do not stand on their own.
https://html.spec.whatwg.org/dev/embedded-content-other.html#svg-0

Note: This does not match up with the definition of CommonMark HTML
blocks. CommonMark does not recognize the SVG element as a HTML block.
In this respect, however, it would seem that CommonMark is lagging
behind. https://spec.commonmark.org/0.31.2/#html-blocks
  • Loading branch information
kensanata authored and kjk committed Jul 30, 2024
1 parent 0acb1f1 commit 034f12a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
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)
}
}

0 comments on commit 034f12a

Please sign in to comment.