Author Topic: Syntax Highligting for Code  (Read 11624 times)

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Syntax Highligting for Code
« Reply #40 on: September 25, 2014, 06:23:38 AM »
done, check PM Blizz.

try useing this to help you select styles for light and dark themes instead of just edit test repeating
https://highlightjs.org/static/test.html

notice that you can select the them at the top

also this lists all the languages the highlighting supports as well as what aliases you can put in the
Code: [Select]
code=<lang> tag to force highlighting in a language. if there is enough of it the language should be auto detected but shot one liners might need some help.


Tomorrow Night Bright looks like a good dark theme
« Last Edit: September 27, 2014, 06:01:14 PM by Ryex »
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19916
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Syntax Highligting for Code
« Reply #41 on: September 29, 2014, 06:26:33 PM »
Added.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Syntax Highligting for Code
« Reply #42 on: September 29, 2014, 09:09:55 PM »
Something is wrong, this is what it was dining to me before i stopped it from useing the old css. Something is preventing the css file from loading
« Last Edit: September 29, 2014, 09:13:13 PM by Ryex »
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19916
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Syntax Highligting for Code
« Reply #43 on: September 29, 2014, 09:20:35 PM »
Try refreshing the site, clearing your cache and/or restarting your browser. When I first uploaded everything, it was totally broken. Then I pressed F5 and it was fine. Also, I removed the highlight.css in the default folder since it wasn't even being used anymore.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Syntax Highligting for Code
« Reply #44 on: September 30, 2014, 02:47:34 AM »
oh ok ya it's working now, I did some edits, it's easier to configure now as you only have to change the variables as the top of the script.
also
CODE IS PROPERLY FORMATED DURING A PREVIEW!

http://pastebin.com/wsbvtTFC

EDIT: I tried putting it in a code tag but the the existence of a code tag in the source just made it drop some of the script :(
« Last Edit: September 30, 2014, 02:57:18 AM by Ryex »
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19916
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Syntax Highligting for Code
« Reply #45 on: September 30, 2014, 07:57:36 AM »
Finally, lol! I was already looking everywhere where vs.css was defined. xD I uploaded the new one.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Syntax Highligting for Code
« Reply #46 on: October 01, 2014, 02:10:37 AM »
ah crap I forgot the most important part


replace
Code: (php) [Select]
   // Preview
    if (!empty($modSettings['ch_enable']) && in_array($context['current_action'], array('post', 'post2')))
        $context['html_headers'] .= '
        <script type="text/javascript">
            var highlightPreviewCodeBlocks = function(){
                if (highlightPreviewCodeBlocks.calling)
                    return;
                highlightPreviewCodeBlocks.calling = true;
                var blocks = document.querySelectorAll("#preview_body pre code");
                Array.prototype.forEach.call(blocks, hljs.highlightBlock);
                highlightPreviewCodeBlocks.calling = false;
            };
            
            document.querySelector("#preview_body").addEventListener("DOMSubtreeModified", highlightPreviewCodeBlocks, false);
        </script>';

with
Code: (php) [Select]
   // Preview
    if (!empty($modSettings['ch_enable']) && in_array($context['current_action'], array('post', 'post2')))
        $context['html_headers'] .= '
        <script type="text/javascript">
            var highlightPreviewCodeBlocks = function(){
                if (highlightPreviewCodeBlocks.calling)
                    return;
                highlightPreviewCodeBlocks.calling = true;
                var blocks = document.querySelectorAll("#preview_body pre code");
                Array.prototype.forEach.call(blocks, hljs.highlightBlock);
                highlightPreviewCodeBlocks.calling = false;
            };

            var initPreviewHighlighting = function(){
                if (initPreviewHighlighting.called)
                    return;
                initPreviewHighlighting.called = true;
                document.querySelector("#preview_body").addEventListener("DOMSubtreeModified", highlightPreviewCodeBlocks, false);
            };

            var initPreviewHighlightingOnLoad = function(){
                document.addEventListener("DOMContentLoaded", initPreviewHighlighting, false);
                document.addEventListener("load", initPreviewHighlighting, false);
            };
           
            initPreviewHighlightingOnLoad();
           
        </script>';

otherwise the code to highlight code in the preview section when you click the preview button doesn't get attached as the preview section doesn't exist yet.
« Last Edit: October 01, 2014, 02:14:50 AM by Ryex »
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline G_G

  • Green Gmod Game_Guy AKA G4 AKA hyper-G AKA G-force
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 6585
  • LV: 407
  • Gender: Male
    • View Profile
Re: Syntax Highligting for Code
« Reply #47 on: October 01, 2014, 03:44:02 AM »
Absolutely loving it. Awesome job Ryex.

Offline WhiteRose

  • Trying to code in Ruby
  • Moderator
  • Lexima Warrior
  • ***
  • Posts: 2341
  • LV: 127
  • Gender: Female
  • <3
    • View Profile
Re: Syntax Highligting for Code
« Reply #48 on: October 01, 2014, 07:51:58 AM »
Is it supposed to look like this, or is something not working properly for me?

(click to show/hide)

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2970
  • LV: 369
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Syntax Highligting for Code
« Reply #49 on: October 01, 2014, 08:22:48 AM »
It looked like that for me the first time too. But refreshing did the trick. It's one of those many mysteries of the internet~



(click to show/hide)
NNID: KK20-CP

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Syntax Highligting for Code
« Reply #50 on: October 01, 2014, 08:30:03 AM »
if it looks like that It means it' cached the old highlight.pack.js/css files and you need to force the page to refresh.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19916
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Syntax Highligting for Code
« Reply #51 on: October 01, 2014, 12:51:14 PM »
The same happens for me briefly after loading/reloading the site, just before the highlighting is applied. Even with the new code.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19916
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Syntax Highligting for Code
« Reply #52 on: October 04, 2014, 08:37:59 AM »
*double post* Ryex, something's wrong. Check out the script. Its line breaks are broken.

http://forum.chaos-project.com/index.php/topic,4284.0
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Syntax Highligting for Code
« Reply #53 on: October 04, 2014, 05:49:17 PM »
it's auto detecting as elixir instead of ruby. we should probably go and generate a Highlight.pack.js that doesn't include every language possible to avoid it detecting the weird languages.

we should probably go here and build a version with less than all the languages
https://highlightjs.org/download/
« Last Edit: October 04, 2014, 06:57:38 PM by Ryex »
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19916
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Syntax Highligting for Code
« Reply #54 on: October 05, 2014, 05:14:49 PM »
Done.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Syntax Highligting for Code
« Reply #55 on: October 11, 2014, 08:27:10 PM »
I figured out why we get the weird formatting on non highlighted blocks of text (remember you can turn off hilightinging by useing code=nohighlight or code=no-highlight)
you need to add
Code: (nohighlight) [Select]
display: block;

to all your
Code: (css) [Select]
.code, pre.code {
...
}

blocks in your theme css files
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19916
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Syntax Highligting for Code
« Reply #56 on: October 12, 2014, 11:35:39 AM »
Done.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline G_G

  • Green Gmod Game_Guy AKA G4 AKA hyper-G AKA G-force
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 6585
  • LV: 407
  • Gender: Male
    • View Profile
Re: Syntax Highligting for Code
« Reply #57 on: October 25, 2015, 07:17:24 AM »
Dunno if it's something that can be fixed, but it doesn't seem to be liking the tab character.

You can clearly see there's a tab.


But it won't show it in the post.


Making scripts look like garbage.


Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19916
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Syntax Highligting for Code
« Reply #58 on: October 25, 2015, 08:51:09 AM »
IDK. ._.;
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Syntax Highligting for Code
« Reply #59 on: October 26, 2015, 07:30:34 PM »
it's because the web in general doesn't like the tab character there is no standardizes support for it's display.

replacing with spaces might be the only option
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)