Skip to content

Commit

Permalink
clean up font sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Feb 17, 2018
1 parent 11b29ab commit 0f7ef2c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions legi/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
'clear': 'none',
'color': '#000000',
'dir': 'ltr',
'size': '3', # https://developer.mozilla.org/docs/Web/HTML/Element/font
'valign': 'baseline',
}

Expand Down Expand Up @@ -162,6 +163,11 @@ def start(self, tag, attrs):
if parent_style == v:
continue
if parent_style:
if k == 'size':
size = int(v)
# Skip 0 (invalid) and 4 through 7 (enlarged text)
if size == 0 or size > 3:
continue
new_styles[k] = v
# Add to output
attrs_str += ' %s=%s' % (k, quoteattr(v))
Expand Down Expand Up @@ -480,10 +486,17 @@ def analyze(db):
p = ArgumentParser()
p.add_argument('command', choices=['analyze', 'clean'])
p.add_argument('db')
p.add_argument('--font-size', default='keep-small', choices=['drop', 'keep-small', 'preserve'],
help="what to do with the `size` attribute of `font` elements")
p.add_argument('--skip-checks', default=False, action='store_true',
help="skips checking the result of HTML cleaning")
args = p.parse_args()

if args.font_size == 'drop':
USELESS_ATTRIBUTES.add('size')
elif args.font_size == 'preserve':
DEFAULT_STYLE.pop('size')

db = connect_db(args.db)
try:
with db:
Expand Down

0 comments on commit 0f7ef2c

Please sign in to comment.