From ce7b86cccf9e7a56f496c763110d250b4a12b416 Mon Sep 17 00:00:00 2001 From: ArtOfCode- <hello@artofcode.co.uk> Date: Tue, 4 Aug 2020 17:25:15 +0100 Subject: [PATCH] Enable syntax highlighting --- app/assets/stylesheets/application.scss | 10 ++++++++++ app/views/layouts/_head.html.erb | 7 +++++++ db/seeds/site_settings.yml | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 48069d354..2aee5aad6 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -189,4 +189,14 @@ img { } .widget.is-tertiary .widget--body + .widget--header { border-top: 1px solid #9daeb7; +} + +pre { + background: #f0f0f0; + border: 0; +} + +pre .hljs { + padding: 0; + background: inherit; } \ No newline at end of file diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb index 7a67e3c69..88f294dd8 100644 --- a/app/views/layouts/_head.html.erb +++ b/app/views/layouts/_head.html.erb @@ -27,6 +27,13 @@ <%= javascript_include_tag 'application' %> <script src="https://unpkg.com/@codidact/co-design@0.12.0/js/co-design.js" defer></script> +<% if SiteSetting['SyntaxHighlightingEnabled'] %> + <link rel="stylesheet" + href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/styles/default.min.css"> + <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/highlight.min.js"></script> + <script defer>hljs.initHighlightingOnLoad();</script> +<% end %> + <% if SiteSetting['MathJaxEnabled'] %> <script> MathJax = { diff --git a/db/seeds/site_settings.yml b/db/seeds/site_settings.yml index af4f61dd4..70aaab87d 100644 --- a/db/seeds/site_settings.yml +++ b/db/seeds/site_settings.yml @@ -284,6 +284,14 @@ Enable MathJax on this site for math display. This will incur a small penalty in page loading times, so consider whether you really need it. +- name: SyntaxHighlightingEnabled + value: false + value_type: boolean + category: Display + description: > + Enable highlight.js syntax highlighting on this site. This incurs a small penalty in page loading times, so consider + whether you really need it. + - name: ScoringVariable value: 2 value_type: integer -- GitLab