Code blocks need to support highlighting v2 syntax.
As a minimum improvement, the default code block could highlight single quoted strings, despite them being unsupported in v1. I think failure to highlight single quoted strings is the one thing that impacts readability most.
Ideally, v2 code blocks would highlight v2 keywords and link to v2 documentation.
Ideally it would be possible to specify the version for a code block, and the version would default to v2 when posted in a v2 subforum (whether this is done when the editor buttons are clicked or when the page is rendered).
Also, the current "Select code" dropdown (which generates tags which allow for a filename to be specified) is a pain to use. Surely we can put AutoHotkey at the top of the language list.
Syntax highlighting v2
Re: Syntax highlighting v2
It is also possible to use the syntax highlighter from the docs, which is far more accurate and pretty than the default highlighter used in these forums.
Currently I use the following userscript:
and blocked the default highlighter script with an adblocker (ublock) using the filter:
Theoretically, this could also be natively integrated into the forum.
Example: new vs. old
Currently I use the following userscript:
Code: Select all
// ==UserScript==
// @name AutoHotkey Forum Codebox Highlighting
// @namespace https://*.autohotkey.com/board*
// @version 0.1
// @description Use custom syntax highlighter
// @author Ragnar-F
// @match https://*.autohotkey.com/board*
// ==/UserScript==
h2_a = document.querySelector('h2 a');
isV2 = (location.href.match(/f=(82|83|37|92)/) || (h2_a && h2_a.href.match(/f=(82|83|37|92)/))) || false; // forum id is sometimes not always present in the url
unsafeWindow.forceNoScript = true;
var css = '.codebox{border-color:transparent;}*{scrollbar-base-color: #252525;scrollbar-face-color: #4b4b4b;scrollbar-3dlight-color: #252525;scrollbar-highlight-color: #252525;scrollbar-track-color: #252525;scrollbar-arrow-color: #4b4b4b;scrollbar-shadow-color: #252525;}::-webkit-scrollbar{background-color: #252525;}::-webkit-scrollbar-track{background-color: #252525;}::-webkit-scrollbar-thumb{background-color: #4b4b4b;border: 2px solid #252525;}::-webkit-scrollbar-thumb:hover{background-color: #5f5f5f;}::-webkit-scrollbar-corner{background-color: inherit;}::-ms-expand{background-color: #1e1e1e;color: #4b4b4b;border-color: #252525;}code,pre{font-family:Consolas!important;font-size:14px!important;tab-size:4;color:#d5d5d5!important;background-color:#2e2e2e!important;}code span>a,code span>a:hover,code span>a:link,pre span>a,pre span>a:hover,pre span>a:link{color:inherit!important}code>.bif,code>.cmd,pre>.bif,pre>.cmd{color:#569cd6}code>.met,pre>.met{color:#60c5dc}code>.cfs,code>.dec,pre>.cfs,pre>.dec{color:#c586c0}code>.str,pre>.str{color:#ce9178}code .str>.esc,pre .str>.esc{color:#ff6868}pre>.biv,pre>.cls,code>.biv,code>.cls{color:#4ec9b0}code>.dir,pre>.dir{color:#dcdcaa}code>.fun,code>.lab,pre>.fun,pre>.lab{font-weight:normal;color:#dcdcaa}code>.num,pre>.num{color:#b5cea8}code em,code .cmt,pre.origin em,pre .cmt{color:#6a9955!important}';
//var css = 'code,pre { font-family: Consolas !important; font-size: 14px !important; tab-size: 4; color: #000 !important; background-color: #eff0f1 !important;}code span>a,code span>a:hover,code span>a:link,pre span>a,pre span>a:hover,pre span>a:link { color: inherit !important}code>.bif,code>.cmd,pre>.bif,pre>.cmd { color: #0148c2}code>.met,pre>.met { color: #097f9a}code>.cfs,code>.dec,pre>.cfs,pre>.dec { color: #6F008A}code>.str,pre>.str { color: #A31515}code .str>.esc,pre .str>.esc { color: #FF0000}pre>.biv,pre>.cls,code>.biv,code>.cls { color: #006400}code>.dir,pre>.dir { color: green}code>.fun,code>.lab,pre>.fun,pre>.lab { font-weight: bold; color: #290e90}code>.num,pre>.num { color: #1a6c4e}code em,code .cmt,pre.origin em,pre .cmt { color: #708090 !important}';
addGlobalStyle(css);
if (isV2)
{
scriptDir = 'https://www.autohotkey.com/docs/v2/static';
loadScript(scriptDir + '/content.js', function() {
var pres = document.querySelectorAll("code.lang-autohotkey, pre.prettyprint");
// unsafeWindow.features.addCodeBoxButtons(pres);
unsafeWindow.features.addSyntaxColors(pres);
});
}
else
{
scriptDir = 'https://www.autohotkey.com/docs/v1/static';
loadScript(scriptDir + '/content.js', function() {
var pres = document.querySelectorAll("code.lang-autohotkey, pre.prettyprint");
// unsafeWindow.features.addCodeBoxButtons(pres);
unsafeWindow.features.addSyntaxColors(pres);
});
}
function loadScript(url, callback) {
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState){ // IE
script.onreadystatechange = function() {
if (script.readyState == "loaded" ||
script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { // Others
script.onload = function() {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
Code: Select all
||www.autohotkey.com/boards/assets/prism/prism.js$script,domain=www.autohotkey.com
Example: new vs. old
Last edited by Ragnar on 02 May 2023, 16:33, edited 2 times in total.
Re: Syntax highlighting v2
Thanks, I'll have a look to bring these suggestions in.
@Ragnar how is the light or dark theme set? Is there a class name? Haven't fully checked the code, just if you off hand.
@Ragnar how is the light or dark theme set? Is there a class name? Haven't fully checked the code, just if you off hand.
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Syntax highlighting v2
In the userscript this is "hardcoded". See the var css = line. A mixture of CSS from the content.css and dark.css files (specifically <pre>, <code> and scrollbar).
The docs default to light theme CSS defined in content.css, which is overridden with dark.css when set to dark theme.
Formatted, the CSS line would look like the following, which is currently for dark theme:
Light theme would be:
The docs default to light theme CSS defined in content.css, which is overridden with dark.css when set to dark theme.
Formatted, the CSS line would look like the following, which is currently for dark theme:
Code: Select all
.codebox {
border-color: transparent;
}
* {
scrollbar-base-color: #252525;
scrollbar-face-color: #4b4b4b;
scrollbar-3dlight-color: #252525;
scrollbar-highlight-color: #252525;
scrollbar-track-color: #252525;
scrollbar-arrow-color: #4b4b4b;
scrollbar-shadow-color: #252525;
}
::-webkit-scrollbar {
background-color: #252525;
}
::-webkit-scrollbar-track {
background-color: #252525;
}
::-webkit-scrollbar-thumb {
background-color: #4b4b4b;
border: 2px solid #252525;
}
::-webkit-scrollbar-thumb:hover {
background-color: #5f5f5f;
}
::-webkit-scrollbar-corner {
background-color: inherit;
}
::-ms-expand {
background-color: #1e1e1e;
color: #4b4b4b;
border-color: #252525;
}
code,
pre {
font-family: Consolas !important;
font-size: 14px !important;
tab-size: 4;
color: #d5d5d5 !important;
background-color: #2e2e2e !important;
}
code span>a,
code span>a:hover,
code span>a:link,
pre span>a,
pre span>a:hover,
pre span>a:link {
color: inherit !important
}
code>.bif,
code>.cmd,
pre>.bif,
pre>.cmd {
color: #569cd6
}
code>.met,
pre>.met {
color: #60c5dc
}
code>.cfs,
code>.dec,
pre>.cfs,
pre>.dec {
color: #c586c0
}
code>.str,
pre>.str {
color: #ce9178
}
code .str>.esc,
pre .str>.esc {
color: #ff6868
}
pre>.biv,
pre>.cls,
code>.biv,
code>.cls {
color: #4ec9b0
}
code>.dir,
pre>.dir {
color: #dcdcaa
}
code>.fun,
code>.lab,
pre>.fun,
pre>.lab {
font-weight: normal;
color: #dcdcaa
}
code>.num,
pre>.num {
color: #b5cea8
}
code em,
code .cmt,
pre.origin em,
pre .cmt {
color: #6a9955 !important
}
Code: Select all
code,
pre {
font-family: Consolas !important;
font-size: 14px !important;
tab-size: 4;
color: #000 !important;
background-color: #eff0f1 !important;
}
code span>a,
code span>a:hover,
code span>a:link,
pre span>a,
pre span>a:hover,
pre span>a:link {
color: inherit !important
}
code>.bif,
code>.cmd,
pre>.bif,
pre>.cmd {
color: #0148c2
}
code>.met,
pre>.met {
color: #097f9a
}
code>.cfs,
code>.dec,
pre>.cfs,
pre>.dec {
color: #6F008A
}
code>.str,
pre>.str {
color: #A31515
}
code .str>.esc,
pre .str>.esc {
color: #FF0000
}
pre>.biv,
pre>.cls,
code>.biv,
code>.cls {
color: #006400
}
code>.dir,
pre>.dir {
color: green
}
code>.fun,
code>.lab,
pre>.fun,
pre>.lab {
font-weight: bold;
color: #290e90
}
code>.num,
pre>.num {
color: #1a6c4e
}
code em,
code .cmt,
pre.origin em,
pre .cmt {
color: #708090 !important
}
Re: Syntax highlighting v2
https://github.com/PrismJS/prism/blob/master/components/prism-autohotkey.js
I've taken a quick peek at the code (for ref. https://github.com/Lexikos/AutoHotkey_L-Docs/blob/d06a1c4a20/docs/static/content.js#L1767)
It looks like just regex won't suffice...
Okay, when I'm free I'll try to implement something so that we can reference it directly like you've done so above. I'll likely add a v2 option or something like that for the bbcode.
For now, I've managed to place AutoHotkey first in the drop down. the simple [\code] tag defaults to ahk as well.
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Syntax highlighting v2
@joedf - If it would not be possible for the version to be automatically selected based on the sub-forum being posted in as lexikos suggested (which would be best if possible), is the plan to have separate AHK code boxes available for each version in the dropdown list? The simple code tag would be specific to v2, but the list could be used by those wanting to select v1 specifically (with v2 also available there for completeness).
This would allow new posts to use either style, with the handy button applying to v2. We would just have to live with existing posts that use the simple code tags to be rendered with the v2 rules unless there was a way to do a bulk edit of posts by sub-forum to replace “code” tags with “codebox=autohotkeyv1” tags, as I suggested here.
This would allow new posts to use either style, with the handy button applying to v2. We would just have to live with existing posts that use the simple code tags to be rendered with the v2 rules unless there was a way to do a bulk edit of posts by sub-forum to replace “code” tags with “codebox=autohotkeyv1” tags, as I suggested here.
Re: Syntax highlighting v2
I haven't gotten around to it, but the gist of it is to default to v2 for new posts, have some sort of auto-detect if v1 or v2 based on the forum sections, and finally have both v1 and v2 selectable from the dropdown.
I am not sure we have a bulk edit option here... Running SQL script could work, but I don't trust myself doing that and is perhaps more challenging or at least more time consuming.
I am not sure we have a bulk edit option here... Running SQL script could work, but I don't trust myself doing that and is perhaps more challenging or at least more time consuming.
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Syntax highlighting v2
OK. Thanks.
Re: Syntax highlighting v2
is this implemented yet(doesnt appear so)
Re: Syntax highlighting v2
@swagfag Nope, not yet! Still on my to-do list. Thanks for raising the concern though!
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Syntax highlighting v2
@Ragnar I was just testing your userscript now, but it did not fully work. I got this error in the web console:
Is it possible to port it to prism.js ? It would be much easier for me, since we have the line numbers among other features integrated with it.
Code: Select all
Uncaught TypeError: document.getElementById(...) is null
openSite https://www.autohotkey.com/docs/static/content.js:1421
<anonymous> https://www.autohotkey.com/docs/static/content.js:275
i https://www.autohotkey.com/docs/static/content.js:2338
fireWith https://www.autohotkey.com/docs/static/content.js:2338
ready https://www.autohotkey.com/docs/static/content.js:2338
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Syntax highlighting v2
I have updated the userscript above as some links have changed in the meantime. Maybe it works now. This error message doesn't help much. To try reproducing this, I'd still need to know what browser, adblocker and userscript addon you're using.
I have no knowledge about prism.js, so I don't know. My guess is that it probably won't work because the syntax highlighter is handmade.Is it possible to port it to prism.js ? It would be much easier for me, since we have the line numbers among other features integrated with it.
Re: Syntax highlighting v2
Prism.js essentially does it in regex patterns.. but I am guessing it might not be sufficient or so straight-forward...
https://github.com/PrismJS/prism/blob/master/components/prism-autohotkey.js
Funny enough, they are also transitioning to a V2 ...
As for my browser: firefox v112.02, uBlock Origin, and greasemonkey.
https://github.com/PrismJS/prism/blob/master/components/prism-autohotkey.js
Funny enough, they are also transitioning to a V2 ...
As for my browser: firefox v112.02, uBlock Origin, and greasemonkey.
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Syntax highlighting v2
GreaseMonkey was the problem. It seems to be more restrictive than TamperMonkey in terms of security. I fixed the userscript above by adding unsafeWindow and removing the line "// @grant none". It should now work with both addons.
Re: Syntax highlighting v2
ahh okay thanks! I'll give it a try later
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Syntax highlighting v2
Curious if there’s been any progress on this front
Re: Syntax highlighting v2
None, to be honest.
The easiest would be to have the prism.js regex / parse code updated.
Or I just hunker down on this in the morning. right now, I am looking into why emails are not working for anything other than gmail...
The easiest would be to have the prism.js regex / parse code updated.
Or I just hunker down on this in the morning. right now, I am looking into why emails are not working for anything other than gmail...
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Who is online
Users browsing this forum: No registered users and 22 guests