chloe: ensure self-closing tags are self-closing
This gets us much closer to HTML5 compatibility, while not breaking the existing XHTML functionality. (Indeed, the entire reason this is necessary is that XHTML, being an XML derivative, treats `<foo></foo>` and `<foo />` equivalently, whereas HTML5 does not.)db4
parent
2f1b7bf9e1
commit
ed1ccc4448
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: assocs namespaces make kernel sequences accessors
|
USING: assocs namespaces make kernel sequences accessors
|
||||||
combinators strings splitting io io.streams.string present
|
combinators strings splitting io io.streams.string present
|
||||||
xml.writer xml.data xml.entities html.forms
|
sets ascii xml.writer xml.data xml.entities html.forms
|
||||||
html.templates html.templates.chloe.syntax ;
|
html.templates html.templates.chloe.syntax ;
|
||||||
IN: html.templates.chloe.compiler
|
IN: html.templates.chloe.compiler
|
||||||
|
|
||||||
|
@ -60,6 +60,11 @@ DEFER: compile-element
|
||||||
"\"" [write]
|
"\"" [write]
|
||||||
] assoc-each ;
|
] assoc-each ;
|
||||||
|
|
||||||
|
: compile-self-closing-tag ( tag -- )
|
||||||
|
"<" [write]
|
||||||
|
[ name>string [write] ] [ attrs>> compile-attrs ] bi
|
||||||
|
" />" [write] ;
|
||||||
|
|
||||||
: compile-start-tag ( tag -- )
|
: compile-start-tag ( tag -- )
|
||||||
"<" [write]
|
"<" [write]
|
||||||
[ name>string [write] ] [ attrs>> compile-attrs ] bi
|
[ name>string [write] ] [ attrs>> compile-attrs ] bi
|
||||||
|
@ -74,17 +79,38 @@ SYMBOL: string-context?
|
||||||
|
|
||||||
ERROR: tag-not-allowed-here ;
|
ERROR: tag-not-allowed-here ;
|
||||||
|
|
||||||
|
CONSTANT: self-closing-tags {
|
||||||
|
"area"
|
||||||
|
"base"
|
||||||
|
"br"
|
||||||
|
"embed"
|
||||||
|
"hr"
|
||||||
|
"iframe"
|
||||||
|
"img"
|
||||||
|
"input"
|
||||||
|
"link"
|
||||||
|
"meta"
|
||||||
|
"param"
|
||||||
|
"source"
|
||||||
|
"track"
|
||||||
|
}
|
||||||
|
|
||||||
: check-tag ( -- )
|
: check-tag ( -- )
|
||||||
string-context? get [ tag-not-allowed-here ] when ;
|
string-context? get [ tag-not-allowed-here ] when ;
|
||||||
|
|
||||||
: compile-tag ( tag -- )
|
: (compile-tag) ( tag -- )
|
||||||
check-tag
|
dup name>string >lower self-closing-tags in?
|
||||||
{
|
[ compile-self-closing-tag ]
|
||||||
[ main>> tag-stack get push ]
|
[
|
||||||
[ compile-start-tag ]
|
[ compile-start-tag ]
|
||||||
[ compile-children ]
|
[ compile-children ]
|
||||||
[ compile-end-tag ]
|
[ compile-end-tag ] tri
|
||||||
} cleave
|
] if ;
|
||||||
|
|
||||||
|
: compile-tag ( tag -- )
|
||||||
|
check-tag
|
||||||
|
[ main>> tag-stack get push ]
|
||||||
|
[ (compile-tag) ] bi
|
||||||
tag-stack get pop* ;
|
tag-stack get pop* ;
|
||||||
|
|
||||||
ERROR: unknown-chloe-tag tag ;
|
ERROR: unknown-chloe-tag tag ;
|
||||||
|
|
Loading…
Reference in New Issue