Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] (I know it's an outdated language, but) BBcode #2592

Closed
JapanYoshi opened this issue Jun 5, 2020 · 13 comments · Fixed by #2867
Closed

[Request] (I know it's an outdated language, but) BBcode #2592

JapanYoshi opened this issue Jun 5, 2020 · 13 comments · Fixed by #2867
Labels
enhancement An enhancement or new feature

Comments

@JapanYoshi
Copy link

Is your request related to a specific problem you're having?
I'm here from Discord, and I had to describe how to do something on a bulletin board site using BBcode. I noticed that starting the code block with ```bbcode did nothing.

The solution you'd prefer / feature you'd like to see added...
I'd like basic syntax highlighting added for BBcode.

The main (only?) components of BBcode that I want highlighted are tags and emotes.

Regex for tags (just a guess): \[(\w+|\*)(=[.]+)?\]

Tags that don’t support a parameter: b, i, u, s, center, spoiler, youtube

Tags that require a parameter: img, font, color, size

Tags with an optional parameter: url, quote, box (found on osu! forums)

Regex for board-defined emotes (also a guess): :[\w_]+:

Common emotes: =>, :D, :S, :cool:, :'(, :eek:, :evil:, :!:, :(, :idea:, :lol:, :@, :green:, :|, :?:, :P, :$, 8-), :), :o, :devil:, :wink:, :hehe:, ¬_¬, x_x, ^_^, :XD:, :-3, :vhappy:, :doh:, in addition to unbroken text surrounded within two :s

@JapanYoshi JapanYoshi added the enhancement An enhancement or new feature label Jun 5, 2020
@taufik-nurrohman
Copy link
Member

This should be enough to get started 😉

hljs.registerLanguage('bbcode', function(hljs) {
  return {
    contains: [
      {
        className: 'template-tag',
        begin: /\[/, end: /\]/
      },
      {
        className: 'symbol',
        begin: /[:;]'?\-?[\)\(SPD]/i
      },
      {
        className: 'symbol',
        begin: /:/, end: /:/,
        illegal: /\s/
      }
    ]
  };
});

Demo: https://jsfiddle.net/r6g2qvd7/

@JapanYoshi
Copy link
Author

That's great! I'd color it like this:
image

@joshgoebel
Copy link
Member

joshgoebel commented Jun 5, 2020

A 3rd party language module for BBCode would be pretty cool!


From our documentation:

This is a general answer to requests for adding new languages that appear from
time to time in the highlight.js issue tracker and discussion group.

Highlight.js doesn't have a fundamental plan for implementing languages,
instead the project works by encouraging development of 3rd party language
grammars from contributors. We're also happy to host 3rd party language
grammars at the highlightjs GitHub organization - no matter how obscure
or weird.

This means that there's no point in requesting a new language without
providing an implementation for it
. If you want to see a particular language
included in highlight.js but cannot implement it, the best way to make it
happen is to get another developer interested in doing so. Here's our
:doc:language-guide.

If you might be interested in contributing a 3rd party language grammar you can start at:

https://github.com/highlightjs/highlight.js/blob/master/extra/3RD_PARTY_QUICK_START.md

@joshgoebel
Copy link
Member

Closing per provided explanation. If someone wants to work on a 3rd party grammar we'd be happy to add a link to it to supported languages.

@JapanYoshi
Copy link
Author

@yyyc514 - The link to "3RD_PARTY_QUICK_START" returns a 404.

@joshgoebel
Copy link
Member

Fixed.

@taufik-nurrohman
Copy link
Member

A 3rd party language module for BBCode would be pretty cool!

I would consider making it official repository if I have the chance.

That’s great! I’d color it like this.

If it is the color of the HTML tag, I’m afraid it doesn’t conform to the purpose of the HTML class in Highlight.js. BBCode symbols are more inclined to template syntax like Twig and Handlebars compared to HTML markup. Let’s see…

@JapanYoshi
Copy link
Author

If it is the color of the HTML tag, I’m afraid it doesn’t conform to the purpose of the HTML class in Highlight.js. BBCode symbols are more inclined to template syntax like Twig and Handlebars compared to HTML markup. Let’s see…

I meant that the equals sign and the value should be highlighted separately...

@RedGuy12
Copy link
Contributor

RedGuy12 commented Nov 14, 2020

I made one, but I don't know how to add it (I'm new to GitHub).

hljs.registerLanguage('bbcode', function (hljs) {
    return {
        case_insensitive: true,
        contains: [
            {
                className: 'name',
                begin: /\[[^=\s\]]*/
            },
            {
                className: 'name',
                begin: ']'
            },
            {
              className: 'attribute',
              begin: /(?<==)[^\]\s]*/
            },
            {
                className: 'attr',
                begin: /(?<=\[[^\]]* )[^\s=\]]*/
            },
            {
                className: 'string',
                begin: /[=;:8]'?\-?[\)\(3SPDO>@$|/]/
            },
            {
                className: 'string',
                begin: /:[\w]*:/
            }
        ]
    };
});
hljs.initHighlightingOnLoad();

@joshgoebel
Copy link
Member

joshgoebel commented Nov 14, 2020

https://github.com/highlightjs/highlight.js/blob/master/extra/3RD_PARTY_QUICK_START.md

Or you can just leave it right here and anyone who googles will probably find this thread and then they could include the source code in their project if they wanted to. We currently don’t add new languages to the core library so if you want this out in the world you can either leave it right here or you can publish it to your own repository as a third-party grammar which people can choose to use if they want.

@RedGuy12
Copy link
Contributor

https://github.com/highlightjs/highlight.js/blob/master/extra/3RD_PARTY_QUICK_START.md

Or you can just leave it right here and anyone who googles will probably find this thread and then they could include the source code in their project if they wanted to. We currently don’t add new languages to the core library so if you want this out in the world you can either leave it right here or you can publish it to your own repository as a third-party grammar which people can choose to use if they want.

i made a repo, is this good? https://github.com/RedGuy12/highlightjs-bbcode

@joshgoebel
Copy link
Member

It's a little unconventional (layout of the files, etc)... but it works. :-) If you want to make a PR and add a link to SUPPORTED_LANGUAGES please do so!

@RedGuy12
Copy link
Contributor

Added with #2867

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants