From d790b0b17ae9801fee1a4601552a68dee95b0556 Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 19 Sep 2024 14:19:20 +0200 Subject: [PATCH] feat: enhance content type handling and code styling - Added 'type' attribute to the Text dataclass to support HTML tag designation. - Trimmed text content and assigned types in MediumClient to improve consistency. - Updated article template to dynamically use text types, allowing for more flexible HTML structure. - Applied CSS styling for 'pre' tags to enhance code block appearance. These changes improve the semantic structure of articles and enhance the visual presentation of code blocks in the user interface. --- src/small/models/nodes.py | 1 + src/small/services/medium_client.py | 2 +- src/small/static/css/style.css | 7 +++++++ src/small/templates/article.html | 6 ++++-- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/small/models/nodes.py b/src/small/models/nodes.py index ce84463..50b5f00 100644 --- a/src/small/models/nodes.py +++ b/src/small/models/nodes.py @@ -5,6 +5,7 @@ from typing import List, Union @dataclass class Text: content: str + type: str @dataclass diff --git a/src/small/services/medium_client.py b/src/small/services/medium_client.py index 493abc1..90444ec 100644 --- a/src/small/services/medium_client.py +++ b/src/small/services/medium_client.py @@ -58,7 +58,7 @@ class MediumClient: ) ] else: - children = [Text(content=p["text"])] + children = [Text(content=p["text"].strip(), type=p["type"])] paragraphs.append(Paragraph(children=children)) return Page( diff --git a/src/small/static/css/style.css b/src/small/static/css/style.css index f0e4aa5..c21ffc9 100644 --- a/src/small/static/css/style.css +++ b/src/small/static/css/style.css @@ -72,6 +72,13 @@ article img { margin: 20px 0; } +pre { + background-color: #f4f4f4; + padding: 10px; + border-left: 3px solid #1a73e8; + overflow-x: auto; +} + /* Error Page Styles */ .error-container { text-align: center; diff --git a/src/small/templates/article.html b/src/small/templates/article.html index c374ca7..e92a035 100644 --- a/src/small/templates/article.html +++ b/src/small/templates/article.html @@ -7,15 +7,17 @@

By {{ page.author }} on {{ page.created_at }}

{% for paragraph in page.content %} -

{% for child in paragraph.children %} {% if child.__class__.__name__ == 'Text' %} + <{{ child.type | lower }}> {{ child.content }} + {% elif child.__class__.__name__ == 'Image' %} +

{{ child.alt }} +

{% endif %} {% endfor %} -

{% endfor %}
{% endblock %}