From decdc0941e1686ab6685caf802e5921dcadc5d89 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 23 Jan 2018 00:45:28 +0100 Subject: [PATCH] Handle content(first-letter) --- weasyprint/css/validation.py | 3 +-- weasyprint/formatting_structure/build.py | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/weasyprint/css/validation.py b/weasyprint/css/validation.py index 2912e77e..08f96f9d 100644 --- a/weasyprint/css/validation.py +++ b/weasyprint/css/validation.py @@ -1585,8 +1585,7 @@ def validate_content_list_token(token): elif prototype in (('content', ()), ('content', ('ident',))): if not args: return (name, 'text') - elif args[0] in ('text', 'after', 'before'): - # TODO: first-letter should be allowed here too + elif args[0] in ('text', 'after', 'before', 'first-letter'): return (name, args[0]) elif prototype in (('counter', ('ident',)), ('counters', ('ident', 'string'))): diff --git a/weasyprint/formatting_structure/build.py b/weasyprint/formatting_structure/build.py index 38c304cc..dbe5ae45 100644 --- a/weasyprint/formatting_structure/build.py +++ b/weasyprint/formatting_structure/build.py @@ -1159,6 +1159,11 @@ def box_text(box): return '' +def box_text_first_letter(box): + text = box_text(box) + return text[0] if text else '' + + def box_text_before(box): if isinstance(box, boxes.ParentBox): return ''.join( @@ -1182,4 +1187,5 @@ def box_text_after(box): TEXT_CONTENT_EXTRACTORS = { 'text': box_text, 'before': box_text_before, - 'after': box_text_after} + 'after': box_text_after, + 'first-letter': box_text_first_letter}