mirror of
https://codeberg.org/privacy1st/image-width-limit
synced 2024-12-04 22:25:03 +01:00
height:25em instead of height:auto
This commit is contained in:
parent
78f55ee1a1
commit
c82049a958
2
PKGBUILD
2
PKGBUILD
@ -3,7 +3,7 @@ _pkgname=image-width-limit
|
|||||||
_reponame=arch
|
_reponame=arch
|
||||||
|
|
||||||
pkgname="de-p1st-$_pkgname"
|
pkgname="de-p1st-$_pkgname"
|
||||||
pkgver=1.0.1
|
pkgver=1.0.2
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Limit width of HTML images"
|
pkgdesc="Limit width of HTML images"
|
||||||
arch=('any')
|
arch=('any')
|
||||||
|
14
README.md
14
README.md
@ -1,15 +1,11 @@
|
|||||||
# (HTML) Image width limit
|
# (HTML) Image width limit
|
||||||
|
|
||||||
From [image-width-limit.py](image-width-limit.py), function `limit_image_width`:
|
Add the style attribute `max-width:100%;height:25em;`
|
||||||
|
to image tags which only contain the `src` and `alt` attribute.
|
||||||
|
|
||||||
> When converting HTML5 to other formats, e.g. PDF, it
|
This prevents too large images from getting cropped off on the
|
||||||
may happen that too wide images get cropped of.
|
right (if too wide) or split up over multiple pages
|
||||||
>
|
(if too tall).
|
||||||
> If there are HTML5 image tags which do only contain
|
|
||||||
the 'src' and 'alt' attribute, then this method adds
|
|
||||||
the following style attribute to limit their width:
|
|
||||||
>
|
|
||||||
> max-width:100%;height:auto;
|
|
||||||
|
|
||||||
## Global Installation - Arch Linux
|
## Global Installation - Arch Linux
|
||||||
|
|
||||||
|
@ -46,6 +46,12 @@ def limit_image_width(html_str) -> str:
|
|||||||
|
|
||||||
max-width:100%;height:auto;
|
max-width:100%;height:auto;
|
||||||
|
|
||||||
|
Update: As images may also be to tall (and get split
|
||||||
|
up over multiple pages), here is an improved style
|
||||||
|
attribute:
|
||||||
|
|
||||||
|
max-width:100%;height:25em;
|
||||||
|
|
||||||
:param html_str: source HTML5 string
|
:param html_str: source HTML5 string
|
||||||
:returns: modified HTML5 with max-width attribute added to all img tags without size attributes
|
:returns: modified HTML5 with max-width attribute added to all img tags without size attributes
|
||||||
"""
|
"""
|
||||||
@ -73,7 +79,7 @@ def limit_image_width(html_str) -> str:
|
|||||||
# Sources:
|
# Sources:
|
||||||
# -> https://www.smashingmagazine.com/2020/03/setting-height-width-images-important-again/
|
# -> https://www.smashingmagazine.com/2020/03/setting-height-width-images-important-again/
|
||||||
# -> https://www.w3schools.com/tags/att_style.asp
|
# -> https://www.w3schools.com/tags/att_style.asp
|
||||||
attrs['style'] = 'max-width:100%;height:auto;'
|
attrs['style'] = 'max-width:100%;height:25em;'
|
||||||
|
|
||||||
# return soup.prettify()
|
# return soup.prettify()
|
||||||
return str(soup)
|
return str(soup)
|
||||||
|
Loading…
Reference in New Issue
Block a user