summaryrefslogtreecommitdiff
path: root/lib/TUWF
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2017-12-16 09:59:20 +0100
committerYorhel <git@yorhel.nl>2017-12-16 10:00:01 +0100
commit65d8669cbd8ecbe8149e2a0072e14a26b30149c3 (patch)
tree03ab9ab37e24e1d8543ace3c6ecaf1acf5abf4d3 /lib/TUWF
parent8fefd16c2b503e09730951258944c73ef14a2264 (diff)
TUWF::XML: Add HTML5 doctype and use it by default
This is kind-of a breaking change, but the HTML5 doctype is more compatible than xhtml1-strict. This change is a bit silly when everything else in TUWF::XML is still built for XHTML rather than HTML5, but I'll add some proper HTML5 support in a bit.
Diffstat (limited to 'lib/TUWF')
-rw-r--r--lib/TUWF/XML.pm17
-rw-r--r--lib/TUWF/XML.pod8
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/TUWF/XML.pm b/lib/TUWF/XML.pm
index d15b8e9..d988fc7 100644
--- a/lib/TUWF/XML.pm
+++ b/lib/TUWF/XML.pm
@@ -48,7 +48,7 @@ BEGIN {
};
-# the common XHTML doctypes, from http://www.w3.org/QA/2002/04/valid-dtd-list.html
+# the common (X)HTML doctypes, from http://www.w3.org/QA/2002/04/valid-dtd-list.html
my %doctypes = split /\r?\n/, <<__;
xhtml1-strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -62,6 +62,8 @@ xhtml-basic11
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
xhtml-math-svg
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
+html5
+<!DOCTYPE html>
__
@@ -170,11 +172,18 @@ sub html {
my $c = $hascontent && pop;
my %o = @_;
- $s->lit($doctypes{ delete($o{doctype}) || 'xhtml1-strict' }."\n");
+ my $doctype = delete $o{doctype} || 'html5';
+
+ $s->lit($doctypes{$doctype}."\n");
my $lang = delete $o{lang};
$s->tag('html',
- xmlns => 'http://www.w3.org/1999/xhtml',
- $lang ? ('xml:lang' => $lang, lang => $lang) : (),
+ # html5 has no 'xmlns' or 'xml:lang'
+ $doctype eq 'html5' ? (
+ $lang ? (lang => $lang) : (),
+ ) : (
+ xmlns => 'http://www.w3.org/1999/xhtml',
+ $lang ? ('xml:lang' => $lang, lang => $lang) : (),
+ ),
%o,
$hascontent ? ($c) : ()
);
diff --git a/lib/TUWF/XML.pod b/lib/TUWF/XML.pod
index 2382723..e861d28 100644
--- a/lib/TUWF/XML.pod
+++ b/lib/TUWF/XML.pod
@@ -143,7 +143,7 @@ Since this function does not open a tag, it does not have to be C<end()>'ed.
=head2 html(options)
-Writes an XHTML doctype and opens an C<E<lt>htmlE<gt>> tag. Accepts the
+Writes an (X)HTML doctype and opens an C<E<lt>htmlE<gt>> tag. Accepts the
following options:
=over
@@ -153,15 +153,15 @@ following options:
Specify the doctype to use. Can be one of the following:
xhtml1-strict xhtml1-transitional xhtml1-frameset
- xhtml11 xhtml-basic11 xhtml-math-svg
+ xhtml11 xhtml-basic11 xhtml-math-svg html5
These refer to the doctypes found at
-L<http://www.w3.org/QA/2002/04/valid-dtd-list.html>. Default: xhtml1-strict.
+L<http://www.w3.org/QA/2002/04/valid-dtd-list.html>. Default: html5.
=item lang
Specifies the (human) language of the generated content. This will generate a
-C<lang> and C<xml:lang> attribute for the html open tag.
+C<lang> (and C<xml:lang> for XHTML) attribute for the html open tag.
=item I<anything else>