From 04e3828f7ef6959f1ff0f9d23a35a23345765b05 Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 19 Aug 2024 17:16:43 +0200 Subject: [PATCH] fix: correctly handle 'ku-arab' script direction in articles Addressed an edge case where articles with the 'ku-arab' variant were displayed in left-to-right (LTR) direction despite being in Arabic script. Added logic to force right-to-left (RTL) direction for such cases, ensuring correct display. Resolves issue with incorrect article formatting. --- src/wikimore/app.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wikimore/app.py b/src/wikimore/app.py index d8bf5f4..a17faa0 100644 --- a/src/wikimore/app.py +++ b/src/wikimore/app.py @@ -241,11 +241,19 @@ def wiki_article(project, lang, title): li.decompose() processed_html = str(body) + + rtl = bool(soup.find("div", class_="mw-parser-output", dir="rtl")) + + # Edge case: When passing the `ku-arab` variant, the article is in Arabic + # script but the direction returned in the API response is still LTR. + if request.args.get("variant") == "ku-arab": + rtl = True + return render_template( "article.html", title=title.replace("_", " "), content=processed_html, - rtl=bool(soup.find("div", class_="mw-parser-output", dir="rtl")), + rtl=rtl, )