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.
This commit is contained in:
Kumi 2024-08-19 17:16:43 +02:00
parent 4dfbd002f6
commit 04e3828f7e
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -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,
)