Code Block Highlighting is Now (Disabled)

Ideas and discussion


Post Reply
User avatar
rockedge
Site Admin
Posts: 6521
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2727 times
Been thanked: 2614 times
Contact:

Code Block Highlighting is Now (Disabled)

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

s243a
Posts: 501
Joined: Mon Dec 09, 2019 7:29 pm
Has thanked: 90 times
Been thanked: 37 times

Re: Code Block Highlighting is Now Enabled

Post 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?

User avatar
sc0ttman
Posts: 93
Joined: Sat Aug 22, 2020 3:55 pm
Has thanked: 4 times
Been thanked: 33 times

Re: Code Block Highlighting is Now Enabled

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

Last edited by rockedge on Thu Nov 12, 2020 1:55 am, edited 2 times in total.
Reason: enabled Markdown parsing
s243a
Posts: 501
Joined: Mon Dec 09, 2019 7:29 pm
Has thanked: 90 times
Been thanked: 37 times

Re: Code Block Highlighting is Now Enabled

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

Last edited by rockedge on Wed Nov 11, 2020 11:43 pm, edited 1 time in total.
Reason: enabled Markdown parsing
User avatar
rockedge
Site Admin
Posts: 6521
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2727 times
Been thanked: 2614 times
Contact:

Re: Code Block Highlighting is Now Enabled

Post 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}`;
User avatar
rockedge
Site Admin
Posts: 6521
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2727 times
Been thanked: 2614 times
Contact:

Re: Code Block Highlighting is Now Enabled

Post 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/

s243a
Posts: 501
Joined: Mon Dec 09, 2019 7:29 pm
Has thanked: 90 times
Been thanked: 37 times

Re: Code Block Highlighting is Now Enabled

Post 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?

User avatar
rockedge
Site Admin
Posts: 6521
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2727 times
Been thanked: 2614 times
Contact:

Re: Code Block Highlighting is Now Enabled

Post 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

s243a
Posts: 501
Joined: Mon Dec 09, 2019 7:29 pm
Has thanked: 90 times
Been thanked: 37 times

Re: Code Block Highlighting is Now Enabled

Post 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"; ?>
User avatar
MochiMoppel
Posts: 1229
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 436 times

Re: Code Block Highlighting is Now Enabled

Post by MochiMoppel »

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

Attachments
syntax_highlighting.png
syntax_highlighting.png (18.12 KiB) Viewed 402 times
User avatar
rockedge
Site Admin
Posts: 6521
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2727 times
Been thanked: 2614 times
Contact:

Re: Code Block Highlighting is Now Enabled

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

s243a
Posts: 501
Joined: Mon Dec 09, 2019 7:29 pm
Has thanked: 90 times
Been thanked: 37 times

Re: Code Block Highlighting is Now Enabled

Post 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 451 times
s243a
Posts: 501
Joined: Mon Dec 09, 2019 7:29 pm
Has thanked: 90 times
Been thanked: 37 times

Re: Code Block Highlighting is Now Enabled

Post 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 :)

User avatar
rockedge
Site Admin
Posts: 6521
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2727 times
Been thanked: 2614 times
Contact:

Re: Code Block Highlighting is Now Enabled

Post 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;
    }



?>
User avatar
MochiMoppel
Posts: 1229
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 436 times

Re: Code Block Highlighting is Now Enabled

Post 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 399 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
User avatar
rockedge
Site Admin
Posts: 6521
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2727 times
Been thanked: 2614 times
Contact:

Re: Code Block Highlighting is Now Enabled

Post by rockedge »

code highlighting has been disabled for further testing.

Post Reply

Return to “Forum Organization & Structure Council”