Syntax highlighting?


#1

Is there a way to get some sort of syntax highlighting on the site?

I think this would make sharing (and reading, obviously) snippets far more easy and comfortable.


#2

+1.

I think there is syntax highlighting, just not OCaml. I just wrote a code snippet, and had to highlight it as “text,” otherwise the highlighting was all wrong. It would be nice to get OCaml highlighting.


#3

Does it really not support ocaml?

Testing:

open Tea
open Overbots_types

let init () =
  let model = {
    start_realtime = -1.0;
    current_realtime = -1.0;
    gametime = 0.0;
    msgs = [];
    resource_values = Overbots_resource.init_resources_values;
    bool_flags = init_bool_flags;
    int_flags = init_int_flags;
    float_flags = init_float_flags;
    cache = Overbots_resource.init_cache;
  } in
  (model, Cmd.none)

let update model = function
  | UpdateFrame timeinfo ->
    let time = timeinfo.time *. 0.001 in
    let model =
      if model.start_realtime >= 0.0 then
        model
      else
        {model with start_realtime = time; current_realtime = time; gametime = 0.0}
    in Overbots_update.update_state model time
  | ActionButtonClicked bid ->
    Overbots_buttons.perform_button model bid

let subscriptions _model =
  Sub.batch [
    AnimationFrame.every updateFrame;
  ]

let main =
  App.standardProgram {
    init;
    update;
    view = Overbots_view.view;
    subscriptions;
  }

Looks fairly normal for Discourse (which uses a regex-based highlighter last I saw)?


#4

The syntax highlighting (as shown in the code snippet) is really not good: apart from the ‘let’ keyword, there are the very faintly discernable ‘function’, ‘in’, and ‘then’ keywords (but you almost have to look for it to become visible), and the buggy ‘float’ keyword highlighting, which is rather annoying.
Overall I don’t find it enough to be really useful in its current state.


#5

Apparently, Discourse uses HighlightJS for their syntax highlighting, and it supports OCaml (it’s in the “Functional” section on the demo site).

Also, this thread seems to suggest that there is a setting to manage highlighted langages.


#6

It is indeed, but this is pretty common with any language being parsed by regex parsers like HighlightJS. I’m not sure if I’ve run across any actual javascript parsers for a language, though I guess you could compile the actual ocaml parser to javascript and highlight using it, would be perfectly accurate than, though larger. ^.^


#7

I had a look, and the site did not have OCaml, Haskell or Coq in the default highlighted languages list. I removed Windows INI files and a few other probably irrelevant ones in order to make room for these.

Testing…

module Log_entry = struct
    type t =
      { session_id: string;
        time: Time.t;
        important: bool;
        message: string;
      }
  end
  module Heartbeat = struct
    type t =
      { session_id: string;
        time: Time.t;
        status_message: string;
      }
  end
  module Logon = struct
    type t =
      { session_id: string;
        time: Time.t;
        user: string;
        credentials: string;
      }
  end;;
let test = "Hello!" ;;

Discussion site status and timeline
#8

Whoo hoo! Looks like the ElixirForums discourse site highlighting now. :slight_smile:

Still not great, but better.

An interesting ocaml/bucklescript project would be to take the actual ocaml parser though and syntax highlight it. :wink: