mod: настройки типографа (06) режимы layout

This commit is contained in:
2026-01-02 20:11:12 +03:00
parent 75ef076e14
commit 8636b7854c
2 changed files with 33 additions and 10 deletions

View File

@@ -7,8 +7,7 @@
<form hx-post="{% url 'process_text' %}" hx-target="#result-area" hx-swap="innerHTML"> <form hx-post="{% url 'process_text' %}" hx-target="#result-area" hx-swap="innerHTML">
{% csrf_token %} {% csrf_token %}
<!-- Поле ввода --> {# ГЛАВНОЕ ПОЛЕ ВВОДА: ТЕКСТ ДЛЯ ФОТОГРАФИРОВАНИЯ #}<div class="mb-3">
<div class="mb-3">
<textarea class="form-control" name="text" rows="10" placeholder="Вставьте текст сюда..."></textarea> <textarea class="form-control" name="text" rows="10" placeholder="Вставьте текст сюда..."></textarea>
</div> </div>
@@ -55,24 +54,39 @@
<label class="form-check-label fw-bold" for="optQuotes">Обработка кавычек</label> <label class="form-check-label fw-bold" for="optQuotes">Обработка кавычек</label>
</div> </div>
<!-- Группа "Знаки и отбивка" (Layout) --> {# Группа "Компоновка и отбивка" (Layout) #}<div x-data="{ enabled: true }" class="mb-2">
<div x-data="{ enabled: true }" class="mb-2">
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" name="layout" id="optLayout" checked x-model="enabled"> <input class="form-check-input" type="checkbox" name="layout" id="optLayout" checked x-model="enabled">
<label class="form-check-label fw-bold" for="optLayout">Компоновка и&nbsp;отбивка</label> <label class="form-check-label fw-bold" for="optLayout">Компоновка и&nbsp;отбивка</label>
</div> </div>
<div class="ms-3">
<!-- Настройки (видны, когда включено) -->
<div class="ms-3" x-show="enabled" x-transition>
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" name="layout_initials" id="optLayoutInitials" checked :disabled="!enabled"> <input class="form-check-input" type="checkbox" name="layout_initials" id="optLayoutInitials" checked>
<label class="form-check-label" for="optLayoutInitials">Инициалы <small class="text-muted">(А.&thinsp;С.&thinsp;Пушкин) и акронимы записанные через точку (U.&thinsp;S.&thinsp;S.)</small></label> <label class="form-check-label" for="optLayoutInitials">Инициалы <small class="text-muted">(А.&thinsp;С.&thinsp;Пушкин)</small></label>
</div> </div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="layout_units" id="optLayoutUnits" checked :disabled="!enabled"> <!-- Единицы измерения с кастомным полем -->
<div x-data="{ unitsEnabled: true }" class="form-check">
<input class="form-check-input" type="checkbox" name="layout_units" id="optLayoutUnits" checked
x-model="unitsEnabled">
<label class="form-check-label" for="optLayoutUnits">Единицы измерения <small class="text-muted">(10&thinsp;км)</small></label> <label class="form-check-label" for="optLayoutUnits">Единицы измерения <small class="text-muted">(10&thinsp;км)</small></label>
<!-- Поле для кастомных единиц -->
<div class="mt-1" x-show="unitsEnabled" x-transition>
<input type="text" class="form-control form-control-sm" name="layout_units_custom"
placeholder="Доп. единицы (через пробел): бит байт">
</div> </div>
</div> </div>
</div> </div>
<!-- Описание (видно, когда выключено) -->
<div class="ms-3 form-text text-muted small" x-show="!enabled" x-transition>
Обработка тире, чисел, инициалов, сокращений и единиц измерения отключена.
</div>
</div>
<div class="form-check mb-2"> <div class="form-check mb-2">
<input class="form-check-input" type="checkbox" name="unbreakables" id="optUnbreakables" checked> <input class="form-check-input" type="checkbox" name="unbreakables" id="optUnbreakables" checked>
<label class="form-check-label" for="optUnbreakables">Неразрывные пробелы</label> <label class="form-check-label" for="optUnbreakables">Неразрывные пробелы</label>

View File

@@ -18,11 +18,20 @@ def process_text(request):
layout_option = False # По умолчанию выключен layout_option = False # По умолчанию выключен
if layout_enabled: 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( layout_option = LayoutProcessor(
langs=langs, langs=langs,
process_initials_and_acronyms=request.POST.get('layout_initials') == 'on', process_initials_and_acronyms=request.POST.get('layout_initials') == 'on',
process_units=request.POST.get('layout_units') == 'on' process_units=process_units
) )
# 3. Читаем Sanitizer # 3. Читаем Sanitizer