Page 1 of 1

Code Block Highlighting is Now (Disabled)

Posted: Wed Nov 11, 2020 9:06 pm
by rockedge

I have installed and enabled a code highlighter that will highlight code syntax in a Code Block.

Indicate the language in the BBCode for example
code=bash
code=python

Also code=none turns code highlighting OFF

Please report if any problems or conflicts occur.


Re: Code Block Highlighting is Now Enabled

Posted: Wed Nov 11, 2020 10:52 pm
by s243a
rockedge wrote: Wed Nov 11, 2020 9:06 pm

I have installed and enabled a code highlighter that will highlight code syntax in a Code Block.

How do we use it and can we specify the programming language?


Re: Code Block Highlighting is Now Enabled

Posted: Wed Nov 11, 2020 11:04 pm
by sc0ttman

I'm guessing we use the standard bbcode way:

Code: Select all

var foo = `some ${string}`;

const bar = (cfg = { ...one, ...two }) => cfg.toString();

And here is the Markdown way (seems unsupported, but hey ho, no biggie)

Code: Select all

var foo = `some ${string}`;

....so the above test shows you need to write your code in bbcode code blocks, not markdown-style backticks, if you want it to get syntax highlighting..


Re: Code Block Highlighting is Now Enabled

Posted: Wed Nov 11, 2020 11:33 pm
by s243a
sc0ttman wrote: Wed Nov 11, 2020 11:04 pm

I'm guessing we use the standard bbcode way:

Code: Select all

var foo = `some ${string}`;

And here is the Markdown way (seems unsupported, but hey ho, no biggie)

Code: Select all

var foo = `some ${string}`;

....so the above test shows you need to write your code in bbcode code blocks, not markdown-style backticks, if you want it to get syntax highlighting..

If I add in your bbcode style code block code=js it doesn't produce an error. However, this test isn't enough to tell me if the syntax highlighting takes language into account. If language is taken into account then I'd like to know which languages are supported.


Re: Code Block Highlighting is Now Enabled

Posted: Wed Nov 11, 2020 11:42 pm
by rockedge

@s243a You might need to enable Markdown by unchecking the box down on the bottom of the post editor. I have modified the code to always load the post editor with Markdown disabled by default.

Markdown enabled and using 3 tick marks

Code: Select all

var foo = `some ${string}`;

Re: Code Block Highlighting is Now Enabled

Posted: Thu Nov 12, 2020 12:05 am
by rockedge

@s243a

The system is using highlight.js which recognizes 189 programming and scripting languages, automatically. Also highlights configuration files like those from the Apache Web Server or .htaccess

Here is the link for a demo.

https://highlightjs.org/static/demo/


Re: Code Block Highlighting is Now Enabled

Posted: Thu Nov 12, 2020 1:44 am
by s243a
rockedge wrote: Thu Nov 12, 2020 12:05 am

@s243a

The system is using highlight.js which recognizes 189 programming and scripting languages, automatically. Also highlights configuration files like those from the Apache Web Server or .htaccess

Here is the link for a demo.

https://highlightjs.org/static/demo/

Thankyou for the info :)

That said, it would still be nice to be able to specify the programming/scripting language...but perhaps you can with this system?


Re: Code Block Highlighting is Now Enabled

Posted: Thu Nov 12, 2020 1:52 am
by rockedge

I am looking into the possiblity although it seems not possible to specify. The orginal BBCode code block used to take code=php but that was it. I only see so far that it automatically detects the language being used.

See the demo for more


Re: Code Block Highlighting is Now Enabled

Posted: Thu Nov 12, 2020 3:01 am
by s243a
rockedge wrote: Thu Nov 12, 2020 1:52 am

I am looking into the possiblity although it seems not possible to specify. The orginal BBCode code block used to take code=php but that was it. I only see so far that it automatically detects the language being used.

See the demo for more

Seems to be possible with BBCodes

code=js

Code: Select all

var foo = `some ${string}`;

code=awk (likely not valid awk)

Code: Select all

var foo = `some ${string}`;

code=C++

Code: Select all

cout << "Enter an integer: ";

code=php

Code: Select all

<?php echo "The Best PHP Examples"; ?>

Re: Code Block Highlighting is Now Enabled

Posted: Thu Nov 12, 2020 3:32 am
by MochiMoppel

This is not "highlighting". Quite the opposite. Can you read this?


Re: Code Block Highlighting is Now Enabled

Posted: Thu Nov 12, 2020 3:44 am
by rockedge

@MochiMoppel

I have not yet looked at the ne-blackgreen style version of the code highlighter. I only have so much time in the day for a full time job I don't get paid for. I can always remove it.

I will examine the CSS for the style to see what can be done

positive re-enforcement is a thing.


Re: Code Block Highlighting is Now Enabled

Posted: Thu Nov 12, 2020 4:00 am
by s243a
MochiMoppel wrote: Thu Nov 12, 2020 3:32 am

This is not "highlighting". Quite the opposite. Can you read this?

On my computer it looks like this which shows a different highlighting for each language.

code_highlighting.png
code_highlighting.png (26.7 KiB) Viewed 422 times

Re: Code Block Highlighting is Now Enabled

Posted: Thu Nov 12, 2020 4:02 am
by s243a
rockedge wrote: Thu Nov 12, 2020 3:44 am

@MochiMoppel

I have not yet looked at the ne-blackgreen style version of the code highlighter. I only have so much time in the day for a full time job I don't get paid for. I can always remove it.

I will examine the CSS for the style to see what can be done

positive re-enforcement is a thing.

I just gave you a "thanks". I like the code highlighting. Unfortuantly given MochiMoppel it still has some bugs but keep up the good work :)


Re: Code Block Highlighting is Now Enabled

Posted: Thu Nov 12, 2020 4:26 am
by rockedge

@MochiMoppel

I think I might have fixed it...or we will be going off the rails any minute now.....either way, please test the code block out and report.

Code: Select all

<?php
    if(isset($_POST['B7on'])){
	$url = "http://192.168.0.17:8008/?house=B&unit=7&command=ON";
	$cmd_string = file_get_contents_curl($url);
	echo $cmd_string; 
    }
    if(isset($_POST['B7off'])){
	$url = "http://192.168.0.17:8008/?house=B&unit=7&command=OFF";
	$cmd_string = file_get_contents_curl($url);
	echo $cmd_string; 
    }
    if(isset($_POST['B7dim'])){
	$url = "http://192.168.0.17:8008/?house=B&unit=7&command=DIM";
	$cmd_string = file_get_contents_curl($url);
	echo $cmd_string; 
    }
    if(isset($_POST['B7bright'])){
	$url = "http://192.168.0.17:8008/?house=B&unit=7&command=BRIGHT";
	$cmd_string = file_get_contents_curl($url);
	echo $cmd_string; 
    }
    if(isset($_POST['B9on'])){
	$url = "http://192.168.0.17:8008/?house=B&unit=9&command=ON";
	$cmd_string = file_get_contents_curl($url);
	echo $cmd_string; 
    }
    if(isset($_POST['B9off'])){
	$url = "http://192.168.0.17:8008/?house=B&unit=9&command=OFF";
	$cmd_string = file_get_contents_curl($url);
	echo $cmd_string; 
    }
    if(isset($_POST['B9dim'])){
	$url = "http://192.168.0.17:8008/?house=B&unit=9&command=DIM";
	$cmd_string = file_get_contents_curl($url);
	echo $cmd_string; 
    }
    if(isset($_POST['B9bright'])){
	$url = "http://192.168.0.17:8008/?house=B&unit=9&command=BRIGHT";
	$cmd_string = file_get_contents_curl($url);
	echo $cmd_string; 
    }
function IsChecked($chkname,$value)
    {
        if(!empty($_POST[$chkname]))
        {
            foreach($_POST[$chkname] as $chkval)
            {
                if($chkval == $value)
                {
                    return true;
                }
            }
        }
        return false;
    }

function file_get_contents_curl($url) {
    $ch = curl_init();
     
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
    curl_setopt($ch, CURLOPT_URL, $url);
     
    $data = curl_exec($ch);
    curl_close($ch);
     
    return $data;
    }



?>

Re: Code Block Highlighting is Now Enabled

Posted: Fri Nov 13, 2020 2:10 am
by MochiMoppel
s243a wrote: Thu Nov 12, 2020 4:00 am

On my computer it looks like this which shows a different highlighting for each language.

Your display looks OK to me, but mine is different. Using default Palemoon settings and default forum theme:

differences_s243a_MM.png
differences_s243a_MM.png (41.93 KiB) Viewed 370 times

Slightly better when I use the dark ne-blackgreen theme because it uses a bigger font size, but still not comfortabe to read. I use the dark theme not because is looks fancy but because my eyesight is bad and text with a glaring white background is hard to read for me. The syntax highlighting deprives me of this choice. It enforces colored text on white background. Comments are displayed in light grey on white. This is the point when I have to throw in the towel.

@rockedge yes, seems to work now. What - not surprisingly - does not work is automatic language detection. Assuming that the vast majority of code snippets are written in bash/ash/sh it becomes mandatory to either add a shebang or indicate the language in BBcode like [code=bash]. I further assume that users will not do this because they never were required to do this. Simple snippets are posted without a shebang and enclose with what the Code button spits out. Take following example. The second without shebang shows highlighting without any meaningful context. Defeats the purpose of syntax highlighting.

Code: Select all

#!/bin/sh
if [ -e /bin/cp  ];then
	echo "/bin/cp exists"
	grep . << XYZ 2>/dev/null
	/bin/cp exists
XYZ
else
	printf "%s" '/bin/cp missing'
fi

Code: Select all

if [ -e /bin/cp  ];then
	echo "/bin/cp exists"
	grep . << XYZ 2>/dev/null
	/bin/cp exists
XYZ
else
	printf "%s" '/bin/cp missing' 
fi

Re: Code Block Highlighting is Now Enabled

Posted: Fri Nov 13, 2020 3:00 am
by rockedge

code highlighting has been disabled for further testing.