Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Highlight.js syntax highlighting #230

Merged
merged 12 commits into from
Feb 21, 2025
6 changes: 6 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const dotenv = require('dotenv');
const express = require('express');
const nunjucks = require('nunjucks');
const sessionInMemory = require('express-session');
const highlightjs = require('highlight.js');

// Run before other code to make sure variables from .env are available
dotenv.config();
Expand Down Expand Up @@ -65,6 +66,11 @@ nunjucksConfig.express = app;
const nunjucksAppEnv = nunjucks.configure(appViews, nunjucksConfig);
nunjucksAppEnv.addGlobal('version', packageInfo.version);

nunjucksAppEnv.addFilter('highlight', (code, language) => {
const languages = language ? [language] : false;
return highlightjs.highlightAuto(code.trim(), languages).value;
});

// Add Nunjucks filters
utils.addNunjucksFilters(nunjucksAppEnv);

Expand Down
7 changes: 0 additions & 7 deletions app/assets/javascript/prism.js

This file was deleted.

8 changes: 8 additions & 0 deletions app/assets/sass/components/_code-snippet.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Code snippet
.app-code-snippet {
background-color: $color_nhsuk-white;
border: 1px solid $nhsuk-border-color;
overflow: auto;
padding: nhsuk-spacing(1) nhsuk-spacing(3);
margin-bottom: nhsuk-spacing(3);
}
27 changes: 0 additions & 27 deletions app/assets/sass/docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,6 @@
background-color: $color_nhsuk-grey-4 !important;
}

// <pre> and <code> tag styles
.app-pre {
@include nhsuk-responsive-margin(4, "bottom");

background: $color_nhsuk-white;
border: 1px solid $nhsuk-border-color;
overflow: auto;
margin-top: 0;
padding: nhsuk-spacing(3);
position: relative;
}

li .app-code,
p .app-code {
background: $color_nhsuk-white;
border: 1px solid $nhsuk-border-color;
padding: nhsuk-spacing(1) nhsuk-spacing(3);
font-size: 0.8em;
}

.nhsuk-expander .app-pre,
.nhsuk-expander p .app-code,
.nhsuk-expander li .app-code {
background: $color_nhsuk-grey-5;
border: 1px solid $color_nhsuk-grey-4;
}

// Installation guide screenshots
.app-img-guide {
width: 100%;
Expand Down
5 changes: 5 additions & 0 deletions app/assets/sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

// Components that are not in the NHS.UK frontend library
@import 'components/figure';
@import 'components/code-snippet';

@import 'styles/code';
@import 'styles/highlight';


///////////////////////////////////////////
// Add your custom CSS/Sass styles below...
Expand Down
140 changes: 0 additions & 140 deletions app/assets/sass/prism.scss

This file was deleted.

9 changes: 9 additions & 0 deletions app/assets/sass/styles/_code.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Highlight code within body copy
// This uses the same styling as on the NHS Service Manual
p code,
li code {
background-color: $color_nhsuk-white;
color: #d14;
padding: 2px nhsuk-spacing(2);
word-break: break-word;
}
Loading
Loading