From 61bdb663e0818f90714fd59e4980091b283ecd82 Mon Sep 17 00:00:00 2001 From: Thomas Hebb Date: Wed, 23 Aug 2023 14:51:12 -0400 Subject: [PATCH 1/3] Replace highlight.js with server-side Rouge highlighting Jekyll 3 and 4 process code blocks by default using Rouge[1], which adds s of various classes to the code indicating how different parts should be highlighted. So to highlight code, all a theme needs to do is include an appropriate stylesheet, which can be easily created for a variety of color schemes using Rouge's `rougify style` command. YAT, however, ignores the Rouge highlighting and instead includes highlight.js, which does its own highlighting client-side. That increases both bandwidth and client CPU usage for no clear benefit. Furthermore, it tries to guess a language if none is specified even if `guess_lang` is turned off in Jekyll's configuration, since `guess_lang` only affects Rouge. Let me know if there's a good reason to prefer highlight.js over Rouge, but to me it it just looks like extra complexity for no gain. As such, this change removes it and adds a Rouge stylesheet instead. [1] https://github.com/rouge-ruby/rouge --- README.md | 4 +- _config.yml | 16 +++- _includes/extensions/code-highlight.html | 14 +-- _sass/yat/_base.scss | 1 - _sass/yat/_dark.scss | 1 - assets/css/code-highlight-rouge.css | 112 +++++++++++++++++++++++ 6 files changed, 133 insertions(+), 15 deletions(-) create mode 100644 assets/css/code-highlight-rouge.css diff --git a/README.md b/README.md index 573b8c7e02a..2471415497d 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ I will respect your crucial support and say THANK YOU! - Full layouts `home`, `post`, `tags`, `archive` and `about`. - Uses font awesome 5 for icons. - Beautiful page banner with image and video. -- Beautiful Syntax Highlight using [highlight.js][highlight-js]. +- Beautiful Syntax Highlight with overridable [Rouge][rouge] themes. - RSS support using [Jekyll Feed][jekyll-feed] gem. - Optimized for search engines using [Jekyll Seo Tag][jekyll-seo-tag] gem. - Sitemap support using [Jekyll Sitemap][jekyll-sitemap] gem. @@ -197,4 +197,4 @@ This theme is licensed under the [MIT license](https://opensource.org/licenses/m [jekyll-seo-tag]: https://github.com/jekyll/jekyll-seo-tag [jekyll-sitemap]: https://github.com/jekyll/jekyll-sitemap [jekyll-feed]: https://github.com/jekyll/jekyll-feed -[highlight-js]: https://github.com/highlightjs/highlight.js +[rouge]: https://github.com/rouge-ruby/rouge diff --git a/_config.yml b/_config.yml index 9724c6b9f5c..e1b138d0cee 100644 --- a/_config.yml +++ b/_config.yml @@ -150,6 +150,21 @@ yat: # background_color: "#ff4e00" # text_transform: "uppercase" # ("uppercase", "lowercase", "capitalize") +# Code highlighting setting +# This is a Jekyll setting rather than a theme setting, but the theme includes +# stylesheets to highlight code when the Rouge highlighter (the default) is in +# use. This setting affects both Markdown code blocks and Liquid `highlight` +# blocks. You can set it to `none` to disable highlighting. +# +# By default, we highlight code with Rouge's "github.light" theme. If you want +# to change that, you can override `assets/css/code-highlight-rouge.css` with a +# different stylesheet generated with Rouge's `rougify` command. If you do so, +# you must set the CSS scope to `.highlight pre` for proper rendering: +# +# $ mkdir -p assets/css +# $ bundle exec rougify style --scope '.highlight pre' >assets/css/code-highlight-rouge.css +# highlighter: rouge + # If you want to link only specific pages in your header, uncomment # this and add the path to the pages in order as they should show up # header_pages: @@ -233,7 +248,6 @@ yat: # follow_site_theme: true # Build settings -# highlighter: none markdown: kramdown kramdown: input: GFM diff --git a/_includes/extensions/code-highlight.html b/_includes/extensions/code-highlight.html index b7c6399f15c..f2750d8940c 100644 --- a/_includes/extensions/code-highlight.html +++ b/_includes/extensions/code-highlight.html @@ -1,9 +1,4 @@ - - - - + {%- assign name = 'code_badge.enabled' -%} {%- include functions.html func='get_value' default='true' -%} @@ -21,8 +16,8 @@ {%- include functions.html func='get_value' default='uppercase' -%} {%- assign badge_text_transform = return -%} +{%- if badge_enabled -%} {%- endif -%} diff --git a/_sass/yat/_base.scss b/_sass/yat/_base.scss index be1f842e5e6..e12dc36c171 100644 --- a/_sass/yat/_base.scss +++ b/_sass/yat/_base.scss @@ -157,15 +157,8 @@ code { pre { overflow-x: auto; - position: relative; background-color: #f0f0f0; - - > code { - display: inline-block; - padding: 20px!important; - background-color: transparent; - border: 0; - } + padding: 20px; table, pre { margin-bottom: 0;