Any code format plugin?

NodeBB Plugins
  • Similar to markdown code block ``` but with additional of line numbers, is such plugin available?

    Please advise, thanks.

  • Put this in your custom header (ACP -> Appearance -> Custom HTML & CSS -> Custom Header):

    <script>
    require(['highlight'], function (hljs) {
      require([
        'https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/1.1.0/highlightjs-line-numbers.min.js'
      ], function () {
        $(window).on('load action:ajaxify.end', function () {
          setTimeout(function () {
            hljs.initLineNumbersOnLoad();
          }, 100);
        });
      });
    });
    </script>
    
  • @PitaJ said in Any code format plugin?:

    <script>
    require(['highlight'], function (hljs) {
    require([
    'https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/1.1.0/highlightjs-line-numbers.min.js'
    ], function () {
    $(window).on('load action:ajaxify.end', function () {
    setTimeout(function () {
    hljs.initLineNumbersOnLoad();
    }, 100);
    });
    });
    });
    </script>

    Perfect! 👍

  • @PitaJ

    This doesn't work for me (NodeBB v1.12.1). My plugins as below. Any ideas?

    nodebb-plugin-composer-default
    Default composer for NodeBB
    
    Installed 6.2.11 | Latest 6.2.11
    For more information: https://github.com/NodeBB/nodebb-plugin-composer-default#readme
    
    nodebb-plugin-dbsearch
    A Plugin that lets users search posts and topics
    
    Installed 3.0.6 | Latest 3.0.6
    For more information: https://github.com/barisusakli/nodebb-plugin-dbsearch#readme
    
    nodebb-plugin-emoji
    Adds extensible emoji functionality to NodeBB
    
     Installed 2.2.6 | Latest 3.2.0 
    For more information: https://github.com/NodeBB/nodebb-plugin-emoji#readme
    
    nodebb-plugin-emoji-android
    The Android blob emoji-set for NodeBB (requires nodebb-plugin-emoji)
    
    Installed 2.0.0 | Latest 2.0.0
    For more information: https://github.com/NodeBB-Community/nodebb-plugin-emoji-android#readme
    
    nodebb-plugin-extended-markdown
    A NodeBB plugin to add some bb code, as tooltip, anchor, custom text header with background, etc.
    
    Installed 1.4.0 | Latest 1.4.0
    For more information: https://github.com/MinecraftForgeFrance/nodebb-plugin-extended-markdown#readme
    
    nodebb-plugin-forms
    NodeBB plugin for form management
    
    Installed 0.0.1 | Latest 0.0.1
    For more information: https://github.com/NodeBB-Community/nodebb-plugin-forms
    
    nodebb-plugin-markdown
    A Markdown parser for NodeBB
    
    Installed 8.9.2 | Latest 8.9.2
    For more information: https://github.com/julianlam/nodebb-plugin-markdown#readme
    
    nodebb-plugin-mentions
    NodeBB Plugin that allows users to mention other users by prepending an '@' sign to their username
    
    Installed 2.5.2 | Latest 2.5.2
    For more information: https://github.com/julianlam/nodebb-plugin-mentions#readme
    
    nodebb-plugin-node-ldap
    Node LDAP Login
    
    Installed 1.0.0 | Latest 1.0.0
    For more information: https://github.com/ink-blot/nodebb-plugin-node-ldap
    
    nodebb-plugin-session-sharing
    Allows login sessions from your app to persist in NodeBB
    
    Installed 4.6.2 | Latest 4.6.2
    For more information: https://github.com/julianlam/nodebb-plugin-session-sharing#readme
    
    nodebb-plugin-soundpack-default
    Default Sound Pack
    
    Installed 1.0.0 | Latest 1.0.0
    For more information: https://github.com/julianlam/nodebb-plugin-soundpack-default
    
    nodebb-plugin-spam-be-gone
    anti spam using both Google Recaptcha, Akismet.com, StopForumSpam.com & ProjectHoneyPot.com
    
    Installed 0.6.1 | Latest 0.6.1
    For more information: https://github.com/akhoury/nodebb-plugin-spam-be-gone#readme
    
    nodebb-rewards-essentials
    Essential Rewards Starter Pack for NodeBB
    
    Installed 0.0.13 | Latest 0.0.13
    For more information: https://github.com/NodeBB/nodebb-rewards-essentials
    
    nodebb-theme-lavender
    Lavender Theme for NodeBB
    
    Installed 5.0.9 | Latest 5.0.9
    For more information: https://github.com/NodeBB/nodebb-theme-lavender#readme
    
    nodebb-theme-persona
    Persona theme for NodeBB
    
    Installed 9.1.29 | Latest 9.1.29
    For more information: https://github.com/psychobunny/nodebb-theme-persona#readme
    
    nodebb-theme-slick
    Slick theme for NodeBB
    
    Installed 1.2.23 | Latest 1.2.23
    For more information: https://github.com/pichalite/nodebb-theme-slick#readme
    
    nodebb-theme-vanilla
    Vanilla theme for NodeBB
    
    Installed 10.1.25 | Latest 10.1.25
    For more information: https://github.com/NodeBB/nodebb-theme-vanilla#readme
    
    nodebb-widget-essentials
    NodeBB Essential Widgets
    
    Installed 4.0.17 | Latest 4.0.17
    For more information: https://github.com/psychobunny/nodebb-widget-essentials#readme
    
  • Hmm. I tried pasting your script (without the script tags) into:
    ACP -> Appearance -> Custom HTML & CSS -> Custom Javascript

    and I got the following result:

    code_numbering.jpg

    Not usable, but a clue...

  • @quokka if you want line numbering in code blocks just go to admin/plugins/markdown and select it in CODE FORMATTING settings. You can even choose what languages will it apply to.

  • @oplik0

    Awesome. Legend. Thanks for that!


Suggested Topics