~sircmpwn/core.sr.ht

f770406161e2f0d12d662fee935c52c8030c8a68 — Mehdi Sadeghi 7 months ago d24aa33 0.66.22
Delegate RTL direction handling to user-agents.

Check unicode RTL attrs for html content.

Reset global text-align.
2 files changed, 21 insertions(+), 1 deletions(-)

M srht/flask.py
M srht/scss/base.scss
M srht/flask.py => srht/flask.py +20 -1
@@ 1,4 1,5 @@
DATE_FORMAT = "%Y-%m-%dT%H:%M:%S+00:00"
from bs4 import BeautifulSoup
from flask import Flask, Response, request, url_for, render_template, redirect
from flask import Blueprint, current_app, g, abort, session as flask_session
from enum import Enum


@@ 35,6 36,7 @@ import secrets
import sqlalchemy.exc
import sqlalchemy.orm.exc
import sys
import unicodedata

class NamespacedSession:
    def __getitem__(self, key):


@@ 164,6 166,23 @@ def paginate_query(query, results_per_page=15):
        "total_results": total_results
    }

def inject_rtl_direction(resp):
    if resp.mimetype == 'text/html':
        html_doc = resp.data.decode('utf8')
        soup = BeautifulSoup(html_doc, 'html.parser')
        if not soup.body:
            return resp
        for el in soup.body.find_all():
            if el.name == 'input' or el.name == 'textarea':
                el.attrs['dir'] = "auto"
                continue
            for ch in el.text:
                if unicodedata.bidirectional(ch) in ('R', 'AL'):
                    el.attrs['dir'] = "auto"
                    break
        resp.data = soup.encode('utf8')
    return resp

class ModifiedUnicodeConverter(UnicodeConverter):
    """Added ~ and ^ to safe URL characters, otherwise no changes."""
    def to_url(self, value):


@@ 382,7 401,7 @@ class SrhtFlask(Flask):
                method=request.method,
                route=request.endpoint,
            ).observe(max(default_timer() - request._srht_start_time, 0))
            return resp
            return inject_rtl_direction(resp)

    def make_response(self, rv):
        # Converts responses from dicts to JSON response objects

M srht/scss/base.scss => srht/scss/base.scss +1 -0
@@ 32,6 32,7 @@ body {
  font-family: sans-serif;
  font-size: $base-font-size;
  padding-bottom: 1rem;
  text-align: initial;
}

@include media-breakpoint-down(md) {