mod: настройки типографа (08) оформление

This commit is contained in:
2026-01-03 01:24:36 +03:00
parent 64bc1b1d33
commit 1167f07904
3 changed files with 138 additions and 92 deletions

View File

@@ -2,6 +2,7 @@ from django.shortcuts import render
from django.http import HttpResponse
from etpgrf.typograph import Typographer
from etpgrf.layout import LayoutProcessor
from etpgrf.hyphenation import Hyphenator
def index(request):
return render(request, template_name='typograph/index.html')
@@ -15,40 +16,50 @@ def process_text(request):
# 2. Собираем LayoutProcessor
layout_enabled = request.POST.get('layout') == 'on'
layout_option = False # По умолчанию выключен
layout_option = False
if layout_enabled:
# Обработка единиц измерения
process_units = request.POST.get('layout_units') == 'on'
if process_units:
# Если включено, проверяем кастомные единицы
custom_units = request.POST.get('layout_units_custom', '').strip()
if custom_units:
# Если есть кастомные, передаем их списком (библиотека сама объединит с дефолтными)
process_units = custom_units.split()
# Если включен, создаем процессор с тонкими настройками
layout_option = LayoutProcessor(
langs=langs,
process_initials_and_acronyms=request.POST.get('layout_initials') == 'on',
process_units=process_units
)
# 3. Читаем Sanitizer
# 3. Собираем Hyphenator
hyphenation_enabled = request.POST.get('hyphenation') == 'on'
hyphenation_option = False
if hyphenation_enabled:
max_len = request.POST.get('hyphenation_len', '15')
try:
max_len = int(max_len)
except (ValueError, TypeError):
max_len = 15 # Дефолтное значение, если пришло что-то не то
hyphenation_option = Hyphenator(
langs=langs,
max_unhyphenated_len=max_len
)
# 4. Читаем Sanitizer
sanitizer_val = request.POST.get('sanitizer', '')
sanitizer_option = None
if sanitizer_val:
sanitizer_option = sanitizer_val # 'etp' или 'html'
sanitizer_option = sanitizer_val
# 4. Собираем общие опции
# 5. Собираем общие опции
options = {
'langs': langs,
'process_html': True,
'quotes': request.POST.get('quotes') == 'on',
'layout': layout_option, # Передаем объект или False
'layout': layout_option,
'unbreakables': request.POST.get('unbreakables') == 'on',
'hyphenation': request.POST.get('hyphenation') == 'on',
'hyphenation': hyphenation_option,
'symbols': request.POST.get('symbols') == 'on',
'hanging_punctuation': request.POST.get(key='hanging_punctuation', default='none'),