From 612cd8f8b4035903f8e51c1ad728ba190c9a24eb Mon Sep 17 00:00:00 2001 From: James Panther <4462786+jpanther@users.noreply.github.com> Date: Sun, 1 May 2022 11:17:30 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20code=20blocks=20in=20RTL?= =?UTF-8?q?=20languages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #164 --- CHANGELOG.md | 1 + assets/js/rtl.js | 3 +++ layouts/partials/head.html | 4 ++++ 3 files changed, 8 insertions(+) create mode 100644 assets/js/rtl.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e7b90e6..f7cae75f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Fixed +- Code blocks are rendered incorrectly in RTL languages ([#164](https://github.com/jpanther/congo/issues/164)) - Scroll to top link overlaps footer menu on mobile devices when there are several links ([#172](https://github.com/jpanther/congo/issues/172)) ### Removed diff --git a/assets/js/rtl.js b/assets/js/rtl.js new file mode 100644 index 00000000..26852d47 --- /dev/null +++ b/assets/js/rtl.js @@ -0,0 +1,3 @@ +window.addEventListener("DOMContentLoaded", (event) => { + document.querySelectorAll("pre, .highlight-wrapper").forEach((tag) => (tag.dir = "auto")); +}); diff --git a/layouts/partials/head.html b/layouts/partials/head.html index c78bd371..d36cda4f 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -62,6 +62,10 @@ {{ $jsCode := resources.Get "js/code.js" }} {{ $assets.Add "js" (slice $jsCode) }} {{ end }} + {{ if .Site.Params.rtl | default false }} + {{ $jsRTL := resources.Get "js/rtl.js" }} + {{ $assets.Add "js" (slice $jsRTL) }} + {{ end }} {{ if $assets.Get "js" }} {{ $bundleJS := $assets.Get "js" | resources.Concat "js/main.bundle.js" | resources.Minify | resources.Fingerprint "sha512" }}