romoez / algo-tn-vscode

Visual Studio Code extension that provides syntax highlighting and snippets for pseudocode in French as it is written at high school in Tunisia.
14 stars 3 forks source link

way to support pseudo code in highlight.js ? #2

Open jeremie-diarra opened 1 year ago

jeremie-diarra commented 1 year ago

This "Algorithme en Pseudocode" is exactly the (french) pseudo code language I was looking for, so, first of all, thank you so much for this 🙏

I'm also a big fan of highlight.js, and I'm looking for a way to highlight french pseudo code on a web page. And I'm wondering if you guys got some clues on this ?

Thanks again for the great great extension, so helpful to bring life to code with the students !

jeremie-diarra commented 1 year ago

Ping @romoez & @TheLime1

TheLime1 commented 1 year ago

sorry i dont know how to transfer the code to a highlight.js function but i asked ChatGPT !

  1. Create a new .js file for your language in the highlight.js/src/languages directory.
  2. In this file, define a hljs.registerLanguage() function that takes an object defining your language's syntax rules.
  3. Copy the contents of your .json file into this object, but convert the syntax rules to the Highlight.js format.

Here is an example of what your hljs.registerLanguage() function might look like:

hljs.registerLanguage('my-language', function(hljs) {
  var keywords = 'if else while for ...';  // list of keywords in your language
  var builtins = 'print input ...';  // list of built-in functions in your language

  return {
    name: 'My Language',  // name of your language
    case_insensitive: true,  // whether your language is case-insensitive
    keywords: {
      keyword: keywords,
      built_in: builtins
    },
    contains: [
      {
        className: 'string',
        begin: "'", end: "'",
        contains: [hljs.BACKSLASH_ESCAPE]
      },
      {
        className: 'string',
        begin: '"', end: '"',
        contains: [hljs.BACKSLASH_ESCAPE]
      },
      {
        className: 'number',
        begin: '\\b\\d+(\\.\\d+)?',
        relevance: 0
      },
      // more syntax rules here
    ]
  };
});

@jeremie-diarra

jrm-omg commented 1 year ago

thanks mate, will try this :pray: