Fixing codeboxes

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Fixing codeboxes

Re: Fixing codeboxes

by gregster » 16 Mar 2020, 17:08

AreaMan wrote:
16 Mar 2020, 14:47
I got into a real mess trying to use a saved draft.
Codebox stuff out the wazoo, in and out of my simple Help request.
Hope this helps your diagnosis.
You should also describe your exact work process... if I look at this: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=73586 , I see <br> tags (among others):

Code: Select all

<r>I have a bunch of simple hotkeys to insert commonly used text. No easy way to insert an em-dash so I tried AutoHotKey. Got strange results: [b]—[/b]<br/>
<br/>
Using the numeric Unicode finally worked.<br/>

<CODEBOX codebox="autohotkey" file="Untitled.ahk"><s>[Codebox=autohotkey file=Untitled.ahk]</s><i>
</i>^#e::
  ; ;; Control Window e yields an EM DASH: —
SendInput, {U+2014}
Return

^#g::
  ; ;; Control Window g yields — (Crap instead of an EM DASH)
SendInput, —
Return
<e>[/Codebox]</e></CODEBOX>

So why won't the em-dash itself insert like any other bunch of text?<br/>
<br/>
Windows 1909, 64-bit, x86<br/>
AutoHotKey 1.1.32.00</r>
These are used in HTML, not in BBCode. Did you insert them yourself? If yes, don't do it. Just use the tags that are also provided in the forum editor via buttons.
Or did you somehow save your draft in HTML format yourself instead of using the built-in 'Save draft' function of the editor?

I actually don't think that those <r>, <s> or <e> tags will be created by the forum editor - and it doesn't look like our HTML source code either. I've used the forum editor's Save draft function regularly, but never encountered this. So, how is your process and does it also happen, if you don't use drafts?

Re: Fixing codeboxes

by joedf » 16 Mar 2020, 15:50

@AreaMan
If you are having bugs or other issues with the codeboxes, please share the BBCode if possible. Thanks. :+1:

Re: Fixing codeboxes

by AreaMan » 16 Mar 2020, 14:47

I got into a real mess trying to use a saved draft.
Codebox stuff out the wazoo, in and out of my simple Help request.
Hope this helps your diagnosis.

Re: Fixing codeboxes

by joedf » 23 Jan 2020, 17:03

Thanks! :D

Re: Fixing codeboxes

by HotKeyIt » 23 Jan 2020, 16:52

Nice :thumbup:

Re: Fixing codeboxes

by joedf » 23 Jan 2020, 12:55

another update, I've added the option to toggle line numbers :+1:

Code here for future reference:

Code: Select all

// joedf: add option toggle line numbers in codeboxes
// created Jan 2020
// should on all latest major browsers
// Chrome v1, Edge 12, FF62, IE9

function toggleLineNums_init(){
	// add css rules
	var ir = document.createElement('style');
	ir.innerHTML = ".Ln_prism_sub::selection{background:none}" + "\n .Ln_prism_sub{width:auto;height:'+hCode+'px;float:left;border-right:1px solid limegreen;line-height:1.5em;padding-right:.5em;margin-right:.5em;text-align:right;color:#999;user-select:none;overflow:hidden;pointer-events:none}";
	document.body.appendChild(ir);

	// add toggle anchor links ...
	var boxes = document.getElementsByTagName('code');
	for (var i = 0; i < boxes.length; i++) {
		var tagP = (boxes[i].parentNode.tagName.toLowerCase() == 'pre' ? boxes[i].parentNode.previousSibling : boxes[i].previousSibling);
			tagP.innerHTML += ' - <a href="#" title="Toggle Line numbers" onclick="toggleLineNums(this); return false;">Toggle Line numbers</a>';
	}
}
function toggleLineNums(e) {
	var eCode = e.parentNode.parentNode.getElementsByTagName('code')[0];

	// check if linenumbers are ready
	if(eCode.className.indexOf('Ln_prism_ready')>-1) {
		var lnBox = eCode.getElementsByClassName('Ln_prism_sub')[0];

		// determine case to show/hide them
		if(eCode.className.indexOf('Ln_prism_show')>-1) {
			eCode.className = eCode.className.replace(' Ln_prism_show','')
			lnBox.style.display = 'none';
		} else {
			eCode.className += ' Ln_prism_show';
			lnBox.style.display = 'block';
		}
	} else {
		// otherwise initialize and create the line numbers
		var hCode = eCode.scrollHeight;
		var l_start = '<div class="Ln_prism_sub">';
		var l_end = '</div>';

		var lnBox = window.document.createElement('div');
		var numbers = [];
		var hay = eCode.innerHTML;
		var ln = 1;
		for(var i=0;i<hay.length;i++){
			if (hay[i]=='\n')
				numbers.push(ln++);
		}
		numbers.push(ln++);
		lnBox.innerHTML = l_start + numbers.join('\n') + l_end;
		lnBox.style.display = 'block';

		eCode.insertBefore(lnBox, eCode.firstChild);
		eCode.className += ' Ln_prism_ready Ln_prism_show'
	}
}
toggleLineNums_init();

Re: Fixing codeboxes

by joedf » 22 Feb 2019, 17:13

Great to hear! :+1:

Re: Fixing codeboxes

by DRocks » 22 Jan 2019, 06:46

The code box is nicer than before now.. good job!
Thank you

Re: Fixing codeboxes

by joedf » 20 Jan 2019, 21:58

Okay, should work now. Tested. Updated and hooks on to timing of Prism.js :+1:

Code: Select all

/* PrismJS 1.15.0 -- modified joedf: added patch from nnnik for block-comments https://github.com/PrismJS/prism/pull/1703

// [...]

/* joedf - include prism.urls.js after prism.js load */
(function(){
	if (typeof self === 'undefined' || !self.Prism || !self.document || !document.querySelector) {
		return;
	}
	Prism.RunCount = 0;
	Prism.hooks.add('complete', function(env) {
		Prism.RunCount += 1;
		Prism.RunTotal = document.body.getElementsByTagName('code').length;
		console.log("Prism executed ["+Prism.RunCount+" / "+Prism.RunTotal+"].");
		if (Prism.RunCount >= Prism.RunTotal) {
			console.log("Launching prism.urls.js ...");
			if (document.body.getElementsByTagName('code').length > 0) {
				var prismdocsjs = document.createElement('script');
				prismdocsjs.src="/boards/assets/prism/prism.urls.js";
				document.body.appendChild(prismdocsjs);
			}
		}
	});
})();
prism.urls.js

Code: Select all

// linker to docs for prism.js update
// created 7/01/2019 - updated 20/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 (['builtin','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...
		}
	}
}

/* force the underlined link style */
codelinkstyle = document.createElement('style');
codelinkstyle .innerHTML = "code a:hover{text-decoration:underline !important;}";
document.head.appendChild(codelinkstyle);
console.log("prism.urls.js executed.");

Re: Fixing codeboxes

by joedf » 20 Jan 2019, 21:36

TAC109 wrote:
19 Jan 2019, 16:55
Some progress on iPad using Safari - some code boxes support help lookup, but others don’t. :crazy:

Not so good with IE11 - help doesn’t work at all now. :think:
Thank you for report. Okay there was a little compatibility that was fixed. Now, there are not errors... but, the timing is off. If prism.urls.js runs at the very end, everything is okay on IE11.
But when it loads from cache, the timing is messed up.

Re: Fixing codeboxes

by TAC109 » 19 Jan 2019, 16:55

Some progress on iPad using Safari - some code boxes support help lookup, but others don’t. :crazy:

Not so good with IE11 - help doesn’t work at all now. :think:

Re: Fixing codeboxes

by jeeswg » 17 Jan 2019, 22:50

Sure, will do. (I thought of them as codebox issues, but I can see now they're more like post issues.) Thanks.

Done:
phpBB issues - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=3&t=61130

Re: Fixing codeboxes

by joedf » 17 Jan 2019, 22:40

jeeswg wrote:
17 Jan 2019, 20:22
- The url tag used to show the full url, currently it doesn't.
- I've always used the url tag in my posts, so that people can easily copy and paste all the information, with full urls.

- Also, the default quote text has changed:
- Current: 'quote=##### post_id=###### time=########## user_id=##'.
- Original: 'quote=#####'. Thanks.
Yes, you are correct. Phpbb changed some things... Please open a seperate topic for this. I have too many things in mind. Posting here about this will only confuse me more.
Thanks.

Re: Fixing codeboxes

by joedf » 17 Jan 2019, 22:38

Ok, IE Bug fix

Code: Select all

// ==UserScript==
// @name        AHK-Forum display solved h3 title
// @namespace   autohotkey.com
// @include     http://autohotkey.com/boards/viewtopic.php*
// @include     https://autohotkey.com/boards/viewtopic.php*
// @version     1
// @grant       none
// @author      joedf
// timestamp 15:11 2016/06/24
// ==/UserScript==
if (document.body.contains(document.getElementsByClassName('icon_solved_post') [0])) {
  //window.onload = function () {
    p = document.getElementsByClassName('postbody');
    n = p.length;
    for (i = 0; i < n; i++) {
      if (p[i].getElementsByTagName('h3')[0].contains(document.getElementsByClassName('icon_solved_post') [0])) {
        p[i].getElementsByTagName('h3')[0].style.display = 'inline';
        m = p[i].getElementsByTagName('div')[0];
        m.style.border = '2px solid lime';
        m.style.padding = '4px';
        m.style.backgroundColor = 'lightgoldenrodyellow';
        break;
      }
    }
  //}
}
Built-in functions fix

Code: Select all

// linker to docs for prism.js update
// created 7/01/2019 - updated 16/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('builtin')>-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...
		}
	}
}

/* force the underlined link style */
codelinkstyle = document.createElement('style');
codelinkstyle .innerHTML = "code a:hover{text-decoration:underline !important;}";
document.head.appendChild(codelinkstyle);

Re: Fixing codeboxes

by jeeswg » 17 Jan 2019, 20:22

- The url tag used to show the full url, currently it doesn't.
- I've always used the url tag in my posts, so that people can easily copy and paste all the information, with full urls.

- Also, the default quote text has changed:
- Current: 'quote=##### post_id=###### time=########## user_id=##'.
- Original: 'quote=#####'. Thanks.

Re: Fixing codeboxes

by TAC109 » 17 Jan 2019, 16:46

On IE11 I see 'css3114 @font-face failed OpenType embedding permission check. Permission must be installable.' twice when it works the first time. Keyword was underlined with little hand icon. After going back in IE11, hovering over keyword again now has no effect (no underline and no little hand icon).

I also see the 'script438' error.

Nothing happens at all on iPad.

Re: Fixing codeboxes

by joedf » 17 Jan 2019, 09:51

TAC109 wrote:
16 Jan 2019, 23:06
Help in code boxes still doesn’t work for me. I use prosilver layout.
On my iPad using default Safari web browser it doesn’t work at all.
On my PC it works only once and then not at all until the PC is reloaded. Here I use IE11.

Before the forum software was 'upgraded' it all used to work fine on both platforms.

Hope you can get to the bottom of this.
Cheers
Thanks for reporting this. I was able to reproduce the links not working. I have tested with IE11 and refreshed a few times.
https://www.autohotkey.com/boards/viewt ... 73&style=1
If you try running with the developer tools - console open, do you see any errors?
I get this error for now, which I shall fix when I get home:
SCRIPT438: Object doesn't support property or method 'contains'
highlightsolved.js (11,1)

gregster wrote:
17 Jan 2019, 01:25
joedf wrote:
16 Jan 2019, 23:01
As for length... looks like there's a difference between
https://autohotkey.com/docs/length()
and
https://autohotkey.com/docs/length
Yes, okay, but the code boxes seem to use the second, even If i use () behind it - but not a big deal. This is so much better now than directly after the forum software upgrade.
Thank you again for your work on this. I see now underlining and 'Expand view' in spoilers - and built-in functions are working again :clap:
Okay, it seems like I can use Dllcall() instead of Dllcall too, so I will change builtin function links to have an extra () at the end. Should fix it. I'll try this when I get home.

Re: Fixing codeboxes

by gregster » 17 Jan 2019, 01:25

joedf wrote:
16 Jan 2019, 23:01
As for length... looks like there's a difference between
https://autohotkey.com/docs/length()
and
https://autohotkey.com/docs/length
Yes, okay, but the code boxes seem to use the second, even If i use () behind it - but not a big deal. This is so much better now than directly after the forum software upgrade.
Thank you again for your work on this. I see now underlining and 'Expand view' in spoilers - and built-in functions are working again :clap:

Re: Fixing codeboxes

by TAC109 » 16 Jan 2019, 23:06

Help in code boxes still doesn’t work for me. I use prosilver layout.
On my iPad using default Safari web browser it doesn’t work at all.
On my PC it works only once and then not at all until the PC is reloaded. Here I use IE11.

Before the forum software was 'upgraded' it all used to work fine on both platforms.

Hope you can get to the bottom of this.
Cheers

Re: Fixing codeboxes

by joedf » 16 Jan 2019, 23:01

As for length... looks like there's a difference between
https://autohotkey.com/docs/length()
and
https://autohotkey.com/docs/length

Top