Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Right-to-left text follows its own direction (#414)
Murtaza Nasirb91e0a99b541
diff --git a/src/utils/markdown.py b/src/utils/markdown.pyindex 8b55635e..f7a86495 100644--- a/src/utils/markdown.py+++ b/src/utils/markdown.py@@ -129,4 +129,15 @@ def md_to_html(text):html = _markdown_instance.convert(processed_text)# Apply sanitization to the generated HTML- return sanitize_html(html)+ return _with_auto_direction(sanitize_html(html))+++# Block elements that take their direction from their own text (#414): an+# Arabic, Hebrew, Persian or Urdu paragraph or list reads right to left, with+# its bullet on the right, while the rest of the summary stays left to right.+# Code stays left to right.+_AUTO_DIR_TAGS = re.compile(r'<(p|li|ul|ol|h[1-6]|blockquote|td|th|dt|dd)(?=[\s>])(?![^>]*\bdir=)')+++def _with_auto_direction(html):+ return _AUTO_DIR_TAGS.sub(r'<\1 dir="auto"', html)diff --git a/static/css/styles.css b/static/css/styles.cssindex 38ac3835..27e7a2f2 100644--- a/static/css/styles.css+++ b/static/css/styles.css@@ -4973,3 +4973,18 @@ select:disabled {.spk-modal .spk-seg-actions { grid-column: 3; grid-row: 1; }.spk-modal .spk-right { padding: var(--sp-3); }}+++/* Right-to-left text (#414). Each paragraph takes its direction from its+ first letter, so Arabic, Hebrew, Persian or Urdu aligns right inside the+ left-to-right interface, and a transcript or summary that switches+ language changes direction line by line. No language setting is needed. */+.speaker-text,+.speaker-bubble-content,+.transcript-segment,+.spk-seg-text,+.bidi-auto,+:is(.prose-flush, .prose, .summary-box, .notes-box, .notes-preview, .bidi-auto) :is(p, li, h1, h2, h3, h4, h5, h6, blockquote, td, th, dt, dd) {+ unicode-bidi: plaintext;+ text-align: start;+}diff --git a/templates/components/detail/desktop-transcription-panel.html b/templates/components/detail/desktop-transcription-panel.htmlindex 5df71c37..9746c871 100644--- a/templates/components/detail/desktop-transcription-panel.html+++ b/templates/components/detail/desktop-transcription-panel.html@@ -264,7 +264,7 @@</span>${segment.sentence}</div></div>- <div v-else class="whitespace-pre-wrap">+ <div v-else class="whitespace-pre-wrap bidi-auto">${processedTranscription.content}</div></div>diff --git a/templates/components/detail/floating-chat.html b/templates/components/detail/floating-chat.htmlindex 65f3b99a..04b71b04 100644--- a/templates/components/detail/floating-chat.html+++ b/templates/components/detail/floating-chat.html@@ -163,8 +163,8 @@<pre class="whitespace-pre-wrap font-mono">${message.thinking}</pre></div></div>- <div v-if="message.html" v-html="message.html"></div>- <div v-else class="whitespace-pre-wrap">${message.content}</div>+ <div v-if="message.html" class="bidi-auto" v-html="message.html"></div>+ <div v-else class="whitespace-pre-wrap bidi-auto">${message.content}</div></div><div v-if="isChatLoading" class="ai-message flex items-center gap-2">diff --git a/templates/components/detail/mobile-chat-panel.html b/templates/components/detail/mobile-chat-panel.htmlindex cf9d04fb..826e6ecc 100644--- a/templates/components/detail/mobile-chat-panel.html+++ b/templates/components/detail/mobile-chat-panel.html@@ -33,8 +33,8 @@</div></div><!-- Main message content -->- <div v-if="message.html" v-html="message.html"></div>- <div v-else class="whitespace-pre-wrap">${message.content}</div>+ <div v-if="message.html" class="bidi-auto" v-html="message.html"></div>+ <div v-else class="whitespace-pre-wrap bidi-auto">${message.content}</div></div><div v-if="isChatLoading" class="ai-message flex items-center gap-2"><div class="spinner"></div>diff --git a/templates/components/detail/mobile-transcript-panel.html b/templates/components/detail/mobile-transcript-panel.htmlindex 0695eafd..f409d5e2 100644--- a/templates/components/detail/mobile-transcript-panel.html+++ b/templates/components/detail/mobile-transcript-panel.html@@ -117,7 +117,7 @@<div v-if="processedTranscription.simpleSegments && processedTranscription.simpleSegments.length > 0"><div v-for="(segment, index) in processedTranscription.simpleSegments" :key="`seg-${index}-${segment.startTime}`" :class="['transcript-segment cursor-pointer hover:bg-[var(--bg-accent-hover)] p-2 rounded transition-colors', { 'active-playing-segment': currentPlayingSegmentIndex === index }]" @click="seekAudioFromEvent" @dblclick.stop="openAsrEditorAtSegment(index)" :data-start-time="segment.startTime" :data-segment-index="index"><span v-if="showTimestampsSimpleView" class="speaker-segment-timestamp speaker-segment-timestamp--inline">${ formatTimestamp(segment.startTime) }</span>${segment.sentence}</div></div>- <div v-else class="whitespace-pre-wrap">${processedTranscription.content}</div>+ <div v-else class="whitespace-pre-wrap bidi-auto">${processedTranscription.content}</div></div></div><div v-else-if="transcriptionViewMode === 'bubble'" class="transcription-with-speakers">diff --git a/templates/components/header.html b/templates/components/header.htmlindex 878ac3c6..34c7a78b 100644--- a/templates/components/header.html+++ b/templates/components/header.html@@ -46,6 +46,7 @@selectedRecording.is_shared ? 'text-[var(--text-accent)]' : 'text-[var(--text-primary)]',selectedRecording.can_edit !== false ? 'cursor-text hover:opacity-80' : '']"+ dir="auto":title="selectedRecording.title || 'Untitled Recording'">${selectedRecording.title || 'Untitled Recording'}</h1>diff --git a/templates/components/sidebar.html b/templates/components/sidebar.htmlindex f0dd8029..81909393 100644--- a/templates/components/sidebar.html+++ b/templates/components/sidebar.html@@ -441,7 +441,7 @@<!-- Title and Status Row --><div class="flex items-center justify-between mb-1":class="{ 'pr-7': selectionMode }">- <h4 class="font-medium text-sm truncate flex-1 mr-2" :class="selectedRecording?.id === recording.id && !selectionMode ? 'text-[var(--text-accent)]' : 'text-[var(--text-primary)]'">+ <h4 dir="auto" class="font-medium text-sm truncate flex-1 mr-2" :class="selectedRecording?.id === recording.id && !selectionMode ? 'text-[var(--text-accent)]' : 'text-[var(--text-primary)]'">${ recording.title || t('common.untitled') }</h4><div class="flex items-center gap-0.5 flex-shrink-0">diff --git a/templates/modals/asr-editor-modal.html b/templates/modals/asr-editor-modal.htmlindex 03dd7c6a..b1a4e0ce 100644--- a/templates/modals/asr-editor-modal.html+++ b/templates/modals/asr-editor-modal.html@@ -130,7 +130,7 @@<input type="number" step="0.01" v-model.number="editingSegments[segment._originalIndex].end_time" class="w-full px-3 py-2.5 bg-transparent border-0 focus:outline-none text-sm text-[var(--text-primary)] text-center" /></td><td class="border-r border-[var(--border-primary)] align-top">- <textarea v-model="editingSegments[segment._originalIndex].sentence" rows="1" class="w-full px-3 py-2.5 bg-transparent border-0 focus:outline-none text-sm text-[var(--text-primary)] resize-none max-h-20 overflow-y-auto custom-scrollbar block" @input="autoResizeTextarea($event)"></textarea>+ <textarea dir="auto" v-model="editingSegments[segment._originalIndex].sentence" rows="1" class="w-full px-3 py-2.5 bg-transparent border-0 focus:outline-none text-sm text-[var(--text-primary)] resize-none max-h-20 overflow-y-auto custom-scrollbar block" @input="autoResizeTextarea($event)"></textarea></td><td class="px-1 text-center align-middle"><div class="flex items-center justify-center gap-1">diff --git a/templates/modals/edit-modal.html b/templates/modals/edit-modal.htmlindex 4ad14f01..55b4def9 100644--- a/templates/modals/edit-modal.html+++ b/templates/modals/edit-modal.html@@ -26,7 +26,7 @@</div><div><label class="block text-sm font-medium mb-2" v-text="t('form.notes')"></label>- <textarea v-model="editingRecording.notes" rows="4" class="field" style="min-height: 96px;"></textarea>+ <textarea dir="auto" v-model="editingRecording.notes" rows="4" class="field" style="min-height: 96px;"></textarea></div></div><div class="modal-footer">diff --git a/templates/modals/edit-text-modal.html b/templates/modals/edit-text-modal.htmlindex b2530bb0..2c4eb412 100644--- a/templates/modals/edit-text-modal.html+++ b/templates/modals/edit-text-modal.html@@ -7,7 +7,7 @@</div><div class="modal-body"><label class="block text-sm font-medium text-[var(--text-secondary)] mb-2">Text Content</label>- <textarea v-model="editedText" rows="6" class="field" style="resize: vertical; min-height: 144px;" placeholder="Enter transcript text..."></textarea>+ <textarea dir="auto" v-model="editedText" rows="6" class="field" style="resize: vertical; min-height: 144px;" placeholder="Enter transcript text..."></textarea></div><div class="modal-footer"><button @click="closeEditTextModal" class="btn btn--ghost">${ t('buttons.cancel') }</button>diff --git a/templates/modals/text-editor-modal.html b/templates/modals/text-editor-modal.htmlindex 50ad589a..88d9b20c 100644--- a/templates/modals/text-editor-modal.html+++ b/templates/modals/text-editor-modal.html@@ -8,7 +8,7 @@<div class="modal-body"><div><label class="block text-sm font-medium mb-2" v-text="t('transcription.title')"></label>- <textarea v-model="editingTranscriptionContent" rows="15" class="field font-mono" style="min-height: 320px;"></textarea>+ <textarea dir="auto" v-model="editingTranscriptionContent" rows="15" class="field font-mono" style="min-height: 320px;"></textarea></div></div><div class="modal-footer">diff --git a/templates/share.html b/templates/share.htmlindex 0bcb8105..6c1c40a3 100644--- a/templates/share.html+++ b/templates/share.html@@ -295,7 +295,7 @@</div>{% else %}<!-- Plain Text View (for non-JSON transcriptions) -->- <div class="whitespace-pre-wrap cursor-pointer hover:bg-[var(--bg-accent-hover)] p-2 rounded transition-colors">{{ transcript.plain_text }}</div>+ <div class="whitespace-pre-wrap bidi-auto cursor-pointer hover:bg-[var(--bg-accent-hover)] p-2 rounded transition-colors">{{ transcript.plain_text }}</div>{% endif %}</div>{% else %}@@ -359,7 +359,7 @@</div><!-- Plain Text View (for non-JSON transcriptions) -->- <div v-if="!processedTranscription.isJson" class="whitespace-pre-wrap cursor-pointer hover:bg-[var(--bg-accent-hover)] p-2 rounded transition-colors">+ <div v-if="!processedTranscription.isJson" class="whitespace-pre-wrap bidi-auto cursor-pointer hover:bg-[var(--bg-accent-hover)] p-2 rounded transition-colors">${processedTranscription.content}</div></div>diff --git a/tests/test_rtl_text.py b/tests/test_rtl_text.pynew file mode 100644index 00000000..4b20f5ea--- /dev/null+++ b/tests/test_rtl_text.py@@ -0,0 +1,44 @@+"""Right-to-left text in summaries, notes and transcripts (#414).++Each block takes its direction from its own text: an Arabic, Hebrew,+Persian or Urdu paragraph reads right to left, with list bullets on the+right, and the rest stays left to right. Code stays left to right, and a+direction supplied in the text itself is still removed by the sanitizer.+"""++import os+import re+import sys++sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))++from src.utils.markdown import md_to_html++ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+++def test_blocks_take_their_direction_from_their_text():+ html = md_to_html("## خلاصہ\n\nٹیم نے بات کی۔\n\n- پہلا\n- Dan will send it.\n\n> نقل\n")+ for tag in ("h2", "p", "ul", "li", "blockquote"):+ assert re.search(rf'<{tag} dir="auto">', html), tag+++def test_code_and_tables_keep_their_shape():+ html = md_to_html("```\nx = 1\n```\n\n| a | b |\n|---|---|\n| 1 | 2 |\n")+ assert "<pre" in html and 'pre dir=' not in html and 'code dir=' not in html+ assert '<td dir="auto">1</td>' in html and '<table>' in html+++def test_a_direction_in_the_text_is_not_kept():+ html = md_to_html('<p dir="rtl" onclick="x()">hi</p>')+ assert 'dir="rtl"' not in html and "onclick" not in html+++def test_transcript_and_chat_text_follow_their_own_direction():+ css = open(os.path.join(ROOT, "static/css/styles.css")).read()+ rule = css[css.index("Right-to-left text (#414)"):]+ for selector in (".speaker-text", ".speaker-bubble-content", ".transcript-segment", ".bidi-auto"):+ assert selector in rule+ assert "unicode-bidi: plaintext" in rule and "text-align: start" in rule+ for path in ("templates/components/header.html", "templates/components/sidebar.html"):+ assert 'dir="auto"' in open(os.path.join(ROOT, path)).read(), path