CONTRIBUTING 000664 001750 001750 6146 12405057420 15016 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 NAME
CONTRIBUTING
DESCRIPTION
If you're reading this document, that means you might be thinking about
helping me out with this project. Thanks!
Here's some ways you could help out:
* Bug reports
Found a bug? Great! (Well, not so great I suppose.)
The place to report them is . Don't e-mail me
about it, as your e-mail is more than likely to get lost amongst the
spam.
An example script clearly demonstrating the bug (preferably written
using Test::More) would be greatly appreciated.
* Patches
If you've found a bug and written a fix for it, even better!
Generally speaking you should check out the latest copy of the code
from the source repository rather than using the CPAN distribution.
The file META.yml should contain a link to the source repository. If
not, then try or submit a bug report.
(As far as I'm concerned the lack of a link is a bug.) Many of my
distributions are also mirrored at .
To submit the patch, do a pull request on GitHub or Bitbucket, or
attach a diff file to a bug report. Unless otherwise stated, I'll
assume that your contributions are licensed under the same terms as
the rest of the project.
(If using git, feel free to work in a branch. For Mercurial, I'd
prefer bookmarks within the default branch.)
* Documentation
If there's anything unclear in the documentation, please submit this
as a bug report or patch as above.
Non-toy example scripts that I can bundle would also be appreciated.
* Translation
Translations of documentation would be welcome.
For translations of error messages and other strings embedded in the
code, check with me first. Sometimes the English strings may not in
a stable state, so it would be a waste of time translating them.
Coding Style
I tend to write using something approximating the Allman style, using
tabs for indentation and Unix-style line breaks.
*
*
I nominally encode all source files as UTF-8, though in practice most of
them use a 7-bit-safe ASCII-compatible subset of UTF-8.
AUTHOR
Toby Inkster .
COPYRIGHT AND LICENCE
Copyright (c) 2012-2014 by Toby Inkster.
CONTRIBUTING is available under three different licences permitting its
redistribution: the CC-BY-SA_UK-2.0 licence, plus the same licences as
Perl itself, which is distributed under the GNU General Public Licence
version 1, and the Artistic Licence.
This file is licensed under the Creative Commons Attribution-ShareAlike
2.0 UK: England & Wales License. To view a copy of this license, visit
.
This file is free software; you can redistribute it and/or modify it
under the same terms as the Perl 5 programming language system itself.
COPYRIGHT 000664 001750 001750 2266 12405057420 14456 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: HTML-HTML5-Sanity
Upstream-Contact: TOBYINK and Toby Inkster
Source: https://metacpan.org/release/HTML-HTML5-Sanity
Files: Changes
META.json
META.yml
dist.ini
doap.ttl
Copyright: Copyright 2014 Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
Files: COPYRIGHT
CREDITS
SIGNATURE
Copyright: None
License: public-domain
Files: CONTRIBUTING
INSTALL
LICENSE
Copyright: Unknown
License: Unknown
Files: README
lib/HTML/HTML5/Sanity.pm
Copyright: Copyright (C) 2009-2014 by Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
Files: t/01basics.t
t/02languages.t
Copyright: Copyright 2011 Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
Files: Makefile.PL
Copyright: Copyright 2013 Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
License: Artistic-1.0
This software is Copyright (c) 2014 by the copyright holder(s).
This is free software, licensed under:
The Artistic License 1.0
License: GPL-1.0
This software is Copyright (c) 2014 by the copyright holder(s).
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
CREDITS 000664 001750 001750 114 12405057416 14156 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 Maintainer:
- TOBYINK
- Toby Inkster
Changes 000664 001750 001750 3020 12405057416 14450 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 HTML-HTML5-Sanity
=================
Created: 2009-11-30
Home page:
Bug tracker:
Maintainer: Toby Inkster
0.105 2014-09-13
[ Packaging ]
- Fix dependency metadata (still included Object::AUTHORITY).
- Switch to Dist::Inkt.
[ Other ]
- Minor tidying.
0.104 2013-05-13
[ Packaging ]
- Newer version of build system; avoid bundling ancient Scalar::Util.
[ Other ]
- Removed: Object::AUTHORITY
0.103 2011-12-08
[ Packaging ]
- Update test cases to cope with changes to XML::LibXML::Debugging.
[ Other ]
- Updated: use Object::AUTHORITY
0.102 2011-10-20
[ Packaging ]
- Module::Package::RDF.
[ Other ]
- Updated: use 5.010.
0.101 2011-01-20
- Removed: No longer make fix_element and fix_attribute functions
exportable. They're fairly obscure and pretty confusing to use.
- Removed: No longer rely on HTML::Entities.
0.100 2010-06-23
- Removed: Remove deprecated debugging functions.
0.04 2010-04-28
- Split out XML-LibXML-Debugging.
0.03 2010-01-08
[ Bug Fixes ]
- Mention HTML::Entities dependency in Makefile.PL.
[ Other ]
- Updated: Add 2010 copyright notice.
- Updated: Use Turtle for Changes file.
0.02 2009-12-23
- Added: Handling for invalid language attributes.
- Improve tests.
- Updated: Update build system; sign distribution.
0.01 2009-12-03
INSTALL 000664 001750 001750 1726 12405057415 14220 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 Installing HTML-HTML5-Sanity should be straightforward.
INSTALLATION WITH CPANMINUS
If you have cpanm, you only need one line:
% cpanm HTML::HTML5::Sanity
If you are installing into a system-wide directory, you may need to pass
the "-S" flag to cpanm, which uses sudo to install the module:
% cpanm -S HTML::HTML5::Sanity
INSTALLATION WITH THE CPAN SHELL
Alternatively, if your CPAN shell is set up, you should just be able to
do:
% cpan HTML::HTML5::Sanity
MANUAL INSTALLATION
As a last resort, you can manually install it. Download the tarball and
unpack it.
Consult the file META.json for a list of pre-requisites. Install these
first.
To build HTML-HTML5-Sanity:
% perl Makefile.PL
% make && make test
Then install it:
% make install
If you are installing into a system-wide directory, you may need to run:
% sudo make install
LICENSE 000664 001750 001750 43655 12405057415 14223 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 This software is copyright (c) 2014 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Terms of the Perl programming language system itself
a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
This software is Copyright (c) 2014 by Toby Inkster.
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
GNU GENERAL PUBLIC LICENSE
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications. Each
licensee is addressed as "you".
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program. You may charge a fee for the physical act of
transferring a copy.
2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:
a) cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.
8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
Copyright (C) 19yy
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
That's all there is to it!
--- The Artistic License 1.0 ---
This software is Copyright (c) 2014 by Toby Inkster.
This is free software, licensed under:
The Artistic License 1.0
The Artistic License
Preamble
The intent of this document is to state the conditions under which a Package
may be copied, such that the Copyright Holder maintains some semblance of
artistic control over the development of the package, while giving the users of
the package the right to use and distribute the Package in a more-or-less
customary fashion, plus the right to make reasonable modifications.
Definitions:
- "Package" refers to the collection of files distributed by the Copyright
Holder, and derivatives of that collection of files created through
textual modification.
- "Standard Version" refers to such a Package if it has not been modified,
or has been modified in accordance with the wishes of the Copyright
Holder.
- "Copyright Holder" is whoever is named in the copyright or copyrights for
the package.
- "You" is you, if you're thinking about copying or distributing this Package.
- "Reasonable copying fee" is whatever you can justify on the basis of media
cost, duplication charges, time of people involved, and so on. (You will
not be required to justify it to the Copyright Holder, but only to the
computing community at large as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item itself, though
there may be fees involved in handling the item. It also means that
recipients of the item may redistribute it under the same conditions they
received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications derived
from the Public Domain or from the Copyright Holder. A Package modified in such
a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided that
you insert a prominent notice in each changed file stating how and when you
changed that file, and provided that you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or an
equivalent medium, or placing the modifications on a major archive site
such as ftp.uu.net, or by allowing the Copyright Holder to include your
modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict with
standard executables, which must also be provided, and provide a separate
manual page for each non-standard executable that clearly documents how it
differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where to
get the Standard Version.
b) accompany the distribution with the machine-readable source of the Package
with your modifications.
c) accompany any non-standard executables with their corresponding Standard
Version executables, giving the non-standard executables non-standard
names, and clearly documenting the differences in manual pages (or
equivalent), together with instructions on where to get the Standard
Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this Package. You
may not charge a fee for this Package itself. However, you may distribute this
Package in aggregate with other (possibly commercial) programs as part of a
larger (possibly commercial) software distribution provided that you do not
advertise this Package as a product of your own.
6. The scripts and library files supplied as input to or produced as output
from the programs of this Package do not automatically fall under the copyright
of this Package, but belong to whomever generated them, and may be sold
commercially, and may be aggregated with this Package.
7. C or perl subroutines supplied by you and linked into this Package shall not
be considered part of this Package.
8. The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written permission.
9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End
MANIFEST 000664 001750 001750 270 12405057420 14265 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 CONTRIBUTING
COPYRIGHT
CREDITS
Changes
INSTALL
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
SIGNATURE
dist.ini
doap.ttl
lib/HTML/HTML5/Sanity.pm
t/01basics.t
t/02languages.t
META.json 000664 001750 001750 4016 12405057420 14577 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 {
"abstract" : "make HTML5 DOM trees less insane",
"author" : [
"Toby Inkster ",
"TOBYINK "
],
"dynamic_config" : 0,
"generated_by" : "Dist::Inkt::Profile::TOBYINK version 0.016, CPAN::Meta::Converter version 2.140640",
"keywords" : [
"Attributes",
"DOM",
"Fix",
"Fixer",
"HTML",
"HTML5",
"Lang",
"Language",
"Markup",
"Namespaces",
"XML"
],
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "HTML-HTML5-Sanity",
"no_index" : {
"directory" : [
"eg",
"examples",
"inc",
"t",
"xt"
]
},
"optional_features" : {},
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "6.17"
}
},
"runtime" : {
"recommends" : {
"HTML::HTML5::Parser" : "0.107"
},
"requires" : {
"Locale::Country" : "0",
"XML::LibXML" : "1.70"
}
},
"test" : {
"requires" : {
"Test::More" : "0.61",
"XML::LibXML::Debugging" : "0"
}
}
},
"provides" : {
"HTML::HTML5::Sanity" : {
"file" : "lib/HTML/HTML5/Sanity.pm",
"version" : "0.105"
}
},
"release_status" : "stable",
"resources" : {
"X_identifier" : "http://purl.org/NET/cpan-uri/dist/HTML-HTML5-Sanity/project",
"bugtracker" : {
"web" : "http://rt.cpan.org/Dist/Display.html?Queue=HTML-HTML5-Sanity"
},
"homepage" : "https://metacpan.org/release/HTML-HTML5-Sanity",
"license" : [
"http://dev.perl.org/licenses/"
],
"repository" : {
"type" : "git",
"url" : "git://github.com/tobyink/p5-html-html5-sanity.git",
"web" : "https://github.com/tobyink/p5-html-html5-sanity"
}
},
"version" : "0.105"
}
META.yml 000664 001750 001750 2333 12405057420 14427 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 ---
abstract: 'make HTML5 DOM trees less insane'
author:
- 'Toby Inkster '
- 'TOBYINK '
build_requires:
Test::More: '0.61'
XML::LibXML::Debugging: '0'
configure_requires:
ExtUtils::MakeMaker: '6.17'
dynamic_config: 0
generated_by: 'Dist::Inkt::Profile::TOBYINK version 0.016, CPAN::Meta::Converter version 2.140640'
keywords:
- Attributes
- DOM
- Fix
- Fixer
- HTML
- HTML5
- Lang
- Language
- Markup
- Namespaces
- XML
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: HTML-HTML5-Sanity
no_index:
directory:
- eg
- examples
- inc
- t
- xt
optional_features: {}
provides:
HTML::HTML5::Sanity:
file: lib/HTML/HTML5/Sanity.pm
version: '0.105'
recommends:
HTML::HTML5::Parser: '0.107'
requires:
Locale::Country: '0'
XML::LibXML: '1.70'
resources:
X_identifier: http://purl.org/NET/cpan-uri/dist/HTML-HTML5-Sanity/project
bugtracker: http://rt.cpan.org/Dist/Display.html?Queue=HTML-HTML5-Sanity
homepage: https://metacpan.org/release/HTML-HTML5-Sanity
license: http://dev.perl.org/licenses/
repository: git://github.com/tobyink/p5-html-html5-sanity.git
version: '0.105'
Makefile.PL 000664 001750 001750 12614 12405057420 15153 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 use strict;
use ExtUtils::MakeMaker 6.17;
my $EUMM = eval( $ExtUtils::MakeMaker::VERSION );
my $meta = {
"abstract" => "make HTML5 DOM trees less insane",
"author" => [
"Toby Inkster ",
"TOBYINK ",
],
"dynamic_config" => 0,
"generated_by" => "Dist::Inkt::Profile::TOBYINK version 0.016, CPAN::Meta::Converter version 2.140640",
"keywords" => [
"Attributes",
"DOM",
"Fix",
"Fixer",
"HTML",
"HTML5",
"Lang",
"Language",
"Markup",
"Namespaces",
"XML",
],
"license" => ["perl_5"],
"meta-spec" => {
url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
version => 2,
},
"name" => "HTML-HTML5-Sanity",
"no_index" => { directory => ["eg", "examples", "inc", "t", "xt"] },
"prereqs" => {
configure => { requires => { "ExtUtils::MakeMaker" => 6.17 } },
runtime => {
recommends => { "HTML::HTML5::Parser" => 0.107 },
requires => { "Locale::Country" => 0, "XML::LibXML" => "1.70" },
},
test => {
requires => { "Test::More" => 0.61, "XML::LibXML::Debugging" => 0 },
},
},
"provides" => {
"HTML::HTML5::Sanity" => { file => "lib/HTML/HTML5/Sanity.pm", version => 0.105 },
},
"release_status" => "stable",
"resources" => {
bugtracker => {
web => "http://rt.cpan.org/Dist/Display.html?Queue=HTML-HTML5-Sanity",
},
homepage => "https://metacpan.org/release/HTML-HTML5-Sanity",
license => ["http://dev.perl.org/licenses/"],
repository => {
type => "git",
url => "git://github.com/tobyink/p5-html-html5-sanity.git",
web => "https://github.com/tobyink/p5-html-html5-sanity",
},
X_identifier => "http://purl.org/NET/cpan-uri/dist/HTML-HTML5-Sanity/project",
},
"version" => 0.105,
};
my %dynamic_config;
my %WriteMakefileArgs = (
ABSTRACT => $meta->{abstract},
AUTHOR => ($EUMM >= 6.5702 ? $meta->{author} : $meta->{author}[0]),
DISTNAME => $meta->{name},
VERSION => $meta->{version},
EXE_FILES => [ map $_->{file}, values %{ $meta->{x_provides_scripts} || {} } ],
NAME => do { my $n = $meta->{name}; $n =~ s/-/::/g; $n },
test => { TESTS => "t/*.t" },
%dynamic_config,
);
$WriteMakefileArgs{LICENSE} = $meta->{license}[0] if $EUMM >= 6.3001;
sub deps
{
my %r;
for my $stage (@_)
{
for my $dep (keys %{$meta->{prereqs}{$stage}{requires}})
{
next if $dep eq 'perl';
my $ver = $meta->{prereqs}{$stage}{requires}{$dep};
$r{$dep} = $ver if !exists($r{$dep}) || $ver >= $r{$dep};
}
}
\%r;
}
my ($build_requires, $configure_requires, $runtime_requires, $test_requires);
if ($EUMM >= 6.6303)
{
$WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build');
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{TEST_REQUIRES} ||= deps('test');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime');
}
elsif ($EUMM >= 6.5503)
{
$WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build', 'test');
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime');
}
elsif ($EUMM >= 6.52)
{
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime', 'build', 'test');
}
else
{
$WriteMakefileArgs{PREREQ_PM} ||= deps('configure', 'build', 'test', 'runtime');
}
{
my ($minperl) = reverse sort(
grep defined && /^[0-9]+(\.[0-9]+)?$/,
map $meta->{prereqs}{$_}{requires}{perl},
qw( configure build runtime )
);
if (defined($minperl))
{
die "Installing $meta->{name} requires Perl >= $minperl"
unless $] >= $minperl;
$WriteMakefileArgs{MIN_PERL_VERSION} ||= $minperl
if $EUMM >= 6.48;
}
}
sub FixMakefile
{
return unless -d 'inc';
my $file = shift;
local *MAKEFILE;
open MAKEFILE, "< $file" or die "FixMakefile: Couldn't open $file: $!; bailing out";
my $makefile = do { local $/; };
close MAKEFILE or die $!;
$makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
$makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
$makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
$makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
$makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;
open MAKEFILE, "> $file" or die "FixMakefile: Couldn't open $file: $!; bailing out";
print MAKEFILE $makefile or die $!;
close MAKEFILE or die $!;
}
my $mm = WriteMakefile(%WriteMakefileArgs);
FixMakefile($mm->{FIRST_MAKEFILE} || 'Makefile');
exit(0);
README 000664 001750 001750 4421 12405057415 14042 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 NAME
HTML::HTML5::Sanity - make HTML5 DOM trees less insane
SYNOPSIS
use HTML::HTML5::Parser;
use HTML::HTML5::Sanity;
my $parser = HTML::HTML5::Parser->new;
my $html5_dom = $parser->parse_file('http://example.com/');
my $sane_dom = fix_document($html5_dom);
DESCRIPTION
The Document Object Model (DOM) generated by HTML::HTML5::Parser meets the
requirements of the HTML5 spec, but will probably catch a lot of people by
surprise.
The main oddity is that elements and attributes which appear to be
namespaced are not really. For example, the following element:
...
Looks like it should be parsed so that it has an attribute "lang" in the
XML namespace. Not so. It will really be parsed as having the attribute
"xml:lang" in the null namespace.
`fix_document($document)`
$sane_dom = fix_document($html5_dom);
Returns a modified copy of the DOM and leaving the original DOM
unmodified.
`fix_element($element_node, $new_document_node, \%namespaces)`
Don't use this. Not exported.
`fix_attribute($attribute_node, $new_element_node, \%namespaces)`
Don't use this. Not exported.
$HTML::HTML5::Sanity::FIX_LANG_ATTRIBUTES
$HTML::HTML5::Sanity::FIX_LANG_ATTRIBUTES = 2;
$sane_dom = fix_document($html5_dom);
If set to 1 (the default), the package will detect invalid values in
@lang and @xml:lang, and remove the attribute if it is invalid. If set
to 2, it will also attempt to canonicalise the value (e.g. 'EN_GB'
will be converted to to 'en-GB'). If set to 0, then the value of
language attributes is not checked.
BUGS
Please report any bugs to .
SEE ALSO
HTML::HTML5::Parser, XML::LibXML, Task::HTML5.
AUTHOR
Toby Inkster .
COPYRIGHT AND LICENSE
Copyright (C) 2009-2014 by Toby Inkster
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
SIGNATURE 000664 001750 001750 3131 12405057421 14440 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 This file contains message digests of all files listed in MANIFEST,
signed via the Module::Signature module, version 0.73.
To verify the content in this distribution, first make sure you have
Module::Signature installed, then type:
% cpansign -v
It will check each file's integrity, as well as the signature's
validity. If "==> Signature verified OK! <==" is not displayed,
the distribution may already have been compromised, and you should
not run its Makefile.PL or Build.PL.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
SHA1 33317486c4fa2cf7fec85bf92ed38ac0f64233a0 CONTRIBUTING
SHA1 48e7d0344323e837f366f7bef359bfbb101c2a90 COPYRIGHT
SHA1 540e627824058dc4b3f75009923f7af8f8e388c8 CREDITS
SHA1 cea4312b3e2d6f03ab3a3d7fbdd073a7462bc684 Changes
SHA1 3fcf84535a4fb22c0d6a61934a29612801fc8464 INSTALL
SHA1 34f5e12514b91055de4b164a1f2327ef5c30ba53 LICENSE
SHA1 362845086a348226d03aab90a0ccba69cb12afa1 MANIFEST
SHA1 7da2cf3530f98d62f671d3253f279cb739e33832 META.json
SHA1 ea460dc144b90ffd8986901d4cd6a65079760e70 META.yml
SHA1 4a34b9ddbe9c3bfa20e7acefdb86205b61b5567a Makefile.PL
SHA1 45be1a5ad5b72d6dd909830cf2e367ac6e51964d README
SHA1 039c8655f6acc8af4668c8365b99edac29aa46a6 dist.ini
SHA1 da3a87125327c68a90ad3f47f88781b0f7c10dc8 doap.ttl
SHA1 d513f9abbc0281094495b113beea09becd764c50 lib/HTML/HTML5/Sanity.pm
SHA1 62cbb5e8e40b175d5b1c4cc7906d8f15db389e2d t/01basics.t
SHA1 2df75c1185c7f659fd4a9b8e548f9b5835cb7b8b t/02languages.t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iEYEARECAAYFAlQUXxEACgkQzr+BKGoqfTma0wCePGMxQaO21bxj5F08RbcMZTVu
cVUAnimANhknBsHh2P93xqYrJMzrecYD
=mqTX
-----END PGP SIGNATURE-----
dist.ini 000664 001750 001750 102 12405057415 14576 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 ;;class='Dist::Inkt::Profile::TOBYINK'
;;name='HTML-HTML5-Sanity'
doap.ttl 000664 001750 001750 22640 12405057420 14651 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105 @prefix dc: .
@prefix doap: .
@prefix doap-changeset: .
@prefix doap-deps: .
@prefix foaf: .
@prefix owl: .
@prefix rdfs: .
@prefix xsd: .
a doap:Project;
dc:contributor ;
doap-deps:runtime-recommendation [
doap-deps:on "HTML::HTML5::Parser 0.107"^^doap-deps:CpanId;
];
doap-deps:runtime-requirement [ doap-deps:on "XML::LibXML 1.70"^^doap-deps:CpanId ], [ doap-deps:on "Locale::Country"^^doap-deps:CpanId ];
doap-deps:test-requirement [ doap-deps:on "Test::More 0.61"^^doap-deps:CpanId ], [
doap-deps:on "XML::LibXML::Debugging"^^doap-deps:CpanId;
];
doap:bug-database ;
doap:category [ rdfs:label "Namespaces" ], [ rdfs:label "XML" ], [ rdfs:label "DOM" ], [ rdfs:label "Lang" ], [ rdfs:label "Language" ], [ rdfs:label "HTML" ], [ rdfs:label "HTML5" ], [ rdfs:label "Markup" ], [ rdfs:label "Fixer" ], [ rdfs:label "Fix" ], [ rdfs:label "Attributes" ];
doap:created "2009-11-30"^^xsd:date;
doap:developer ;
doap:documenter ;
doap:download-page ;
doap:homepage ;
doap:license ;
doap:maintainer ;
doap:name "HTML-HTML5-Sanity";
doap:programming-language "Perl";
doap:release , , , , , , , , , ;
doap:repository [
a doap:GitRepository;
doap:browse ;
];
doap:shortdesc "make HTML5 DOM trees less insane"@en;
doap:tester .
a doap:Version;
dc:issued "2009-12-03"^^xsd:date;
doap:file-release ;
doap:revision "0.01"^^xsd:string;
rdfs:comment "Original version"@en.
a doap:Version;
dc:issued "2009-12-23"^^xsd:date;
doap-changeset:changeset [
a doap-changeset:ChangeSet;
doap-changeset:item [
a doap-changeset:Update;
rdfs:label "Update build system; sign distribution."@en;
rdfs:seeAlso ;
], [
a doap-changeset:Addition;
rdfs:label "Handling for invalid language attributes."@en;
], [
a doap-changeset:Change;
rdfs:label "Improve tests."@en;
];
doap-changeset:versus ;
];
doap:file-release ;
doap:revision "0.02"^^xsd:string.
a doap:Version;
dc:issued "2010-01-08"^^xsd:date;
doap-changeset:changeset [
a doap-changeset:ChangeSet;
doap-changeset:item [
a doap-changeset:Bugfix;
rdfs:label "Mention HTML::Entities dependency in Makefile.PL."@en;
doap-changeset:fixes [
rdfs:seeAlso ;
];
], [
a doap-changeset:Update;
rdfs:label "Use Turtle for Changes file."@en;
doap-changeset:file ;
doap-changeset:implements ;
], [
a doap-changeset:Update;
rdfs:label "Add 2010 copyright notice."@en;
];
doap-changeset:versus ;
];
doap:file-release ;
doap:revision "0.03"^^xsd:string.
a doap:Version;
dc:issued "2010-04-28"^^xsd:date;
doap-changeset:changeset [
a doap-changeset:ChangeSet;
doap-changeset:item [ rdfs:label "Split out XML-LibXML-Debugging."@en ];
doap-changeset:versus ;
];
doap:file-release ;
doap:revision "0.04"^^xsd:string.
a doap:Version;
dc:issued "2010-06-23"^^xsd:date;
doap-changeset:changeset [
a doap-changeset:ChangeSet;
doap-changeset:item [
a doap-changeset:Removal;
rdfs:label "Remove deprecated debugging functions."@en;
];
doap-changeset:versus ;
];
doap:file-release ;
doap:revision "0.100"^^xsd:string.
a doap:Version;
dc:issued "2011-01-20"^^xsd:date;
doap-changeset:changeset [
a doap-changeset:ChangeSet;
doap-changeset:item [
a doap-changeset:Removal;
rdfs:label "No longer rely on HTML::Entities."@en;
], [
a doap-changeset:Removal;
rdfs:label "No longer make fix_element and fix_attribute functions exportable. They're fairly obscure and pretty confusing to use."@en;
];
doap-changeset:versus ;
];
doap:file-release ;
doap:revision "0.101"^^xsd:string.
a doap:Version;
dc:issued "2011-10-20"^^xsd:date;
doap-changeset:changeset [
a doap-changeset:ChangeSet;
doap-changeset:item [
a doap-changeset:Update;
rdfs:label "use 5.010."@en;
], [
a doap-changeset:Packaging;
rdfs:label "Module::Package::RDF."@en;
];
doap-changeset:versus ;
];
doap:file-release ;
doap:revision "0.102"^^xsd:string.
a doap:Version;
dc:issued "2011-12-08"^^xsd:date;
doap-changeset:changeset [
a doap-changeset:ChangeSet;
doap-changeset:item [
a doap-changeset:Update;
rdfs:label "use Object::AUTHORITY"@en;
], [
a doap-changeset:Packaging;
rdfs:label "Update test cases to cope with changes to XML::LibXML::Debugging."@en;
];
doap-changeset:versus ;
];
doap:file-release ;
doap:revision "0.103"^^xsd:string.
a doap:Version;
dc:issued "2013-05-13"^^xsd:date;
doap-changeset:changeset [
a doap-changeset:ChangeSet;
doap-changeset:item [
a doap-changeset:Removal;
rdfs:label "Object::AUTHORITY"@en;
], [
a doap-changeset:Packaging;
rdfs:label "Newer version of build system; avoid bundling ancient Scalar::Util."@en;
];
doap-changeset:versus ;
];
doap:file-release ;
doap:revision "0.104"^^xsd:string.
a doap:Version;
dc:identifier "HTML-HTML5-Sanity-0.105"^^xsd:string;
dc:issued "2014-09-13"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Packaging;
rdfs:label "Switch to Dist::Inkt.";
], [
a doap-changeset:Packaging;
rdfs:label "Fix dependency metadata (still included Object::AUTHORITY).";
], [
a doap-changeset:Change;
rdfs:label "Minor tidying.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.105"^^xsd:string.
a foaf:Person;
foaf:homepage ;
foaf:mbox ;
foaf:name "Toby Inkster";
foaf:page ;
owl:sameAs .
01basics.t 000664 001750 001750 1300 12405057415 15210 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105/t use Test::More tests => 3;
BEGIN { use_ok('HTML::HTML5::Sanity') };
use XML::LibXML::Debugging;
my $doc = XML::LibXML::Document->new;
my $root = $doc->createElementNS('http://www.w3.org/1999/xhtml', 'html');
$doc->setDocumentElement($root);
$root->setAttribute('xml:lang', 'en-gb-oed');
$root->setAttribute('lang', 'en-tobyinkster');
my $fixed = fix_document($doc);
ok(
!$fixed->documentElement->hasAttributeNS(undef, 'lang'),
"Invalid language attribute removed.",
);
is(
lc $fixed->toClarkML,
lc '<{http://www.w3.org/1999/xhtml}html {http://www.w3.org/XML/1998/namespace}lang="en-gb-oed" {http://www.w3.org/2000/xmlns/}XMLNS="http://www.w3.org/1999/xhtml"/>',
"Things seem to be working."); 02languages.t 000664 001750 001750 2104 12405057415 15716 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105/t use Test::More tests => 10;
BEGIN { use_ok('HTML::HTML5::Sanity') };
ok(
HTML::HTML5::Sanity::_valid_lang('EN-LATN-GB'),
'Simple language validity check.',
);
ok(
HTML::HTML5::Sanity::_valid_lang('en-latn-gb-x-tobyink'),
'More complex language validity check.',
);
ok(
!HTML::HTML5::Sanity::_valid_lang('en-tobyinkster'),
'Language validity function fails invalid languages',
);
is(
HTML::HTML5::Sanity::_canon_lang('EN-LATN-GB'),
'en-Latn-GB',
'Case handling of languages is good.',
);
is(
HTML::HTML5::Sanity::_canon_lang('eng'),
'en',
'Correction of 3 character codes to 2 character codes works.',
);
is(
HTML::HTML5::Sanity::_canon_lang('en-uk'),
'en-GB',
'Obsolete/special country codes are corrected.',
);
is(
HTML::HTML5::Sanity::_canon_lang('en-826'),
'en-GB',
'Numeric country codes are swapped.',
);
is(
HTML::HTML5::Sanity::_canon_lang('es-419'),
'es-419',
'Numeric country codes are not swapped when they can\'t be.',
);
is(
HTML::HTML5::Sanity::_canon_lang('i-klingon'),
'tlh',
'Grandfathered tags are replaced with preferred tags.',
);
Sanity.pm 000664 001750 001750 40277 12405057415 17163 0 ustar 00tai tai 000000 000000 HTML-HTML5-Sanity-0.105/lib/HTML/HTML5 use 5.010;
use strict;
use warnings;
package HTML::HTML5::Sanity;
BEGIN {
$HTML::HTML5::Sanity::AUTHORITY = 'cpan:TOBYINK';
$HTML::HTML5::Sanity::VERSION = '0.105';
}
require Exporter;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = (
'all' => [ qw(fix_document) ],
'standard' => [ qw(fix_document) ],
);
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = ( @{ $EXPORT_TAGS{'standard'} } );
our $FIX_LANG_ATTRIBUTES = 1;
use Locale::Country qw(country_code2code LOCALE_CODE_ALPHA_2 LOCALE_CODE_NUMERIC);
use XML::LibXML qw(:ns :libxml);
our $lang_3to2 = {
'aar' => 'aa' ,
'abk' => 'ab' ,
'ave' => 'ae' ,
'afr' => 'af' ,
'aka' => 'ak' ,
'amh' => 'am' ,
'arg' => 'an' ,
'ara' => 'ar' ,
'asm' => 'as' ,
'ava' => 'av' ,
'aym' => 'ay' ,
'aze' => 'az' ,
'bak' => 'ba' ,
'bel' => 'be' ,
'bul' => 'bg' ,
'bih' => 'bh' ,
'bis' => 'bi' ,
'bam' => 'bm' ,
'ben' => 'bn' ,
'tib' => 'bo' ,
'bod' => 'bo' ,
'bre' => 'br' ,
'bos' => 'bs' ,
'cat' => 'ca' ,
'che' => 'ce' ,
'cha' => 'ch' ,
'cos' => 'co' ,
'cre' => 'cr' ,
'cze' => 'cs' ,
'ces' => 'cs' ,
'chu' => 'cu' ,
'chv' => 'cv' ,
'wel' => 'cy' ,
'cym' => 'cy' ,
'dan' => 'da' ,
'ger' => 'de' ,
'deu' => 'de' ,
'div' => 'dv' ,
'dzo' => 'dz' ,
'ewe' => 'ee' ,
'gre' => 'el' ,
'ell' => 'el' ,
'eng' => 'en' ,
'epo' => 'eo' ,
'spa' => 'es' ,
'est' => 'et' ,
'baq' => 'eu' ,
'eus' => 'eu' ,
'per' => 'fa' ,
'fas' => 'fa' ,
'ful' => 'ff' ,
'fin' => 'fi' ,
'fij' => 'fj' ,
'fao' => 'fo' ,
'fre' => 'fr' ,
'fra' => 'fr' ,
'fry' => 'fy' ,
'gle' => 'ga' ,
'gla' => 'gd' ,
'glg' => 'gl' ,
'grn' => 'gn' ,
'guj' => 'gu' ,
'glv' => 'gv' ,
'hau' => 'ha' ,
'heb' => 'he' ,
'hin' => 'hi' ,
'hmo' => 'ho' ,
'hrv' => 'hr' ,
'hat' => 'ht' ,
'hat' => 'ht' ,
'hun' => 'hu' ,
'arm' => 'hy' ,
'hye' => 'hy' ,
'her' => 'hz' ,
'ina' => 'ia' ,
'ind' => 'id' ,
'ile' => 'ie' ,
'ibo' => 'ig' ,
'iii' => 'ii' ,
'ipk' => 'ik' ,
'ido' => 'io' ,
'ice' => 'is' ,
'isl' => 'is' ,
'ita' => 'it' ,
'iku' => 'iu' ,
'jpn' => 'ja' ,
'jav' => 'jv' ,
'geo' => 'ka' ,
'kat' => 'ka' ,
'kon' => 'kg' ,
'kik' => 'ki' ,
'kik' => 'ki' ,
'kua' => 'kj' ,
'kaz' => 'kk' ,
'kal' => 'kl' ,
'khm' => 'km' ,
'kan' => 'kn' ,
'kor' => 'ko' ,
'kau' => 'kr' ,
'kas' => 'ks' ,
'kur' => 'ku' ,
'kom' => 'kv' ,
'cor' => 'kw' ,
'kir' => 'ky' ,
'lat' => 'la' ,
'ltz' => 'lb' ,
'ltz' => 'lb' ,
'lug' => 'lg' ,
'lim' => 'li' ,
'lin' => 'ln' ,
'lao' => 'lo' ,
'lit' => 'lt' ,
'lub' => 'lu' ,
'lav' => 'lv' ,
'mlg' => 'mg' ,
'mah' => 'mh' ,
'mao' => 'mi' ,
'mri' => 'mi' ,
'mac' => 'mk' ,
'mkd' => 'mk' ,
'mal' => 'ml' ,
'mon' => 'mn' ,
'mar' => 'mr' ,
'may' => 'ms' ,
'msa' => 'ms' ,
'mlt' => 'mt' ,
'bur' => 'my' ,
'mya' => 'my' ,
'nau' => 'na' ,
'nob' => 'nb' ,
'nde' => 'nd' ,
'nep' => 'ne' ,
'ndo' => 'ng' ,
'dut' => 'nl' ,
'nld' => 'nl' ,
'nno' => 'nn' ,
'nor' => 'no' ,
'nbl' => 'nr' ,
'nav' => 'nv' ,
'nya' => 'ny' ,
'oci' => 'oc' ,
'oji' => 'oj' ,
'orm' => 'om' ,
'ori' => 'or' ,
'oss' => 'os' ,
'pan' => 'pa' ,
'pli' => 'pi' ,
'pol' => 'pl' ,
'pus' => 'ps' ,
'por' => 'pt' ,
'que' => 'qu' ,
'roh' => 'rm' ,
'run' => 'rn' ,
'rum' => 'ro' ,
'ron' => 'ro' ,
'rus' => 'ru' ,
'kin' => 'rw' ,
'san' => 'sa' ,
'srd' => 'sc' ,
'snd' => 'sd' ,
'sme' => 'se' ,
'sag' => 'sg' ,
'sin' => 'si' ,
'slo' => 'sk' ,
'slk' => 'sk' ,
'slv' => 'sl' ,
'smo' => 'sm' ,
'sna' => 'sn' ,
'som' => 'so' ,
'alb' => 'sq' ,
'sqi' => 'sq' ,
'srp' => 'sr' ,
'ssw' => 'ss' ,
'sot' => 'st' ,
'sun' => 'su' ,
'swe' => 'sv' ,
'swa' => 'sw' ,
'tam' => 'ta' ,
'tel' => 'te' ,
'tgk' => 'tg' ,
'tha' => 'th' ,
'tir' => 'ti' ,
'tuk' => 'tk' ,
'tgl' => 'tl' ,
'tsn' => 'tn' ,
'ton' => 'to' ,
'tur' => 'tr' ,
'tso' => 'ts' ,
'tat' => 'tt' ,
'twi' => 'tw' ,
'tah' => 'ty' ,
'uig' => 'ug' ,
'ukr' => 'uk' ,
'urd' => 'ur' ,
'uzb' => 'uz' ,
'ven' => 've' ,
'vie' => 'vi' ,
'vol' => 'vo' ,
'wln' => 'wa' ,
'wol' => 'wo' ,
'xho' => 'xh' ,
'yid' => 'yi' ,
'yor' => 'yo' ,
'zha' => 'za' ,
'chi' => 'zh' ,
'zho' => 'zh' ,
'zul' => 'zu' ,
};
our $lang_grandfather = {
'art-lojban' => 'jbo',
'i-ami' => 'ami',
'i-bnn' => 'bnn',
'i-hak' => 'hak',
'i-klingon' => 'tlh',
'i-lux' => 'lb',
'i-navajo' => 'nv',
'i-pwn' => 'pwn', #haha
'i-tao' => 'tao',
'i-tay' => 'tay',
'i-tsu' => 'tsu',
'no-bok' => 'nb',
'no-nyn' => 'nn',
'sgn-be-fr' => 'sfb',
'sgn-be-nl' => 'vgt',
'sgn-ch-de' => 'sgg',
'zh-guoyu' => 'cmn',
'zh-hakka' => 'hak',
'zh-min-nan' => 'nan',
'zh-xiang' => 'hsn',
};
our $obsolete_iso3166 = {
'UK' => 'GB', # Exceptionally reserved
'FX' => 'FR', # Exceptionally reserved
'ZR' => 'CD', # Zaire => Congo
'HV' => 'BF', # Upper Volta => Burkina Faso
'DY' => 'BJ', # Dahomey => Benin
'BU' => 'MM', # Burma => Myanmar
'TP' => 'TL', # East Timor => Timor-Leste
'NH' => 'VU', # New Hebrides => Vanuatu
'RH' => 'ZW', # Rhodesia => Zimbabwe
};
our $canon_lang = {};
sub fix_document
{
my $old_document = shift;
my $attribute_behaviour = shift || 0;
my $new_document = XML::LibXML::Document->new;
my $new_root = fix_element(
$old_document->documentElement,
$new_document,
{ ':' => 'http://www.w3.org/1999/xhtml', 'xml' => XML_XML_NS }
);
$new_document->setDocumentElement($new_root);
return $new_document;
}
sub fix_element
{
my $old_element = shift;
my $new_document = shift;
my $parent_declarations = shift;
my $declared_namespaces = {};
foreach my $k (keys %{$parent_declarations})
{
$declared_namespaces->{$k} = $parent_declarations->{$k};
}
# Process namespace declarations on this element.
foreach my $attr ($old_element->attributes)
{
next if $attr->nodeType == XML_NAMESPACE_DECL;
if ($attr->nodeName =~ /^xmlns:(.*)$/)
{
my $prefix = $1;
if ($prefix eq 'xml' && $attr->getData eq XML_XML_NS)
{
# that's OK.
}
elsif ($prefix eq 'xml' || $attr->getData eq XML_XML_NS)
{
next;
}
elsif ($prefix eq 'xmlns' || $attr->getData eq XML_XMLNS_NS)
{
next;
}
$declared_namespaces->{ $prefix } = $attr->getData;
}
}
# Process any default XML Namespace
my $hasExplicit = 0;
if ($old_element->hasAttributeNS(undef, 'xmlns'))
{
$hasExplicit = 1;
$declared_namespaces->{ ':' } = $old_element->getAttributeNS(undef, 'xmlns');
}
# Create a new element.
my $new_element;
if ($hasExplicit)
{
$new_element = $new_document->createElementNS(
$declared_namespaces->{ ':' },
$old_element->nodeName,
);
}
else
{
my $tag = $old_element->nodeName;
if ($tag =~ /^([^:]+)\:([^:]+)$/)
{
my $ns_prefix = $1;
my $localname = $2;
if (defined $declared_namespaces->{$ns_prefix})
{
$new_element = $new_document->createElementNS(
$declared_namespaces->{$ns_prefix}, $tag);
}
}
unless ($new_element)
{
$new_element = $new_document->createElementNS(
$declared_namespaces->{ ':' }, $tag);
}
}
# Add attributes to new element.
foreach my $old_attr ($old_element->attributes)
{
next if $old_attr->nodeType == XML_NAMESPACE_DECL;
# next if $old_attr->nodeName =~ /^xmlns(:.*)?$/;
fix_attribute($old_attr, $new_element, $declared_namespaces);
}
# Process child nodes.
foreach my $old_kid ($old_element->childNodes)
{
if ($old_kid->nodeType == XML_TEXT_NODE
|| $old_kid->nodeType == XML_CDATA_SECTION_NODE)
{
$new_element->appendTextNode($old_kid->nodeValue);
}
elsif ($old_kid->nodeType == XML_COMMENT_NODE)
{
$new_element->appendChild(
$new_document->createComment($old_kid->nodeValue)
);
}
elsif ($old_kid->nodeType == XML_ELEMENT_NODE)
{
$new_element->appendChild(
fix_element($old_kid, $new_document, $declared_namespaces)
);
}
}
return $new_element;
}
sub fix_attribute
{
my $old_attribute = shift;
my $new_element = shift;
my $declared_namespaces = shift;
my $name = $old_attribute->nodeName;
my @new_attribute;
if ($name =~ /^([^:]+)\:([^:]+)$/)
{
my $ns_prefix = $1;
my $localname = $2;
if (defined $declared_namespaces->{$ns_prefix})
{
@new_attribute = (
$declared_namespaces->{$ns_prefix},
sprintf("%s:%s", $ns_prefix, $localname),
);
}
}
my $node_value = $old_attribute->nodeValue;
if ($FIX_LANG_ATTRIBUTES && $name =~ /^(xml:)?lang$/i)
{
return undef
unless _valid_lang($node_value);
if ($FIX_LANG_ATTRIBUTES == 2)
{
$node_value = _canon_lang($node_value);
}
}
if (@new_attribute)
{
$new_element->setAttributeNS(@new_attribute, $node_value);
}
else
{
$new_element->setAttribute($name, $node_value);
}
return undef;
}
sub _valid_lang
{
my $value_to_test = shift;
return 1 if (defined $value_to_test) && ($value_to_test eq '');
return 0 unless defined $value_to_test;
# Regex for recognizing RFC 4646 well-formed tags
# http://www.rfc-editor.org/rfc/rfc4646.txt
# http://tools.ietf.org/html/draft-ietf-ltru-4646bis-21
# The structure requires no forward references, so it reverses the order.
# It uses Java/Perl syntax instead of the old ABNF
# The uppercase comments are fragments copied from RFC 4646
# Note: the tool requires that any real "=" or "#" or ";" in the regex be escaped.
my $alpha = '[a-z]'; # ALPHA
my $digit = '[0-9]'; # DIGIT
my $alphanum = '[a-z0-9]'; # ALPHA / DIGIT
my $x = 'x'; # private use singleton
my $singleton = '[a-wyz]'; # other singleton
my $s = '[_-]'; # separator -- lenient parsers will use [_-] -- strict will use [-]
# Now do the components. The structure is slightly different to allow for capturing the right components.
# The notation (?:....) is a non-capturing version of (...): so the "?:" can be deleted if someone doesn't care about capturing.
my $language = '([a-z]{2,8}) | ([a-z]{2,3} [_-] [a-z]{3})';
# ABNF (2*3ALPHA) / 4ALPHA / 5*8ALPHA --- note: because of how | works in regex, don't use $alpha{2,3} | $alpha{4,8}
# We don't have to have the general case of extlang, because there can be only one extlang (except for zh-min-nan).
# Note: extlang invalid in Unicode language tags
my $script = '[a-z]{4}' ; # 4ALPHA
my $region = '(?: [a-z]{2}|[0-9]{3})' ; # 2ALPHA / 3DIGIT
my $variant = '(?: [a-z0-9]{5,8} | [0-9] [a-z0-9]{3} )' ; # 5*8alphanum / (DIGIT 3alphanum)
my $extension = '(?: [a-wyz] (?: [_-] [a-z0-9]{2,8} )+ )' ; # singleton 1*("-" (2*8alphanum))
my $privateUse = '(?: x (?: [_-] [a-z0-9]{1,8} )+ )' ; # "x" 1*("-" (1*8alphanum))
# Define certain grandfathered codes, since otherwise the regex is pretty useless.
# Since these are limited, this is safe even later changes to the registry --
# the only oddity is that it might change the type of the tag, and thus
# the results from the capturing groups.
# http://www.iana.org/assignments/language-subtag-registry
# Note that these have to be compared case insensitively, requiring (?i) below.
my $grandfathered = '(?:
(en [_-] GB [_-] oed)
| (i [_-] (?: ami | bnn | default | enochian | hak | klingon | lux | mingo | navajo | pwn | tao | tay | tsu ))
| (no [_-] (?: bok | nyn ))
| (sgn [_-] (?: BE [_-] (?: fr | nl) | CH [_-] de ))
| (zh [_-] min [_-] nan)
)';
# old: | zh $s (?: cmn (?: $s Hans | $s Hant )? | gan | min (?: $s nan)? | wuu | yue );
# For well-formedness, we don't need the ones that would otherwise pass.
# For validity, they need to be checked.
# $grandfatheredWellFormed = (?:
# art $s lojban
# | cel $s gaulish
# | zh $s (?: guoyu | hakka | xiang )
# );
# Unicode locales: but we are shifting to a compatible form
# $keyvalue = (?: $alphanum+ \= $alphanum+);
# $keywords = ($keyvalue (?: \; $keyvalue)*);
# We separate items that we want to capture as a single group
my $variantList = $variant . '(?:' . $s . $variant . ')*' ; # special for multiples
my $extensionList = $extension . '(?:' . $s . $extension . ')*' ; # special for multiples
my $langtag = "
($language)
($s ( $script ) )?
($s ( $region ) )?
($s ( $variantList ) )?
($s ( $extensionList ) )?
($s ( $privateUse ) )?
";
# Here is the final breakdown, with capturing groups for each of these components
# The variants, extensions, grandfathered, and private-use may have interior '-'
my $r = ($value_to_test =~
/^(
($langtag)
| ($privateUse)
| ($grandfathered)
)$/xi);
return $r;
}
# If people use a non-canon lang once, they're likely to do it twice, so a little caching.
sub _canon_lang
{
my $lang = shift;
unless (defined $canon_lang->{$lang})
{
$canon_lang->{$lang} = __canon_lang($lang);
}
return $canon_lang->{$lang};
}
sub __canon_lang
{
# Use lower case only
my $lang = lc shift;
# If there's a 2 letter code where a three letter code has been used, replace it.
if ($lang =~ /^([a-z]{3})/)
{
substr($lang, 0, 3) = $lang_3to2->{$1}
if defined $lang_3to2->{$1};
}
return $lang_grandfather->{$lang}
if defined $lang_grandfather->{$lang};
# Simple case.
return $lang if length $lang < 4;
# Replace '_' with '-'.
$lang =~ s/_/-/g;
# upper case the country component of lang-country pairs.
return sprintf('%s-%s', $1, _canon_country($2))
if $lang =~ /^([a-z]{2,3})-([a-z]{2}|\d{3})$/;
# title case the script component of lang-script pairs.
return sprintf('%s-%s', $1, _canon_script($2))
if $lang =~ /^([a-z]{2,3})-([a-z]{4})$/;
# title case the script component, upper case country componet of lang-script-country triplets.
return sprintf('%s-%s-%s', $1, _canon_script($2), _canon_country($3))
if $lang =~ /^([a-z]{2,3})-([a-z]{4})-([a-z]{2}|\d{3})$/;
# Too complicated - give up and return lower case.
return $lang;
}
sub _canon_country
{
my $c = uc shift;
if ($c =~ /^\d\d\d$/)
{
my $c1 = country_code2code($c, LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_2);
$c = uc $c1
if defined $c1 && length $c1;
}
return $obsolete_iso3166->{$c}
if defined $obsolete_iso3166->{$c};
return $c;
}
sub _canon_script
{
my $s = ucfirst lc shift;
return $s;
}
1;
__END__
=head1 NAME
HTML::HTML5::Sanity - make HTML5 DOM trees less insane
=head1 SYNOPSIS
use HTML::HTML5::Parser;
use HTML::HTML5::Sanity;
my $parser = HTML::HTML5::Parser->new;
my $html5_dom = $parser->parse_file('http://example.com/');
my $sane_dom = fix_document($html5_dom);
=head1 DESCRIPTION
The Document Object Model (DOM) generated by HTML::HTML5::Parser meets
the requirements of the HTML5 spec, but will probably catch a lot of
people by surprise.
The main oddity is that elements and attributes which appear to be
namespaced are not really. For example, the following element:
...
Looks like it should be parsed so that it has an attribute "lang" in
the XML namespace. Not so. It will really be parsed as having the
attribute "xml:lang" in the null namespace.
=over 4
=item C<< fix_document($document) >>
$sane_dom = fix_document($html5_dom);
Returns a modified copy of the DOM and leaving the original DOM
unmodified.
=item C<< fix_element($element_node, $new_document_node, \%namespaces) >>
Don't use this. Not exported.
=item C<< fix_attribute($attribute_node, $new_element_node, \%namespaces) >>
Don't use this. Not exported.
=item C<$HTML::HTML5::Sanity::FIX_LANG_ATTRIBUTES>
$HTML::HTML5::Sanity::FIX_LANG_ATTRIBUTES = 2;
$sane_dom = fix_document($html5_dom);
If set to 1 (the default), the package will detect invalid values in
@lang and @xml:lang, and remove the attribute if it is invalid. If set
to 2, it will also attempt to canonicalise the value (e.g. 'EN_GB' will
be converted to to 'en-GB'). If set to 0, then the value of language
attributes is not checked.
=back
=head1 BUGS
Please report any bugs to L.
=head1 SEE ALSO
L, L, L.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2009-2014 by Toby Inkster
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
=cut