|
|
@@ -1744,7 +1744,8 @@ static int match_compound(struct br_doc *d, unsigned int node,
|
|
|
struct br_node *n = &d->nodes[node];
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
- while (i < len && sel[i] != '.' && sel[i] != '#' && sel[i] != '[')
|
|
|
+ while (i < len && sel[i] != '.' && sel[i] != '#' &&
|
|
|
+ sel[i] != '[' && sel[i] != ':')
|
|
|
i++;
|
|
|
if (i > 0 && !(i == 1 && sel[0] == '*')) {
|
|
|
char tag[32];
|
|
|
@@ -1769,7 +1770,7 @@ static int match_compound(struct br_doc *d, unsigned int node,
|
|
|
i++;
|
|
|
start = i;
|
|
|
while (i < len && sel[i] != '.' && sel[i] != '#' &&
|
|
|
- sel[i] != '[' && sel[i] != ' ')
|
|
|
+ sel[i] != '[' && sel[i] != ':' && sel[i] != ' ')
|
|
|
i++;
|
|
|
if (!class_contains(br_find_attr(d, node, "class"),
|
|
|
sel + start, i - start))
|
|
|
@@ -1780,7 +1781,7 @@ static int match_compound(struct br_doc *d, unsigned int node,
|
|
|
i++;
|
|
|
start = i;
|
|
|
while (i < len && sel[i] != '.' && sel[i] != '#' &&
|
|
|
- sel[i] != '[' && sel[i] != ' ')
|
|
|
+ sel[i] != '[' && sel[i] != ':' && sel[i] != ' ')
|
|
|
i++;
|
|
|
{
|
|
|
const char *id = br_find_attr(d, node, "id");
|
|
|
@@ -1835,6 +1836,23 @@ static int match_compound(struct br_doc *d, unsigned int node,
|
|
|
sel + vs, ve - vs, op))
|
|
|
return 0;
|
|
|
}
|
|
|
+ } else if (sel[i] == ':') {
|
|
|
+ unsigned int start;
|
|
|
+
|
|
|
+ i++;
|
|
|
+ start = i;
|
|
|
+ while (i < len && sel[i] != '.' && sel[i] != '#' &&
|
|
|
+ sel[i] != '[' && sel[i] != ':' && sel[i] != ' ')
|
|
|
+ i++;
|
|
|
+ /* Every link is treated as unvisited: there is no
|
|
|
+ * history state, so a:link matches and a:visited does
|
|
|
+ * not. Other pseudo-classes (hover/focus/active) are
|
|
|
+ * deliberately unmatched instead of applying their
|
|
|
+ * styles permanently. */
|
|
|
+ if (i - start != 4 ||
|
|
|
+ !ci_eq_n(sel + start, "link", 4) ||
|
|
|
+ n->tag != BR_TAG_A || !n->href_off)
|
|
|
+ return 0;
|
|
|
} else {
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -5657,6 +5675,13 @@ static void parse_css(struct br_doc *d, const char *s, unsigned int len)
|
|
|
k += 5;
|
|
|
continue;
|
|
|
}
|
|
|
+ if (k + 5 <= e &&
|
|
|
+ ci_eq_n(s + k, ":link", 5) &&
|
|
|
+ (k + 5 == e ||
|
|
|
+ !is_ident(s[k + 5]))) {
|
|
|
+ k += 5;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if (k + 5 <= e &&
|
|
|
ci_eq_n(s + k, ":not(", 5)) {
|
|
|
unsigned int n = k + 5;
|
|
|
@@ -6026,6 +6051,14 @@ static int compound_match(struct br_doc *d, unsigned int node, const char *s,
|
|
|
return 0;
|
|
|
i += 5;
|
|
|
got = 1;
|
|
|
+ } else if (i + 5 <= len && ci_eq_n(s + i, ":link", 5) &&
|
|
|
+ (i + 5 == len || !is_ident(s[i + 5]))) {
|
|
|
+ /* No history state: every link is unvisited. */
|
|
|
+ if (d->nodes[node].tag != BR_TAG_A ||
|
|
|
+ !d->nodes[node].href_off)
|
|
|
+ return 0;
|
|
|
+ i += 5;
|
|
|
+ got = 1;
|
|
|
} else if (i + 5 <= len && ci_eq_n(s + i, ":not(", 5)) {
|
|
|
unsigned int st = i + 5, e = st;
|
|
|
int depth = 1;
|
|
|
@@ -6762,6 +6795,10 @@ void br_style_for(struct br_doc *d, unsigned int node,
|
|
|
break;
|
|
|
case BR_TAG_TD: case BR_TAG_TH:
|
|
|
out->pr = 12;
|
|
|
+ /* A cell establishes left-aligned content even inside a legacy
|
|
|
+ * <center> (HN's outer page wrapper); author CSS/align below
|
|
|
+ * can still override this. */
|
|
|
+ out->align = BR_ALIGN_LEFT;
|
|
|
break;
|
|
|
case BR_TAG_VIDEO:
|
|
|
out->display = BR_DISPLAY_BLOCK;
|
|
|
@@ -6770,16 +6807,26 @@ void br_style_for(struct br_doc *d, unsigned int node,
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- /* Legacy bgcolor attributes (tables/cells/body) are presentational
|
|
|
- * hints; author CSS still wins because it is applied below. */
|
|
|
+ /* Legacy bgcolor/align attributes (tables/cells/body) are
|
|
|
+ * presentational hints; author CSS still wins because it is applied
|
|
|
+ * below. */
|
|
|
{
|
|
|
unsigned short bgc;
|
|
|
const char *bga = br_find_attr(d, node, "bgcolor");
|
|
|
+ const char *ala = br_find_attr(d, node, "align");
|
|
|
|
|
|
if (bga && parse_color(bga, s_len(bga), &bgc)) {
|
|
|
out->bg = bgc;
|
|
|
out->has_bg = 1;
|
|
|
}
|
|
|
+ if (ala) {
|
|
|
+ if (same_string(ala, "right"))
|
|
|
+ out->align = BR_ALIGN_RIGHT;
|
|
|
+ else if (same_string(ala, "center"))
|
|
|
+ out->align = BR_ALIGN_CENTER;
|
|
|
+ else if (same_string(ala, "left"))
|
|
|
+ out->align = BR_ALIGN_LEFT;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* presentational <font color>: author CSS below still wins */
|
|
|
@@ -7175,6 +7222,7 @@ int br_parse(struct br_doc *d, const char *html, unsigned int len)
|
|
|
if (tag == BR_TAG_SCRIPT) {
|
|
|
int p = find_ci(html, len, "</script", 8, i);
|
|
|
unsigned int end = p >= 0 ? (unsigned int)p : len;
|
|
|
+ unsigned int idx;
|
|
|
|
|
|
if (script_is_javascript(html + attr_start,
|
|
|
attr_end - attr_start)) {
|
|
|
@@ -7191,6 +7239,16 @@ int br_parse(struct br_doc *d, const char *html, unsigned int len)
|
|
|
d->scripts_truncated = 1;
|
|
|
}
|
|
|
}
|
|
|
+ /* Keep the element in the DOM even though its body is
|
|
|
+ * executed separately: scripts (Piwik, analytics)
|
|
|
+ * insert a sibling after getElementsByTagName('script')
|
|
|
+ * [0], and the element must exist for that to work. */
|
|
|
+ idx = node_append(d, stack[sp], BR_NODE_ELEM,
|
|
|
+ (unsigned char)tag);
|
|
|
+ if (idx)
|
|
|
+ parse_attrs(d, &d->nodes[idx],
|
|
|
+ html + attr_start,
|
|
|
+ attr_end - attr_start);
|
|
|
i = p >= 0 ? (unsigned int)p + 8 : len;
|
|
|
while (i < len && html[i] != '>')
|
|
|
i++;
|
|
|
@@ -7220,6 +7278,8 @@ int br_parse(struct br_doc *d, const char *html, unsigned int len)
|
|
|
int p = find_ci(html, len, "</style", 7, i);
|
|
|
unsigned int end = p >= 0 ? (unsigned int)p : len;
|
|
|
unsigned int cend = end;
|
|
|
+ unsigned int idx;
|
|
|
+
|
|
|
while (cend > i && is_space(html[cend - 1]))
|
|
|
cend--;
|
|
|
if (css_len + (cend - i) + 2 < BR_CSS_SIZE) {
|
|
|
@@ -7227,6 +7287,15 @@ int br_parse(struct br_doc *d, const char *html, unsigned int len)
|
|
|
css_store[css_len++] = html[k];
|
|
|
css_store[css_len++] = '\n';
|
|
|
}
|
|
|
+ /* The CSS is collected above, but keep a display:none
|
|
|
+ * element so getElementsByTagName('style')/parentNode
|
|
|
+ * behave like a real document. */
|
|
|
+ idx = node_append(d, stack[sp], BR_NODE_ELEM,
|
|
|
+ (unsigned char)tag);
|
|
|
+ if (idx)
|
|
|
+ parse_attrs(d, &d->nodes[idx],
|
|
|
+ html + attr_start,
|
|
|
+ attr_end - attr_start);
|
|
|
i = p >= 0 ? (unsigned int)p + 7 : len;
|
|
|
while (i < len && html[i] != '>')
|
|
|
i++;
|