syntax-highlighting

Add syntax highlight to code blocks on the REAPER forum

Skript installieren?
Vom Ersteller vorgeschlagenes Skript

Ihnen könnte auch original-poster gefallen.

Skript installieren

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        syntax-highlighting
// @description Add syntax highlight to code blocks on the REAPER forum
// @namespace   https://cfillion.ca
// @version     1.0.3
// @author      cfillion
// @license     GPL-3.0-or-later
// @include     https://forum.cockos.com/showthread.php*
// @include     https://forum.cockos.com/showpost.php*
// @include     https://forum.cockos.com/editpost.php*
// @include     https://forum.cockos.com/newreply.php*
// @require     https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.3/highlight.min.js
// ==/UserScript==

// highlight.js v11 removed auto-merging of html (removes links) 

var theme = document.createElement('link');
theme.rel = 'stylesheet';
theme.href = 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.3/styles/sunburst.min.css';
document.body.appendChild(theme);

var style = document.createElement('style');
style.textContent = `
  pre.alt2 a:link, pre.alt2 a:visited { color: white; }
  pre.alt2 font { color: inherit; }
`;
document.body.appendChild(style);

hljs.configure({
  tabReplace: '\x20'.repeat(2),
  languages: ['lua', 'cpp'],
});

document.querySelectorAll('pre.alt2').forEach(hljs.highlightBlock);