Fixing codeboxes
Re: Fixing codeboxes
My vote is for Coy ...
Re: Fixing codeboxes
Ok coolio, I'll get it setup later tonight.
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: Fixing codeboxes
u used to be able to click on commands in codeboxes to open the docs. any plans on that making a return?
Re: Fixing codeboxes
Well, that used to be implement with geshi, but perhaps a nice little js could do the trick...
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: Fixing codeboxes
for example, the following
gets tokenized to punctuation, selector, operator, constant, keyword, etc. by prism.js
EDIT: might be even easier...
Found the redirect script on the server for this... usage e.g. autohotkey.com/docs/redirect.php?topic=AutoTrim
Code: Select all
; 1 Tab
loop, read, winevt.txt
{
loop, parse, A_LoopReadLine, %A_Tab%
{
RunWait, %comspec% /c ""C:\Windows\System32\wevtutil.exe" "cl" "%A_LoopField%"",,hide
}
}
Code: Select all
<code class=" language-autohotkey"><span class="token comment">; 1 Tab</span>
<span class="token selector">loop</span><span class="token punctuation">,</span> <span class="token keyword">read</span><span class="token punctuation">,</span> winevt<span class="token operator">.</span>txt
<span class="token punctuation">{</span>
<span class="token selector">loop</span><span class="token punctuation">,</span> <span class="token keyword">parse</span><span class="token punctuation">,</span> <span class="token constant">A_LoopReadLine</span><span class="token punctuation">,</span> <span class="token variable">%A_Tab%</span>
<span class="token punctuation">{</span>
<span class="token selector">RunWait</span><span class="token punctuation">,</span> <span class="token variable">%comspec%</span> <span class="token operator">/</span>c <span class="token string">""</span><span class="token tag">C</span><span class="token punctuation">:</span>\Windows\System32\wevtutil<span class="token operator">.</span>exe<span class="token string">" "</span>cl<span class="token string">" "</span><span class="token variable">%A_LoopField%</span><span class="token string">""</span><span class="token punctuation">,</span><span class="token punctuation">,</span><span class="token keyword">hide</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code>
Found the redirect script on the server for this... usage e.g. autohotkey.com/docs/redirect.php?topic=AutoTrim
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: Fixing codeboxes
Ok, here's what I've scripted. You can test it by doing copy paste into the js console on a loaded page with ahk codeboxes...
It uses the current php script we have that tries a best guest, however... I've noticed it might be little problematic in some cases.
e.g. the read in Loop, read will redirect to https://autohotkey.com/docs/commands/FileRead.htm instead of https://autohotkey.com/docs/commands/LoopReadFile.htm
a minor issue in this particular case, as they are still somewhat related in terms of what they do...
Code: Select all
// linker to docs for prism.js update
// created 7/01/2019
// script by joedf
////////////////////////////////////
var redirectQURL = 'https://www.autohotkey.com/docs/redirect.php?topic=';
// get AHK codeboxes
var cboxes = document.querySelectorAll('code.language-autohotkey');
for(var i=0;i<cboxes.length;i++) {
ctokens = cboxes[i].getElementsByClassName('token');
for(var j=0;j<ctokens.length;j++) {
type = ctokens[j].className.replace('token','').trim().toLowerCase();
// supported types: selector, keyword, constant, operator, and variable
if (['selector','keyword','constant','operator'].indexOf(type)>-1) {
ctokens[j].outerHTML = '<a href="'+redirectQURL+ctokens[j].innerHTML+'">'+ctokens[j].outerHTML+'</a>';
} else if (type.indexOf('variable')>-1) {
// same as bove normal rediretor usage but remove the % symbols...
ctokens[j].outerHTML = '<a href="'+redirectQURL+ctokens[j].innerHTML.replace(/%/gi,'')+'">'+ctokens[j].outerHTML+'</a>';
} else {
// do nothing? leave as is...
}
}
}
e.g. the read in Loop, read will redirect to https://autohotkey.com/docs/commands/FileRead.htm instead of https://autohotkey.com/docs/commands/LoopReadFile.htm
a minor issue in this particular case, as they are still somewhat related in terms of what they do...
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: Fixing codeboxes
Problem with block comments
OK:
OK:
NOT OK:
It seems like everything is highlighted as comments from the start of the first block comment until the end of the last one.
Side note, I think commands (and maybe built-in functions and control flow statements) used to be blue, I think that is better.
Cheers.
OK:
Code: Select all
msgbox "hello"
Code: Select all
msgbox "hello"
/*
block comment 1
*/
msgbox "world"
Code: Select all
msgbox "hello"
/*
block comment 1
*/
msgbox "world"
/*
block comment 2
*/
msgbox "hello world"
Side note, I think commands (and maybe built-in functions and control flow statements) used to be blue, I think that is better.
Cheers.
Re: Fixing codeboxes
I have identified the issue and prepared a fix - will try to merge it into the PrismJS AutoHotkey highlighter later today.
See: https://github.com/PrismJS/prism/issues/1700
See: https://github.com/PrismJS/prism/issues/1700
Recommends AHK Studio
Re: Fixing codeboxes
I made the pull request - joedf or tank could probably already update the definitions we have.
See: https://github.com/PrismJS/prism/pull/1703
Edit: if you see any other things our Highlighting misses out on, please share it here.
See: https://github.com/PrismJS/prism/pull/1703
Edit: if you see any other things our Highlighting misses out on, please share it here.
Recommends AHK Studio
Re: Fixing codeboxes
I don't know how your code box fix handles directives, but I noticed that directives don't work with [docs] tags, which I assume is related - for example, #If just leads to the docs start page https://autohotkey.com/docs/AutoHotkey.htm instead of https://autohotkey.com/docs/commands/_If.htm
and #NoEnv doesn't call https://autohotkey.com/docs/commands/_NoEnv.htm . I think, this applies to all directives. The pattern seems clear, though: # -> _
But I think this was actually already an issue before the forum software update. If it is an easy fix, it would be nice to have.
Anyway, thank you for your work on the code boxes.
and #NoEnv doesn't call https://autohotkey.com/docs/commands/_NoEnv.htm . I think, this applies to all directives. The pattern seems clear, though: # -> _
But I think this was actually already an issue before the forum software update. If it is an easy fix, it would be nice to have.
Anyway, thank you for your work on the code boxes.
Re: Fixing codeboxes
@Helgef Thanks for reporting!
@nnnik Awesome work! I've applied the patch.
Also, I have installed the docs "links" script I posted above.
@gregster Yeah, thats a phpbb/php limitation, I dont think there's something I can do without modifying phpbb code too much... or using some weird redirect tricks...
However, I have put some js to replace all # in docs-links to _.
EDIT: realised that wont work, since the help db index doesnt do it with #, so I've changed it to simply remove the # from docs-link urls
TLDR All issues fixed.
@nnnik Awesome work! I've applied the patch.
Also, I have installed the docs "links" script I posted above.
@gregster Yeah, thats a phpbb/php limitation, I dont think there's something I can do without modifying phpbb code too much... or using some weird redirect tricks...
However, I have put some js to replace all # in docs-links to _.
Code: Select all
/* joedf: patch [docs] links with # in element, e.g. #NoEnv, #If, to _NoEnv, _If, etc. */
var docslinks = document.querySelectorAll('.docs-link');
for(var i=0;i<docslinks.length;i++){
docslinks[i].href = docslinks[i].href.replace(/#/ig,'_');
}
TLDR All issues fixed.
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: Fixing codeboxes
Thanks joedf , very nice! This fixed it for almost all directives, at least the ones that don't have a corresponding command. But that's already a huge improvement.
That means, #Persistent, #Warn, #NoEnv, #MenuMaskKey, #NoTrayIcon, #Include, #InputLevel, #WinActivateForce, #MaxThreads and many others will work now, leading to the directives, but not #If, #IfWinActive/#IfWinExist and #Hotstring which will lead you to commands If (expression), IfWinActive/IfWinExist and Hotstring instead.
I think these few are the only ones affected that way. Anyway, totally fine for me now! Thanks again!
And of course, it is great that clicking on commands works now in the codebox - I just noticed.Again, great improvements !
That means, #Persistent, #Warn, #NoEnv, #MenuMaskKey, #NoTrayIcon, #Include, #InputLevel, #WinActivateForce, #MaxThreads and many others will work now, leading to the directives, but not #If, #IfWinActive/#IfWinExist and #Hotstring which will lead you to commands If (expression), IfWinActive/IfWinExist and Hotstring instead.
I think these few are the only ones affected that way. Anyway, totally fine for me now! Thanks again!
And of course, it is great that clicking on commands works now in the codebox - I just noticed.
No biggies so far - I think it is again directives that won't work for clicking and I guess If(expression) is mis-considered as a (user-defined) function, if there is no space between if and the parentheses
Code: Select all
#NoEnv ; not clickable
if(var = 5) ; not clickable, highlighting in yellow
Userfunc(parameter) ; (user defined) funcs are also shown in yellow
if (var = 5) ; clickable
msgbox %mytext% ; user variables between %'s are now clickable (and searchable via site:autohotkey.com/docs/), but no harm ;-)
; AHK built-in functions in general are not clickable yet:
OnMessage(0x112,"WM_SYSCOMMAND")
DllCall("AnimateWindow","UInt",Splash_ID,"Int",1000,"UInt","0x90000")
Re: Fixing codeboxes
Good catch, I had not added support for important and function tokens...
Updated:
Updated:
Code: Select all
// linker to docs for prism.js update
// created 7/01/2019 - updated 14/01/2019
// script by joedf
////////////////////////////////////
var redirectQURL = 'https://www.autohotkey.com/docs/redirect.php?topic=';
// get AHK codeboxes
var cboxes = document.querySelectorAll('code.language-autohotkey');
for(var i=0;i<cboxes.length;i++) {
ctokens = cboxes[i].getElementsByClassName('token');
for(var j=0;j<ctokens.length;j++) {
type = ctokens[j].className.replace('token','').trim().toLowerCase();
// supported types: selector, keyword, constant, operator, and variable
if (['selector','keyword','constant','operator','function'].indexOf(type)>-1) {
ctokens[j].outerHTML = '<a href="'+redirectQURL+ctokens[j].innerHTML+'">'+ctokens[j].outerHTML+'</a>';
} else if (type.indexOf('variable')>-1) {
// same as bove normal rediretor usage but remove the % symbols...
ctokens[j].outerHTML = '<a href="'+redirectQURL+ctokens[j].innerHTML.replace(/%/gi,'')+'">'+ctokens[j].outerHTML+'</a>';
} else if (type.indexOf('important')>-1) {
// same as bove normal rediretor usage but remove the # symbols...
ctokens[j].outerHTML = '<a href="'+redirectQURL+ctokens[j].innerHTML.replace(/#/gi,'')+'">'+ctokens[j].outerHTML+'</a>';
} else {
// do nothing? leave as is...
}
}
}
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: Fixing codeboxes
I fixed the highlighting.
See: https://github.com/PrismJS/prism/pull/1 ... 37c02a3b7c
See: https://github.com/PrismJS/prism/pull/1 ... 37c02a3b7c
Recommends AHK Studio
Re: Fixing codeboxes
Alright cool, I'll integrate the change later tonight.
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: Fixing codeboxes
these arent enabled for all themes
it would be cool if it got underlined on hover, too
it would be cool if it got underlined on hover, too
Re: Fixing codeboxes
@nnnik updated.
Whoops! Which themes did I miss? Also, it underlines like a normal link
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 5 guests