fixup garbage with no >

This commit is contained in:
Adam D. Ruppe 2019-02-07 19:51:59 -05:00
parent ee12ef0b6e
commit ec4a718730
1 changed files with 29 additions and 2 deletions

31
dom.d
View File

@ -1,4 +1,8 @@
// FIXME: add classList // FIXME: add classList
// FIXME: add matchesSelector
// FIXME: https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML
// FIXME: appendChild should not fail if the thing already has a parent; it should just automatically remove it per standard.
/++ /++
This is an html DOM implementation, started with cloning This is an html DOM implementation, started with cloning
what the browser offers in Javascript, but going well beyond what the browser offers in Javascript, but going well beyond
@ -824,6 +828,12 @@ class Document : FileResource {
while(pos < data.length && data[pos] != '>') while(pos < data.length && data[pos] != '>')
pos++; pos++;
if(pos >= data.length) {
// the tag never closed
assert(data.length != 0);
pos = data.length - 1; // rewinding so it hits the end at the bottom..
}
} }
auto whereThisTagStarted = pos; // for better error messages auto whereThisTagStarted = pos; // for better error messages
@ -3497,8 +3507,14 @@ struct ElementCollection {
return !elements.length; return !elements.length;
} }
/// Collects strings from the collection, concatenating them together /++
/// Kinda like running reduce and ~= on it. Collects strings from the collection, concatenating them together
Kinda like running reduce and ~= on it.
---
document["p"].collect!"innerText";
---
+/
string collect(string method)(string separator = "") { string collect(string method)(string separator = "") {
string text; string text;
foreach(e; elements) { foreach(e; elements) {
@ -3517,6 +3533,17 @@ struct ElementCollection {
return this; return this;
} }
/++
Calls [Element.wrapIn] on each member of the collection, but clones the argument `what` for each one.
+/
ElementCollection wrapIn(Element what) {
foreach(e; elements) {
e.wrapIn(what.cloneNode(false));
}
return this;
}
/// Concatenates two ElementCollection together. /// Concatenates two ElementCollection together.
ElementCollection opBinary(string op : "~")(ElementCollection rhs) { ElementCollection opBinary(string op : "~")(ElementCollection rhs) {
return ElementCollection(this.elements ~ rhs.elements); return ElementCollection(this.elements ~ rhs.elements);