Discourse Solidity syntax highlighting

We don’t have proper syntax highlighting for Solidity code blocks. I tried highlightjs-solidity but for some reason it didn’t work.

Has anyone seen Solidity syntax highlighting in a Discourse forum so we can ask how they set it up?

Have you tried asking around in https://ethereum-magicians.org/?

Good suggestion but there doesn’t seem to be Solidity highlighting there either.

What was the solution as there is some highlighting in the forum?

I didn’t see Solidity as one of the languages in https://highlightjs.org/

pragma solidity ^0.5.0;

contract DoggoToken is ERC20, ERC20Detailed, ERC20Mintable, ERC20Burnable {

    constructor(
        string name,
        string symbol,
        uint8 decimals
    )
        ERC20Burnable()
        ERC20Mintable()
        ERC20Detailed(name, symbol, decimals)
        ERC20()
        public
    {}
}
1 Like

@abcoathup No solution yet! :disappointed:

The highlighting that you see is a random one that highlightjs is detecting. It seems to be C#.

I would love for us to fix this. We should try highlightjs-solidity again. I may have been doing something wrong.

2 Likes

I asked the creator of highlightjs-solidity https://twitter.com/abcoathup/status/1127827530432385024 but he wasn’t able to advise.

I have asked in the meta discourse. https://meta.discourse.org/t/how-to-get-solidity-syntax-highlighting/117774 the response was to do a PR to highlightjs to get Solidity added as a language and then Discourse would add it to an update.

1 Like

highlightjs-solidity needs an update

2 Likes

It seems like there's an alternative. (Ignore that the tityle says "Hack", the link is to the comment with the official way to do it.)

This is what I tried back then but couldn't get to work. It's worth trying it once more IMO.

1 Like

I have started on a PR for highlightjs Issue #2047 to add the Solidity language.

According to a maintainer of highlightjs

https://github.com/highlightjs/highlight.js/pull/2051#issuecomment-499711780
Solidity should stay in it’s own repo :slight_smile: we are splitting out the languages.

I haven't found out how to get the https://github.com/highlightjs/highlightjs-solidity/ repo picked up by Discourse.

Discourse support have provided instructions on how to do this:

As an aside haltman-at has updated the syntax highlighting in the hightlightjs-solidity repo https://github.com/highlightjs/highlightjs-solidity/pull/5

I have installed the custom theme-component and enabled on the Light and Dark Theme.

We now have Solidity syntax highlighting.

pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol";
import "openzeppelin-solidity/contracts/drafts/Counters.sol";

contract GameItem is ERC721Full {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() ERC721Full("GameItem", "ITM") public {
    }

    function awardItem(address player, string memory tokenURI) public returns (uint256) {
        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();
        _mint(player, newItemId);
        _setTokenURI(newItemId, tokenURI);

        return newItemId;
    }
}
3 Likes

Where has this been all my life!

Any chance for a solidity FORMATTER for Vscode? :slight_smile:

2 Likes

I created a new topic: Wanted: Solidity formatter for Visual Studio Code

1 Like

I have turned on syntax highlighting for indented code blocks too.
Setting: Force apply code highlighting to all preformatted code blocks even when they didn’t explicitly specify the language.

Example of indented code

import "openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol";
import "openzeppelin-solidity/contracts/drafts/Counters.sol";

contract GameItem is ERC721Full {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() ERC721Full("GameItem", "ITM") public {
    }

    function awardItem(address player, string memory tokenURI) public returns (uint256) {
        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();
        _mint(player, newItemId);
        _setTokenURI(newItemId, tokenURI);

        return newItemId;
    }
}
1 Like

SUGOOOOIIIII :sparkles: