Jump to content

Syntax highlighting - plain code option please!


cfish

Recommended Posts

When adding code blocks to a post, the only options are HTML, CSS, JS and PHP. But what about all the other code languages out there. Obviously it's not possible to cater for every language but can we please at least have a "plain" code option that doesn't attempt any highlighting. At least that way other code languages can be added, even if not highlighted. At the moment, the only option is to use one of the available options which results in odd and incorrect highlighting.

Link to comment
Share on other sites

Having done some more research, it seems that there is a "None" option in IPB3.4 but this has been dropped in IPB4. Why on Earth did that happen?

This could well be a deal-breaker for me. I'm currently planning a move from vB for a forum with a large proportion of coders using coding languages other than those available in IPB4.

 

code-options.png

Link to comment
Share on other sites

There is a plugin offered  by the editor that adds a good bit of langues and the none option I believe

​I've no doubt I could spend a couple of weeks working on a bespoke solution to the problem but it seems nonsensical to remove a feature that made the product much more inclusive. Effectively, IPB4 cannot be used by any community of coders that require anything other than HTML, CSS, JS and PHP.

Link to comment
Share on other sites

Calm down before you go all :frantics: lol

He is referring to something like: http://ckeditor.com/addon/codesnippet

Which you can just drop in if your community needs such features. There are tons of editor plugins available.

​OK, point taken :tongue:

But, when you say "drop in", what exactly do you mean? If you could give a brief pointer on this, I'll check it out.

Thanks.

Link to comment
Share on other sites

OK, I installed Code Snippet, Widget and Line Utilities (dependencies) using the Admin CP. All went well but having done that, I see no difference in the editor or in the code options drop-down. Do I need to edit some config file or initialise it in some way?

Link to comment
Share on other sites

Ah! OK, you have to install everything in reverse order otherwise nothing works (the install error message is not clear).

1. Add button: Line Utilities

2. Add button: Widget

3. Add button: Code Snippet

It almost works :sad:

If I add some LISP code and select any option, it just gets posted as plain text and not a code block, presumably because the language is not recognised. So, all I need to do now is spend a few weeks learning how to write a javascript syntax highlighter for LISP. Oh joy!

Link to comment
Share on other sites

Ah! OK, you have to install everything in reverse order otherwise nothing works (the install error message is not clear).

1. Add button: Line Utilities

2. Add button: Widget

3. Add button: Code Snippet

It almost works :sad:

If I add some LISP code and select any option, it just gets posted as plain text and not a code block, presumably because the language is not recognised. So, all I need to do now is spend a few weeks learning how to write a javascript syntax highlighter for LISP. Oh joy!

​According to https://github.com/google/code-prettify, lisp (and a whole load of other languages) are supported by plugins. The lisp plugin is https://github.com/google/code-prettify/blob/master/src/lang-lisp.js - just include that file with the rest of your JS.

Note: I haven't actually tested it, so I'm not 100% sure that it works in IPS4. However, when injected into this page, it doesn't throw any errors, so it looks like it should work.

Just tested - it does work :)

Though I've found a bug with the built in code tags - by default, no language-specific class is applied to the code, so the prettyprinter has to autodetect the language. It also means that when you edit the code, the syntax highlighter in the editor defaults to HTML. If I edit the code that's posted to the server (by intercepting the POST request) and add the relevant class, it works fine. Inside the editor before it's sent to the server, it has the data-pbcklang attribute, but still no lang-* class. The data-pbcklang attribute is posted to the server, but presumably stripped out by your html sanitiser.

Link to comment
Share on other sites

​According to https://github.com/google/code-prettify, lisp (and a whole load of other languages) are supported by plugins. The lisp plugin is https://github.com/google/code-prettify/blob/master/src/lang-lisp.js - just include that file with the rest of your JS.

Note: I haven't actually tested it, so I'm not 100% sure that it works in IPS4. However, when injected into this page, it doesn't throw any errors, so it looks like it should work.

Just tested - it does work :)

Though I've found a bug with the built in code tags - by default, no language-specific class is applied to the code, so the prettyprinter has to autodetect the language. It also means that when you edit the code, the syntax highlighter in the editor defaults to HTML. If I edit the code that's posted to the server (by intercepting the POST request) and add the relevant class, it works fine. Inside the editor before it's sent to the server, it has the data-pbcklang attribute, but still no lang-* class. The data-pbcklang attribute is posted to the server, but presumably stripped out by your html

yeah, quite a few bugs in this area. I've had to do a lot of mods to make plain/other languages work. I've reported a lot some pending, some denied, some ignored :)  This is the one that you mentioned above I think http://community.invisionpower.com/4bugtrack/rc7a-pbckcode-not-using-correct-prettyprint-classes-r4925/ 

Link to comment
Share on other sites

Adding new plugins is a bit of a chore as well. The other syntax highlighter plugins need configuration in config.js which gets wiped out on upgrade. There are also some conflicts with hard coded IPS configs which can only be overridden by manually editing JavaScript within the db (ui.editor). For example, the built in plugin pbckcode can be configured to add other languages usually by editing config.js. Unfortunately IPS have already hard coded that particular option so editing config.js doesn't work. Like I said, a lot of mods required to fine tune this stuff. I've uploaded a plugin that works around the bug mentioned in the previous post, but I still edit the db manually to add a plain text option and another language. 

Link to comment
Share on other sites

This just seems way too difficult for something that ought to be in there by default. I cannot understand why a non-highlighted code option isn't included as an option. This one addition would mean code blocks can be added to posts for any language (sans highlighting). As it stands, I can't move to IPS and as I said above, this is a deal-breaker :sad:, which is really sad because in every other respect, IPS is ideal.

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

I realise development efforts are primarily directed towards stability at the moment but is there any update on this? I'd love to move my forum to IPB but can't do so until the "None" code option has been restored to 4.0.

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...
  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...