diff --git a/config.toml b/config.toml index 078dba9ed..b39f191ee 100644 --- a/config.toml +++ b/config.toml @@ -134,6 +134,11 @@ copy_button = true # Can be set at page or section levels, following the hierarchy: page > section > config. See: https://welpo.github.io/tabi/blog/mastering-tabi-settings/#settings-hierarchy add_src_to_code_block = false +# Force left-to-right (LTR) direction for code blocks. +# Set to false to allow code to follow the document's natural direction. +# Can be set at page or section levels. See: https://welpo.github.io/tabi/blog/mastering-tabi-settings/#settings-hierarchy +force_codeblock_ltr = true + # Show the author(s) of a page. # Can be set at page or section levels, following the hierarchy: page > section > config. See: https://welpo.github.io/tabi/blog/mastering-tabi-settings/#settings-hierarchy show_author = false diff --git a/content/blog/mastering-tabi-settings/index.ca.md b/content/blog/mastering-tabi-settings/index.ca.md index 9237891d6..6bc2a356e 100644 --- a/content/blog/mastering-tabi-settings/index.ca.md +++ b/content/blog/mastering-tabi-settings/index.ca.md @@ -581,6 +581,14 @@ Establir `copy_button = true` afegirà un petit botó de copiar a la part superi Estableix `add_src_to_code_block = true` per habilitar l'ús del [shortcode `add_src_to_code_block`](@/blog/shortcodes/index.ca.md#mostrar-ruta-o-url). +### Forçar blocs de codi d'esquerra a dreta + +| Pàgina | Secció | `config.toml` | Segueix la jerarquia | Requereix JavaScript | +|:------:|:------:|:-------------:|:-----------------:|:--------------------:| +| ✅ | ✅ | ✅ | ✅ | ❌ | + +Per defecte, els blocs de codi es renderitzen d'esquerra a dreta, independentment de la direcció general del text. Estableix `force_codeblock_ltr = false` per permetre que els blocs de codi segueixin la direcció del document. Útil per a idiomes de dreta a esquerra que necessiten blocs de codi de dreta a esquerra. + ### Suport per a KaTeX | Pàgina | Secció | `config.toml` | Segueix la jerarquia | Requereix JavaScript | diff --git a/content/blog/mastering-tabi-settings/index.es.md b/content/blog/mastering-tabi-settings/index.es.md index ce5a92914..298b4f079 100644 --- a/content/blog/mastering-tabi-settings/index.es.md +++ b/content/blog/mastering-tabi-settings/index.es.md @@ -581,6 +581,14 @@ Establecer `copy_button = true` añadirá un pequeño botón de copiar en la par Establece `add_src_to_code_block = true` para habilitar el uso del [shortcode `add_src_to_code_block`](@/blog/shortcodes/index.es.md#mostrar-ruta-o-url). +### Forzar bloques de código de izquierda a derecha + +| Página | Sección | `config.toml` | Sigue la jerarquía | Requiere JavaScript | +|:------:|:-------:|:-------------:|:----------------:|:-------------------:| +| ✅ | ✅ | ✅ | ✅ | ❌ | + +Por defecto, los bloques de código se renderizan de izquierda a derecha, independientemente de la dirección general del texto. Establece `force_codeblock_ltr = false` para permitir que los bloques de código sigan la dirección del documento. Útil para idiomas de derecha a izquierda que necesitan bloques de código de derecha a izquierda. + ### Soporte para KaTeX | Página | Sección | `config.toml` | Sigue la jerarquía | Requiere JavaScript | diff --git a/content/blog/mastering-tabi-settings/index.md b/content/blog/mastering-tabi-settings/index.md index ce4ce6d8e..ffc5805b2 100644 --- a/content/blog/mastering-tabi-settings/index.md +++ b/content/blog/mastering-tabi-settings/index.md @@ -591,6 +591,14 @@ Setting `copy_button = true` will add a small copy button to the top right of co Setting `add_src_to_code_block = true` enables the use of the [`add_src_to_code_block` shortcode](@/blog/shortcodes/index.md#show-source-or-path). +### Force Code Blocks LTR + +| Page | Section | `config.toml` | Follows Hierarchy | Requires JavaScript | +|:----:|:-------:|:-------------:|:-----------------:|:-------------------:| +| ✅ | ✅ | ✅ | ✅ | ❌ | + +By default, code blocks are rendered left-to-right, regardless of the overall text direction. Set `force_codeblock_ltr = false` to allow code blocks to follow the document's text direction. Useful for RTL languages needing RTL code blocks. + ### KaTeX Support | Page | Section | `config.toml` | Follows Hierarchy | Requires JavaScript | diff --git a/sass/parts/_code.scss b/sass/parts/_code.scss index 3940997da..1d090ceab 100644 --- a/sass/parts/_code.scss +++ b/sass/parts/_code.scss @@ -101,6 +101,18 @@ pre { } } +// Default to LTR codeblocks. +code, pre { + direction: ltr; +} + +// Allows RTL codeblocks if `force_codeblock_ltr` is set to false. +html[data-code-direction="inherit"] { + code, pre { + direction: inherit; + } +} + .copy-code { -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 -960 960 960' %3E%3Cpath d='M217.002-67.694q-37.732 0-64.02-26.288-26.287-26.287-26.287-64.019V-707.69h77.999v549.689q0 4.615 3.846 8.462 3.846 3.846 8.462 3.846h451.689v77.999H217.002Zm175.999-175.999q-37.733 0-64.02-26.287T302.694-334v-463.383q0-37.732 26.287-64.02 26.287-26.287 64.02-26.287h365.383q37.732 0 64.019 26.287 26.288 26.288 26.288 64.02V-334q0 37.733-26.288 64.02-26.287 26.287-64.019 26.287H393.001Zm0-77.998h365.383q4.615 0 8.462-3.847 3.846-3.846 3.846-8.462v-463.383q0-4.616-3.846-8.462-3.847-3.846-8.462-3.846H393.001q-4.616 0-8.462 3.846-3.847 3.846-3.847 8.462V-334q0 4.616 3.847 8.462 3.846 3.847 8.462 3.847Zm-12.309 0v-488V-321.691Z'/%3E%3C/svg%3E"); position: absolute; diff --git a/templates/base.html b/templates/base.html index 73145497a..6db8bfd79 100644 --- a/templates/base.html +++ b/templates/base.html @@ -15,11 +15,18 @@ {%- endif -%} {% set rtl_languages = ["ar", "arc", "az", "dv", "ff", "he", "ku", "nqo", "fa", "rhg", "syc", "ur"] %} +{#- Necessary for the hierarchy macro -#} +{%- if page -%} + {%- set current_page = page -%} +{%- else -%} + {%- set current_page = ""-%} +{%- endif -%} +{%- endif -%}{% if macros_settings::evaluate_setting_priority(setting="force_codeblock_ltr", page=current_page, default_global_value=true) == "false" -%} + data-code-direction="inherit"{% endif %}> {% include "partials/header.html" %} diff --git a/templates/page.html b/templates/page.html index 051353067..969baa0fc 100644 --- a/templates/page.html +++ b/templates/page.html @@ -63,6 +63,7 @@ {% set settings_to_test = [ "footnote_backlinks", "add_src_to_code_block", + "force_codeblock_ltr", "copy_button", "katex", "quick_navigation_buttons", diff --git a/theme.toml b/theme.toml index 4b1b57e61..3a8bca202 100644 --- a/theme.toml +++ b/theme.toml @@ -91,6 +91,11 @@ copy_button = true # Can be set at page or section levels, following the hierarchy: page > section > config. See: https://welpo.github.io/tabi/blog/mastering-tabi-settings/#settings-hierarchy add_src_to_code_block = false +# Force left-to-right (LTR) direction for code blocks. +# Set to false to allow code to follow the document's natural direction. +# Can be set at page or section levels. See: https://welpo.github.io/tabi/blog/mastering-tabi-settings/#settings-hierarchy +force_codeblock_ltr = true + # Show the author(s) of a page. # Can be set at page or section levels, following the hierarchy: page > section > config. See: https://welpo.github.io/tabi/blog/mastering-tabi-settings/#settings-hierarchy show_author = false