snapframework / xmlhtml Goto Github PK
View Code? Open in Web Editor NEWXML parser and renderer with HTML 5 quirks mode
License: Other
XML parser and renderer with HTML 5 quirks mode
License: Other
HTML comments have the following format:
<!-- foo -->
This is fine, however, the number of - characters used is not correctly specified in Heist. HTML does not make a distinction between and ------>. Any hyphens after the opening two and preceding the ending two are not significant. Heist will throw a parse error in this situation.
(Originally snapframework/heist#61)
parseHTML is mishandling HTML entities in urls. In particular, if a URL contains the string "¢reLon=158" then parseHTML misinterprets the string "¢" as the HTML entity "¢" and replaces it with the Unicode value for ¢
If you are allowing ampersands in urls because you are not in strict XML mode, then I believe xmlhtml needs to search for a valid terminating semicolon before converting HTML entities. Or ideally it should not convert the entities at all.
Will there be an update of this package that adds support for recent versions of blaze-html?
(maybe it fails on all 32 bit archs)
https://buildd.debian.org/status/package.php?p=haskell-xmlhtml&suite=unstable
test/src/Text/XmlHtml/Tests.hs:20:1: warning: [-Wunused-imports]
The qualified import of `Text.Blaze.Internal' is redundant
except perhaps to import instances from `Text.Blaze.Internal'
To import instances alone, use: import Text.Blaze.Internal()
[6 of 6] Compiling Main ( test/src/TestSuite.hs, dist-ghc/build/testsuite/testsuite-tmp/Main.o )
Linking dist-ghc/build/testsuite/testsuite ...
touch build-ghc-stamp
. /usr/share/haskell-devscripts/Dh_Haskell.sh && \
check_recipe
Running debian/hlibrary.setup test --builddir=dist-ghc --show-details=direct
Running 1 test suites...
Test suite testsuite: RUNNING...
byteOrderMark : [OK]
emptyDocument : [OK]
publicDocType : [OK]
systemDocType : [OK]
emptyDocType : [OK]
dtdInternalScan : [OK]
textOnly : [OK]
textWithRefs : [OK]
untermRef : [OK]
textWithCDATA : [OK]
cdataOnly : [OK]
commentOnly : [OK]
emptyElement : [OK]
emptyElement2 : [OK]
elemWithText : [OK]
xmlDeclXML : [OK]
procInst : [OK]
badDoctype1 : [OK]
badDoctype2 : [OK]
badDoctype3 : [OK]
badDoctype4 : [OK]
badDoctype5 : [OK]
tagNames : [OK]
emptyDocumentHTML : [OK]
publicDocTypeHTML : [OK]
systemDocTypeHTML : [OK]
emptyDocTypeHTML : [OK]
textOnlyHTML : [OK]
textWithRefsHTML : [OK]
textWithCDataHTML : [OK]
cdataOnlyHTML : [OK]
commentOnlyHTML : [OK]
emptyElementHTML : [OK]
emptyElement2HTML : [OK]
elemWithTextHTML : [OK]
xmlDeclHTML : [OK]
procInstHTML : [OK]
badDoctype1HTML : [OK]
badDoctype2HTML : [OK]
badDoctype3HTML : [OK]
badDoctype4HTML : [OK]
badDoctype5HTML : [OK]
voidElem : [OK]
caseInsDoctype1 : [OK]
caseInsDoctype2 : [OK]
voidEmptyElem : [OK]
rawTextElem : [OK]
endTagCase : [OK]
hexEntityCap : [OK]
laxAttrName : [OK]
badAttrName : [OK]
emptyAttr : [OK]
emptyAttr2 : [OK]
unquotedAttr : [OK]
laxAttrVal : [OK]
ampersandInText : [OK]
omitOptionalEnds : [OK]
omitEndHEAD : [OK]
omitEndLI : [OK]
omitEndDT : [OK]
omitEndDD : [OK]
omitEndP : [OK]
omitEndRT : [OK]
omitEndRP : [OK]
omitEndOPTGRP : [OK]
omitEndOPTION : [OK]
omitEndCOLGRP : [OK]
omitEndTHEAD : [OK]
omitEndTBODY : [OK]
omitEndTFOOT : [OK]
omitEndTR : [OK]
omitEndTD : [OK]
omitEndTH : [OK]
testNewRefs : [OK]
errorImplicitClose : [OK]
weirdScriptThing : [OK]
renderByteOrderMark : [OK]
renderByteOrderMarkLE : [OK]
singleQuoteInSysID : [OK]
doubleQuoteInSysID : [OK]
bothQuotesInSysID : [OK]
doubleQuoteInPubID : [OK]
doubleDashInComment : [OK]
trailingDashInComment : [OK]
renderEmptyText : [OK]
singleQuoteInAttr : [OK]
doubleQuoteInAttr : [OK]
bothQuotesInAttr : [OK]
ndashEscapesInLatin : [OK]
smileyEscapesInLatin : [OK]
numericalEscapes : [Failed]
numericalEscapes
hRenderByteOrderMark : [OK]
hSingleQuoteInSysID : [OK]
hDoubleQuoteInSysID : [OK]
hBothQuotesInSysID : [OK]
hDoubleQuoteInPubID : [OK]
hDoubleDashInComment : [OK]
hTrailingDashInComment : [OK]
hRenderEmptyText : [OK]
hSingleQuoteInAttr : [OK]
hDoubleQuoteInAttr : [OK]
hBothQuotesInAttr : [OK]
renderHTMLVoid : [OK]
renderHTMLVoid2 : [OK]
renderHTMLRaw : [OK]
renderHTMLRawMult : [OK]
renderHTMLRaw2 : [OK]
renderHTMLRaw3 : [OK]
renderHTMLRaw4 : [OK]
renderHTMLEmptyAttr : [OK]
renderHTMLEmptyAttr2 : [OK]
renderHTMLAmpAttr1 : [OK]
renderHTMLAmpAttr2 : [OK]
renderHTMLAmpAttr3 : [OK]
renderHTMLQVoid : [OK]
renderHTMLQVoid2 : [OK]
renderHTMLQRaw : [OK]
renderHTMLQRawMult : [OK]
renderHTMLQRaw2 : [OK]
renderHTMLQRaw3 : [OK]
renderHTMLQRaw4 : [OK]
compareExternalIDs : [OK]
compareInternalSubs : [OK]
compareDoctypes : [OK]
compareNodes : [OK]
compareDocuments : [OK]
compareEncodings : [OK]
exerciseShows : [OK]
docNodeAccessors : [OK]
isTextNodeYes : [OK]
isTextNodeNo : [OK]
isTextNodeNo2 : [OK]
isCommentYes : [OK]
isCommentNo : [OK]
isCommentNo2 : [OK]
isElementYes : [OK]
isElementNo : [OK]
isElementNo2 : [OK]
tagNameElement : [OK]
tagNameText : [OK]
tagNameComment : [OK]
getAttributePresent : [OK]
getAttributeMissing : [OK]
getAttributeWrongType : [OK]
hasAttributePresent : [OK]
hasAttributeMissing : [OK]
hasAttributeWrongType : [OK]
setAttributeNew : [OK]
setAttributeReplace : [OK]
setAttributeWrongType : [OK]
nestedNodeText : [OK]
childNodesElem : [OK]
childNodesOther : [OK]
childElemsTest : [OK]
childElemsTagTest : [OK]
childElemTagExists : [OK]
childElemTagNotExists : [OK]
childElemTagOther : [OK]
descNodesElem : [OK]
descNodesOther : [OK]
descElemsTest : [OK]
descElemsTagTest : [OK]
descElemTagExists : [OK]
descElemTagDFS : [OK]
descElemTagNotExists : [OK]
descElemTagOther : [OK]
fromNodeAndCurrent : [OK]
fromNodesAndSiblings : [OK]
leftSiblings : [OK]
emptyFromNodes : [OK]
cursorNEQ : [OK]
cursorNavigation : [OK]
cursorSearch : [OK]
cursorMutation : [OK]
cursorInsertion : [OK]
cursorDeletion : [OK]
blazeTestString : [OK]
blazeTestText : [OK]
blazeTestBS : [OK]
blazeTestPre : [OK]
blazeTestExternal : [OK]
blazeTestCustom : [OK]
blazeTestMulti : [OK]
blazeTestEmpty : [OK]
xmlhtml/ibm-not-wf : [OK]
xmlhtml/ibm-invalid : [OK]
xmlhtml/ibm-valid : [OK]
xmlhtml/oasis : [OK]
xmlhtml/r-ibm-not-wf : [OK]
xmlhtml/r-ibm-invalid : [OK]
xmlhtml/r-ibm-valid : [OK]
xmlhtml/r-oasis : [OK]
xmlhtml/h-ibm-not-wf : [OK]
xmlhtml/h-ibm-invalid : [OK]
xmlhtml/h-ibm-valid : [OK]
xmlhtml/h-oasis : [OK]
xmlhtml/hr-ibm-not-wf : [OK]
xmlhtml/hr-ibm-invalid : [OK]
xmlhtml/hr-ibm-valid : [OK]
xmlhtml/hr-oasis : [OK]
Test Cases Total
Passed 199 199
Failed 1 1
Total 200 200
Test suite testsuite: FAIL
Test suite logged to: dist-ghc/test/xmlhtml-0.2.4-testsuite.log
0 of 1 test suites (0 of 1 test cases) passed.
/usr/share/cdbs/1/class/hlibrary.mk:154: recipe for target 'check-ghc-stamp' failed
make: *** [check-ghc-stamp] Error 1
dpkg-buildpackage: error: debian/rules build-arch gave error exit status 2
--------------------------------------------------------------------------------
Build finished at 2017-06-21T09:39:07Z
Finished
--------
{-# LANGUAGE OverloadedStrings #-}
import Text.XmlHtml
tree1 = parseHTML "" "<div itemtype='type' itemscope></div>"
tree2 = parseHTML "" "<div itemscope itemtype='type'></div>" -- this order fails to parse
ghci session:
*Main> tree1 Right (HtmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [Element {elementTag = "div", elementAttrs = [("itemtype","type"),("itemscope","")], elementChildren = []}]}) *Main> tree2 Left "(line 1, column 16):\nunexpected \"i\"\nexpecting \"=\", \"/\" or \">\""
Leading whitespace treatment in xmlhtml
is inconsistent.
Consider the following behavior of parseXML
(the same happens with parseHTML
) where leading whitespace is always dropped, and trailing whitespace is always kept:
> parseXML "x" ""
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = []})
> parseXML "x" " "
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = []})
> parseXML "x" "x"
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [TextNode "x"]})
> parseXML "x" " x"
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [TextNode "x"]})
> parseXML "x" "x "
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [TextNode "x "]})
> parseXML "x" " x "
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [TextNode "x "]})
See what happens, however, when the “leading whitespace” comes after some element:
> parseXML "x" "<a/> b "
Right (HtmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [Element {elementTag = "a", elementAttrs = [], elementChildren = []},TextNode " b "]})
These two examples behave differently, and I think the correct behavior is the one from the latter example, since xmlhtml
should not be discarding the contents of a text node.
So, my proposal is:
Keep the behavior of leading whitespace after an element as it is today.
Keep the behavior of trailing whitespace everywhere as it is today.
Fix top-level text node parsing so that it doesn't discard leading whitespace.
Builder has been in bytestring
long enough that we might be able to switch to using it now.
" "
if parsed and then rendered will return "<!DOCTYPE html>\n "
instead of "<!DOCTYPE html>\n "
.
Part of the HTML5 form specification includes the ability to write regular expressions that the field needs to validate against. Unfortunately, if the attribute includes backslashes for escaping, Heist removes them.
From my template (both vanilla HTML and digestive functors input tags, the result is the same):
<dfInput type="tel" ref="phone" required pattern="(((\d(-| ){0,1}){0,1}((\(\d{3}\)(-| ){0,1})|(\d{3}-))\d{3}-\d{4})|(\+?\d{2}((-| )\d{1,8}){1,5}))(( x| ext)\d{1,5}){0,1}" />
The following HTML is generated:
<input type='tel' maxlength='25' required pattern='(((d(-| ){0,1}){0,1}(((d{3})(-| ){0,1})|(d{3}-))d{3}-d{4})|(+?d{2}((-| )d{1,8}){1,5}))(( x| ext)d{1,5}){0,1}' id='form.phone' name='form.phone' value='555-5555' />
I have also tried setting the attribute using splices and the resulting HTML source is identical to the previous sample:
<dfInput type="tel" ref="phone" required pattern="${phone_pattern}" />
phoneSplices =
[ ("phone_pattern", callTemplate "/common/forms/fragments/phone_pattern" [])
, ("phone_tip", callTemplate "/common/forms/fragments/phone_tip" [])
]
The contents of /common/forms/fragments/phone_pattern is a single line of text that is the regex pattern from the first sample.
I'm only using callTemplate because I couldn't figure out why the pattern as a string generates this error: lexical error in string/character literal at character 'd' (still fairly new to Haskell)
phoneSplices =
[ ("phone_pattern", textSplice "(((\d(-| ){0,1}){0,1}((\(\d{3}\)(-| ){0,1})|(\d{3}-))\d{3}-\d{4})|(\+?\d{2}((-| )\d{1,8}){1,5}))(( x| ext)\d{1,5}){0,1}" [])
, ("phone_tip", callTemplate "/common/forms/fragments/phone_tip" [])
]
parseHTML
parses " "
into a text node with the unicode code point for nonbreaking space: [TextNode "\160"]
Is it possible and safe to add a parser that leaves HTML entities like
as they are in text nodes? I have a project where xmlhtml is the first stage in a text pipeline spread across different languages/libraries/environments, where it would be more reliable to pass
all the way through than to count on the text encoding of the different components.
Preserving HTML entities could make more sense in contexts like heist
as well, where the mental model is that heist
is stitching together different html fragments. snapframework/heist#37 for instance.
Would it be possible to list this package independently on stackage? I believe it was being brought into stackage transitively via snap-server
, which in turn comes via websockets-snap
listed under @jaspervdj in https://github.com/fpco/stackage/blob/master/build-constraints.yaml. It is therefore missing at the moment from stackage nightly because snap as a whole is not yet GHC 8 compatible. However, xmlhtml
builds successfully against the latest nightly, and I have run the tests manually (with the small change in #18).
I could list this package myself on stackage, but it seems better for it to be done by the maintainers. (This can happen without the tweak to the tests, since they are structured in a way which will not run when building stackage.)
found a funky ghcbug/misbehavior via xmlhtml, and https://ghc.haskell.org/trac/ghc/ticket/9370#comment:10
spj would probably appreciate some information from y'all :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.