Page 6 of 6

Re: Fixing codeboxes

Posted: 22 Feb 2019, 17:13
by joedf
Great to hear! :+1:

Re: Fixing codeboxes

Posted: 23 Jan 2020, 12:55
by joedf
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

Posted: 23 Jan 2020, 16:52
by HotKeyIt
Nice :thumbup:

Re: Fixing codeboxes

Posted: 23 Jan 2020, 17:03
by joedf
Thanks! :D

Re: Fixing codeboxes

Posted: 16 Mar 2020, 14:47
by AreaMan
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

Posted: 16 Mar 2020, 15:50
by joedf
@AreaMan
If you are having bugs or other issues with the codeboxes, please share the BBCode if possible. Thanks. :+1:

Re: Fixing codeboxes

Posted: 16 Mar 2020, 17:08
by gregster
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?