Skip to content

Commit

Permalink
Fix rendering of only text containing elements
Browse files Browse the repository at this point in the history
  • Loading branch information
aaralh committed Dec 3, 2023
1 parent 37a5f79 commit 904698a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
1 change: 1 addition & 0 deletions browser/layouts/BlockLayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from browser.utils.logging import log
from web.dom.elements.Element import Element
from browser.styling.utils import style
from web.dom.elements.Text import Text

class BlockLayout(Layout):
def __init__(self, node: Element, parent: Layout, previous: Layout):
Expand Down
3 changes: 2 additions & 1 deletion browser/layouts/InlineLayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def text(self, element: Text) -> None:
if style == "normal": style = "roman"
size = int(float(element.style["font-size"][:-2]) * .75)
font = get_font(size, font_weight_to_string(weight), style)
for word in element.data.split():
data = element.data.strip()
for word in data.split():
w = font.measure(word)
if self.parent.float == "none":
if self.cursor_x + w > self.width - globals.HSTEP:
Expand Down
4 changes: 0 additions & 4 deletions browser/layouts/Layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ def layout_mode(self, node: Node) -> Literal["inline", "block"]:
if isinstance(child, Text): continue
if child.name in BLOCK_ELEMENTS:
mode = "block"

style_mode = node.style.get("display")
if style_mode in ["inline", "block"]:
mode = style_mode
return mode
else:
return "block"
Expand Down

0 comments on commit 904698a

Please sign in to comment.