Fixing codeboxes

Discuss issues and requests related with the forum software
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Fixing codeboxes

Post by burque505 » 13 Nov 2018, 14:40

My vote is for Coy ...

User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Fixing codeboxes

Post by nnnik » 13 Nov 2018, 14:51

Yes I do believe thats the case.
Recommends AHK Studio

User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Fixing codeboxes

Post by joedf » 13 Nov 2018, 14:57

Ok coolio, I'll get it setup later tonight. :+1:
Image Image Image Image Image
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]

guest3456
Posts: 3453
Joined: 09 Oct 2013, 10:31

Re: Fixing codeboxes

Post by guest3456 » 14 Nov 2018, 08:43

yes i think Coy is a better theme


swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Fixing codeboxes

Post by swagfag » 06 Jan 2019, 04:45

u used to be able to click on commands in codeboxes to open the docs. any plans on that making a return?

User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Fixing codeboxes

Post by joedf » 06 Jan 2019, 23:50

Well, that used to be implement with geshi, but perhaps a nice little js could do the trick...
Image Image Image Image Image
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]

User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Fixing codeboxes

Post by joedf » 06 Jan 2019, 23:57

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
Image Image Image Image Image
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]

User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Fixing codeboxes

Post by joedf » 07 Jan 2019, 00:33

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...
Image Image Image Image Image
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]

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Fixing codeboxes

Post by Helgef » 12 Jan 2019, 04:36

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.

User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Fixing codeboxes

Post by nnnik » 12 Jan 2019, 07:08

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
Recommends AHK Studio

User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Fixing codeboxes

Post by nnnik » 13 Jan 2019, 06:15

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.
Recommends AHK Studio

gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: Fixing codeboxes

Post by gregster » 13 Jan 2019, 16:32

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:

User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Fixing codeboxes

Post by joedf » 13 Jan 2019, 21:48

@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:
Image Image Image Image Image
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]

gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: Fixing codeboxes

Post by gregster » 13 Jan 2019, 23:05

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: !

User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Fixing codeboxes

Post by joedf » 14 Jan 2019, 01:28

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

User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Fixing codeboxes

Post by nnnik » 14 Jan 2019, 02:21

I will see if I can fix the yellow highlighting.
Recommends AHK Studio

User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Fixing codeboxes

Post by nnnik » 15 Jan 2019, 06:07

Recommends AHK Studio

User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Fixing codeboxes

Post by joedf » 15 Jan 2019, 10:04

Alright cool, I'll integrate the change later tonight. :+1:
Image Image Image Image Image
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]

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Fixing codeboxes

Post by swagfag » 15 Jan 2019, 10:29

these arent enabled for all themes
it would be cool if it got underlined on hover, too

User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Fixing codeboxes

Post by joedf » 15 Jan 2019, 20:59

@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:
Image Image Image Image Image
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]

Post Reply

Return to “Forum Issues”