Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Syntax Highlighting Solution

Discussion in 'Documentation' started by Fedora_Dev, Jul 8, 2019.

  1. Fedora_Dev

    Fedora_Dev

    Joined:
    Oct 28, 2016
    Posts:
    35
    Hello Unity.

    I have two extensions in Chrome that let me add custom styles and custom javascript to a web page. With just a few lines of code, I added full syntax highlighting to the documentation pages. I think this should be something integrated by you guys already as seeing bare code is a bit difficult to read. I've provided the additions below.

    Code (JavaScript):
    1. $(function ()
    2. {
    3.     $.getScript("//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.8/highlight.min.js", function ()
    4.     {
    5.         document.querySelectorAll("pre code").forEach(item =>
    6.         {
    7.             c.classList.add("cs");
    8.             hljs.highlightBlock(item);
    9.         });
    10.     });
    11. });
    Code (CSS):
    1. .hljs {
    2.     display:block;
    3.     overflow-x:auto;
    4.     padding:.5em;
    5.     background:#F0F0F0
    6. }
    7. .hljs, .hljs-subst {
    8.     color:#444
    9. }
    10. .hljs-comment {
    11.     color:#888888
    12. }
    13. .hljs-keyword, .hljs-attribute, .hljs-selector-tag, .hljs-meta-keyword, .hljs-doctag, .hljs-name {
    14.     font-weight:bold
    15. }
    16. .hljs-type, .hljs-string, .hljs-number, .hljs-selector-id, .hljs-selector-class, .hljs-quote, .hljs-template-tag, .hljs-deletion {
    17.     color:#880000
    18. }
    19. .hljs-title, .hljs-section {
    20.     color:#880000;
    21.     font-weight:bold
    22. }
    23. .hljs-regexp, .hljs-symbol, .hljs-variable, .hljs-template-variable, .hljs-link, .hljs-selector-attr, .hljs-selector-pseudo {
    24.     color:#BC6060
    25. }
    26. .hljs-literal {
    27.     color:#78A960
    28. }
    29. .hljs-built_in, .hljs-bullet, .hljs-code, .hljs-addition {
    30.     color:#397300
    31. }
    32. .hljs-meta {
    33.     color:#1f7199
    34. }
    35. .hljs-meta-string {
    36.     color:#4d99bf
    37. }
    38. .hljs-emphasis {
    39.     font-style:italic
    40. }
    41. .hljs-strong {
    42.     font-weight:bold
    43. }
     
  2. jo-unity

    jo-unity

    Unity Technologies

    Joined:
    Mar 27, 2019
    Posts:
    33
    Hello @Fedora_Dev

    Thanks for this, it's really appreciated! We’re actually working on a new documentation website which will be coming soon and will include things like an updated design with syntax highlighting.

    I’ll pass your suggestion onto our development team to see if this is something we could improve in the meantime while we're between websites.
     
    Fedora_Dev likes this.