Repository navigation
fix(parse): keep <body> and <html> style attributes - #36
leshchenko1979 wants to merge 1 commit into
Conversation
|
Thanks for digging into this, but I can't merge this one as it stands, for two reasons.
The fix for the case in #34 is to move the |
html.ParseFragment ignores <html>, <head> and <body> start tags together with their attributes, so a full document that declares its font, colour or background on <body> rendered with built-in defaults and no background. Stylesheet-driven pages and email templates put exactly those properties there, so the loss was silent and universal. Detect a full document that declares attributes on <body> and parse it with html.Parse, then convert the <body> element itself. Fragments and <body> without attributes keep the existing fragment path. Visible as text rendering in the built-in font instead of the declared one: bold Cyrillic came out 12% narrower than Chromium, which reads like a font metrics bug but is not. Fixes Macawls#34
96aa967 to
8dce095
Compare
Fixes #34.
Problem
html.ParseFragmentignores<html>,<head>and<body>start tags together with their attributes (HTML standard: the fragment is parsed as if it were the body's children).Parsereturned those children, so the<body>element never existed in the tree and itsstylewas lost without a warning.Every stylesheet-driven page and every email template puts the page font, base colour and background on
<body>.Before / after
<body style="background:#ff0000">, pixel (150,150)(255,255,255)(255,0,0)(255,0,0)font-family:'DejaVu Sans'on<body>, family passed toResolve"sans-serif"(built-in fallback)"DejaVu Sans""DejaVu Sans"ПАРИТЕТ ПАРИТЕТ 123, weight 700, 20px, ink widthParity Parity 123, weight 700ПАРИТЕТ ПАРИТЕТ 123, weight 400Bold Cyrillic was 12 % narrower than the browser — which looks exactly like a hinting or font-metrics bug and sends you hunting through
font/. It was not: the bold face was never used.Fix
parse/parse.go: when the input is a full document that declares attributes on<body>, parse it withhtml.Parseand convert the<body>element itself, attributes intact. Fragments, and documents whose<body>carries no attributes, keep the existing fragment path unchanged — so no existing output moves.Tests
parse/body_style_test.go— body style survives; fragment path unchanged;<body>without attributes adds no wrapper.ogre_body_style_e2e_test.go— through the publicRender: body background is painted; text declared on<body>measures identically to the same declaration on a<div>.Both fail on
main(root background = "", want "#ff0000",background pixel = (0,0,0)) and pass with the fix.Comparison harness (21 Chromium cases, DejaVu Sans)
Nothing regressed; text cases improved because they now use the font the document asks for:
17-table-divis the one case that reads worse, and it is not a regression of this change: that fixture relies onbox-sizing: content-box(600 px content box inside 56 px padding). Ogre's default isborder-box(Satori compatibility, see #23), so the wrapper is 600 px wide in both engines; once the real font arrives the cells are laid out at their true widths and the difference becomes visible. Adding an explicitbox-sizing: content-boxto that fixture drops it to 0.07 %:box-sizing: content-boxSuggest updating that fixture rather than changing the renderer default.