Page 4 of 6

Re: Fixing codeboxes

Posted: 13 Nov 2018, 14:40
by burque505
My vote is for Coy ...

Re: Fixing codeboxes

Posted: 13 Nov 2018, 14:51
by nnnik
Yes I do believe thats the case.

Re: Fixing codeboxes

Posted: 13 Nov 2018, 14:57
by joedf
Ok coolio, I'll get it setup later tonight. :+1:

Re: Fixing codeboxes

Posted: 14 Nov 2018, 08:43
by guest3456
yes i think Coy is a better theme

Re: Fixing codeboxes

Posted: 06 Jan 2019, 04:45
by swagfag
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

Posted: 06 Jan 2019, 23:50
by joedf
Well, that used to be implement with geshi, but perhaps a nice little js could do the trick...

Re: Fixing codeboxes

Posted: 06 Jan 2019, 23:57
by joedf
for example, the following

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
	}
}
gets tokenized to punctuation, selector, operator, constant, keyword, etc. by prism.js

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>
EDIT: might be even easier...
Found the redirect script on the server for this... usage e.g. autohotkey.com/docs/redirect.php?topic=AutoTrim

Re: Fixing codeboxes

Posted: 07 Jan 2019, 00:33
by joedf
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...

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...
		}
	}
}
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...

Re: Fixing codeboxes

Posted: 12 Jan 2019, 04:36
by Helgef
Problem with block comments
OK:

Code: Select all

msgbox "hello"
OK:

Code: Select all

msgbox "hello"
/*
	block comment 1
*/
msgbox "world"
NOT OK:

Code: Select all

msgbox "hello"
/*
	block comment 1
*/
msgbox "world"
/*
	block comment 2
*/
msgbox "hello world"
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.

Re: Fixing codeboxes

Posted: 12 Jan 2019, 07:08
by nnnik
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

Re: Fixing codeboxes

Posted: 13 Jan 2019, 06:15
by nnnik
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.

Re: Fixing codeboxes

Posted: 13 Jan 2019, 16:32
by gregster
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. :xmas:

Re: Fixing codeboxes

Posted: 13 Jan 2019, 21:48
by joedf
@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 _.

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,'_');
	}
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. :+1:

Re: Fixing codeboxes

Posted: 13 Jan 2019, 23:05
by gregster
Thanks joedf :clap: , 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! :thumbup: Thanks again!


And of course, it is great that clicking on commands works now in the codebox - I just noticed.
nnnik wrote:
13 Jan 2019, 06:15
Edit: if you see any other things our Highlighting misses out on, please share it here.
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")
Again, great improvements :clap: !

Re: Fixing codeboxes

Posted: 14 Jan 2019, 01:28
by joedf
Good catch, I had not added support for important and function tokens...
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...
		}
	}
}

Re: Fixing codeboxes

Posted: 14 Jan 2019, 02:21
by nnnik
I will see if I can fix the yellow highlighting.

Re: Fixing codeboxes

Posted: 15 Jan 2019, 06:07
by nnnik

Re: Fixing codeboxes

Posted: 15 Jan 2019, 10:04
by joedf
Alright cool, I'll integrate the change later tonight. :+1:

Re: Fixing codeboxes

Posted: 15 Jan 2019, 10:29
by swagfag
these arent enabled for all themes
it would be cool if it got underlined on hover, too

Re: Fixing codeboxes

Posted: 15 Jan 2019, 20:59
by joedf
@nnnik updated.
swagfag wrote:
15 Jan 2019, 10:29
these arent enabled for all themes
it would be cool if it got underlined on hover, too
Whoops! Which themes did I miss? Also, it underlines like a normal link :+1: