Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve block conversion #59

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ Changelog
3.1.3 (unreleased)
------------------

- Handle text-larger class in slate2html.
[cekk]
- Do not pretty slate2html output to avoid not needed spaces between tags.
[cekk]
- Changed label from Parametro to Dato.
[eikichi18]


3.1.2 (2024-12-05)
------------------

Expand Down
6 changes: 4 additions & 2 deletions src/rer/newsletter/blocks_converter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def __call__(self, context, blocks, blocks_layout):
if value:
html.append(value)
root = "".join(html)
soup = bs(root, "html.parser") # make BeautifulSoup
return soup.prettify() # prettify the html

# soup = bs(root, "html.parser") # make BeautifulSoup
# return soup.prettify() # prettify the html
return root

def get_blocks(self, context, blocks, blocks_layout):
"""
Expand Down
17 changes: 11 additions & 6 deletions src/rer/newsletter/blocks_converter/slate2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@ def serialize(self, element):
:param element:
"""
if "text" in element:
if "\n" not in element["text"]:
return [element["text"]]

return join(E.BR, element["text"].split("\n"))
text_elements = element["text"].split("\n")
if element.get("style-text-larger", False):
text_elements = [
E.SPAN(
x,
**{"class": "text-larger"},
)
for x in text_elements
]

return join(E.BR, text_elements)

if element["type"] == "paragraph":
element["type"] = "p"
tagname = element["type"]

if element.get("data") and tagname not in SLATE_ACCEPTED_TAGS:
handler = self.handle_slate_data_element
else:
Expand Down Expand Up @@ -73,7 +79,6 @@ def handle_tag_link(self, element):
children = []
for child in element["children"]:
children += self.serialize(child)

return el(*children, **attributes)

def handle_slate_data_element(self, element):
Expand Down
3 changes: 3 additions & 0 deletions src/rer/newsletter/browser/message/messagepreview.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#footer {
clear: both;
}
.text-larger {
font-size: 1.75em;
}
"""


Expand Down
Loading