-1

I am building a webpage in Vue3. On this webpage I want to display some Solidity code and I would like it to be pretty and highlightend. I found the Highlight.js (link) library. And I also found "rules" for Solidity (link), since solidity doesn't come with highlight.js.

Now, I did got this to work, when I was using Flask (python), but I switched to Vue, and for the love of all that is holy, I can't get it to work now.

So far, I tried following what highlight.js has described on their website, with regards to Vze. But that didn't work. That way didn't even work when using it on "javascript" code and "python" code. The coloring was wrong...

Currently, I import highlight.js in the :

index.html

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <link rel="icon" href="<%= BASE_URL %>favicon.ico" />

    <link
      rel="stylesheet"
      href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/vs2015.min.css"
    />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>

    <script
      type="text/javascript"
      src="/node_modules/highlightjs-solidity/dist/solidity.min.js"
    ></script>
    <!-- <script
      type="text/javascript"
      src="/node_modules/highlightjs-solidity/dist/yul.min.js"
    ></script> -->
  </head>

And then in the Vue Component:

...
mounted() {
    self.hljs.highlightAll();
...

Now, this does work for "javascript" code and "python" code. It also works with random "haskell" code, when I import it in the head:

<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/haskell.min.js"></script>

But I just can't get it to work with Solidity.

1
  • Found a bad workaround (but it works, i guess). Copy the solidity.min.js from node_modules/highlightjs-solidity/dist/solidity.min.js to public/ folder of your Vue app. And then do the import inside the <head> tag like this: <script src="/solidity.min.js"></script> Commented Jan 8, 2023 at 17:54

1 Answer 1

0

It looks like the highlightjs-solidity package isn't compatible with highlight.js version 11 based on this excerpt from the npm package README:

compatibility

You might have to stay on highlight.js version 10 for Solidity syntax highlighting to work.

Sign up to request clarification or add additional context in comments.

1 Comment

Nope, this doesn't seem to slove it :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.