Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/css/doc.css
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,11 @@
display: flex;
visibility: hidden;
position: absolute;
top: 0.25rem;
/* move things up for more distance, original top: 0.25rem; */
top: -0.5rem;
right: 0.5rem;
color: var(--pre-annotation-font-color);
/* same color as in css/highlight.css hljs-built_in */
color: #0086b3;
font-family: var(--body-font-family);
font-size: calc(13.5 / var(--rem-base) * 1rem);
line-height: 1;
Expand Down Expand Up @@ -551,6 +553,13 @@
transition: none;
}

/* When using language console, a bash prompt (like > or $ or % or # or [test@ubuntu ~]$ ect.)
* will activate the meta css tag which prevents that the prompt being copied and pasted manually in the
* browser. This is also true for up to 3 leading blanks at the beginning and then a prompt symbol!
* Rule: if the text to highlight starts with a bash prompt, choose shell (or console),
* otherwise choose bash. If you use console but the line does not start with a bash prompt,
* highlighting will not work. Therefore check the language used carefully.
*/
.doc .language-console .hljs-meta {
user-select: none;
}
Expand Down
1 change: 1 addition & 0 deletions src/css/highlight.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*! GitHub style for highlight.js (c) Vasily Polovnyov <vast@whiteants.net> */

/*
.hljs {
display: block;
Expand Down
20 changes: 20 additions & 0 deletions src/js/vendor/highlight.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
;(function () {
'use strict'

// the following are additional keywords to be highlighted, particulary when using bash
const CUSTOM_KEYWORDS = ['occ', 'apt', 'apt-get', 'systemctl', 'service', 'sudo',
'dpkg', 'wget', 'tar', 'mysql', 'php', 'grep', 'pecl', 'pear', 'make',
'phpenmod', 'phpdismod', 'a2enmod', 'a2dismod', 'a2ensite', 'a2dissite'];

var hljs = (window.hljs = require('highlight.js/lib/core'))
hljs.registerLanguage('apache', require('highlight.js/lib/languages/apache'))
hljs.registerLanguage('asciidoc', require('highlight.js/lib/languages/asciidoc'))
Expand Down Expand Up @@ -38,6 +43,21 @@ var hljs = (window.hljs = require('highlight.js/lib/core'))
hljs.registerLanguage('swift', require('highlight.js/lib/languages/swift'))
hljs.registerLanguage('xml', require('highlight.js/lib/languages/xml'))
hljs.registerLanguage('yaml', require('highlight.js/lib/languages/yaml'))

/* Add the additional keywords to the bash language
* References: https://github.com/highlightjs/highlight.js/wiki/Adding-keywords-to-a-language-at-runtime
* Layout used and defined in highlight.css at .hljs-built_in
*/
hljs.getLanguage('bash').keywords.built_in.push(...CUSTOM_KEYWORDS);
// console.log(hljs.getLanguage('bash').keywords);

/* To eliminate the security messages in the browser telling:
* "One of your code blocks includes unescaped HTML. This is a potentially serious security risk"
* See: https://github.com/highlightjs/highlight.js/wiki/security
* A hljs command has been added in partials/footer-scripts.hbs
* hljs.configure({ ignoreUnescapedHTML: true })
* This is not a security issue for us as we have a static site

@xoxys xoxys Mar 1, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is simply not true. Someone could sneak in evil code in a docs PR, and it can get merged by someone who is not aware of this potential issue. Why not simply escape the HTML within code blocks as recommended? There is no real reason to disable security mechanisms.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks for the insight. I will open a new issue.

*/
;[].slice.call(document.querySelectorAll('pre code.hljs')).forEach(function (node) {
hljs.highlightElement(node)
})
Expand Down
1 change: 1 addition & 0 deletions src/partials/footer-scripts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
{{/if}}
<script src="{{uiRootPath}}/js/vendor/highlight.js"></script>
<script>hljs.highlightAll()</script>
<script>hljs.configure({ ignoreUnescapedHTML: true })</script>