mod: настройки типографа (05) режимы layout
This commit is contained in:
@@ -26,7 +26,6 @@
|
||||
<h6>Основные</h6>
|
||||
|
||||
<!-- Выбор языка (Alpine.js) -->
|
||||
<!-- x-data инициализирует состояние. Берем описание первой опции сразу. -->
|
||||
<div
|
||||
x-data="{ desc: 'Только русская типографика: кавычки «ёлочки» („вложенные“); длинное тире (—) с пробелами; «прилипающие» союзы и предлоги только для русского языка, переносы слов и т. д.' }">
|
||||
<label class="form-label small text-muted mb-0">Язык:</label>
|
||||
@@ -48,18 +47,32 @@
|
||||
Русский
|
||||
</option>
|
||||
</select>
|
||||
<!-- Вывод описания (x-html для рендеринга тегов) -->
|
||||
<div class="form-text text-muted small mb-2" style="min-height: 2.5em;" x-html="desc"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="quotes" id="optQuotes" checked>
|
||||
<label class="form-check-label" for="optQuotes">Обработка кавычек</label>
|
||||
<label class="form-check-label fw-bold" for="optQuotes">Обработка кавычек</label>
|
||||
</div>
|
||||
|
||||
<!-- Группа "Знаки и отбивка" (Layout) -->
|
||||
<div x-data="{ enabled: true }" class="mb-2">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="layout" id="optLayout" checked x-model="enabled">
|
||||
<label class="form-check-label fw-bold" for="optLayout">Компоновка и отбивка</label>
|
||||
</div>
|
||||
<div class="ms-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="layout_initials" id="optLayoutInitials" checked :disabled="!enabled">
|
||||
<label class="form-check-label" for="optLayoutInitials">Инициалы <small class="text-muted">(А. С. Пушкин) и акронимы записанные через точку (U. S. S.)</small></label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="layout" id="optLayout" checked>
|
||||
<label class="form-check-label" for="optLayout">Тире и спецсимволы</label>
|
||||
<input class="form-check-input" type="checkbox" name="layout_units" id="optLayoutUnits" checked :disabled="!enabled">
|
||||
<label class="form-check-label" for="optLayoutUnits">Единицы измерения <small class="text-muted">(10 км)</small></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="checkbox" name="unbreakables" id="optUnbreakables" checked>
|
||||
<label class="form-check-label" for="optUnbreakables">Неразрывные пробелы</label>
|
||||
@@ -84,7 +97,6 @@
|
||||
Мнемоники (&nbsp;)
|
||||
</option>
|
||||
</select>
|
||||
<!-- Вывод описания (x-html для рендеринга тегов) -->
|
||||
<div class="form-text text-muted small mb-2" style="min-height: 2.5em;" x-html="desc"></div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -99,6 +111,16 @@
|
||||
<input class="form-check-input" type="checkbox" name="symbols" id="optSymbols" checked>
|
||||
<label class="form-check-label" for="optSymbols">Символы ((c) → ©)</label>
|
||||
</div>
|
||||
|
||||
<!-- Санитайзер -->
|
||||
<div class="mt-3">
|
||||
<label class="form-label small text-muted mb-0">Очистка (Sanitizer):</label>
|
||||
<select class="form-select form-select-sm" name="sanitizer">
|
||||
<option value="" selected>Без очистки</option>
|
||||
<option value="etp">Удалить старую типографику</option>
|
||||
<option value="html">Удалить все HTML-теги</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
# Импортируем напрямую из пакета etpgrf, который лежит в корне проекта
|
||||
from etpgrf.typograph import Typographer
|
||||
from etpgrf.layout import LayoutProcessor
|
||||
|
||||
def index(request):
|
||||
return render(request, template_name='typograph/index.html')
|
||||
@@ -10,21 +10,42 @@ def process_text(request):
|
||||
if request.method == 'POST':
|
||||
text = request.POST.get(key='text', default='')
|
||||
|
||||
# Собираем настройки из формы
|
||||
options = {
|
||||
# Выпадающие списки
|
||||
'langs': request.POST.get(key='langs', default='ru'),
|
||||
'hanging_punctuation': request.POST.get(key='hanging_punctuation', default='both'),
|
||||
'mode': request.POST.get(key='mode', default='mixed'),
|
||||
# 1. Читаем базовые настройки
|
||||
langs = request.POST.get(key='langs', default='ru')
|
||||
|
||||
# 2. Собираем LayoutProcessor
|
||||
layout_enabled = request.POST.get('layout') == 'on'
|
||||
layout_option = False # По умолчанию выключен
|
||||
|
||||
if layout_enabled:
|
||||
# Если включен, создаем процессор с тонкими настройками
|
||||
layout_option = LayoutProcessor(
|
||||
langs=langs,
|
||||
process_initials_and_acronyms=request.POST.get('layout_initials') == 'on',
|
||||
process_units=request.POST.get('layout_units') == 'on'
|
||||
)
|
||||
|
||||
# 3. Читаем Sanitizer
|
||||
sanitizer_val = request.POST.get('sanitizer', '')
|
||||
sanitizer_option = None
|
||||
if sanitizer_val:
|
||||
sanitizer_option = sanitizer_val # 'etp' или 'html'
|
||||
|
||||
# 4. Собираем общие опции
|
||||
options = {
|
||||
'langs': langs,
|
||||
'process_html': True,
|
||||
|
||||
# Чекбоксы
|
||||
'quotes': request.POST.get('quotes') == 'on',
|
||||
'layout': request.POST.get('layout') == 'on',
|
||||
'layout': layout_option, # Передаем объект или False
|
||||
'unbreakables': request.POST.get('unbreakables') == 'on',
|
||||
'hyphenation': request.POST.get('hyphenation') == 'on',
|
||||
'symbols': request.POST.get('symbols') == 'on',
|
||||
|
||||
'hanging_punctuation': request.POST.get(key='hanging_punctuation', default='none'),
|
||||
'mode': request.POST.get(key='mode', default='mixed'),
|
||||
|
||||
'sanitizer': sanitizer_option
|
||||
}
|
||||
|
||||
if options['hanging_punctuation'] == 'none':
|
||||
@@ -36,7 +57,6 @@ def process_text(request):
|
||||
# Обрабатываем текст
|
||||
processed = typo.process(text)
|
||||
|
||||
# Возвращаем фрагмент с явным указанием аргументов
|
||||
return render(
|
||||
request,
|
||||
template_name='typograph/result_fragment.html',
|
||||
|
||||
Reference in New Issue
Block a user