1

Im using react with meteor and the react-highlight . The problem is my code is not being highlighted and im getting this error on the console

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:3000/singlearticle/node_modules/highlight.js/styles/tomorrow.css".

What does it mean and what should I do about it.?

1
  • How do yo you import the theme "tomorrow" on your app? Commented Aug 26, 2016 at 10:45

3 Answers 3

1

You can just drop the css file tomorrow.css from "/node_modules/highlight.js/styles/tomorrow.css" in your meteor client folder it wil be automatically added to your project.

Or

On your jsx file you can import it like below:

import React, { Component } from 'react';
import Highlight from 'react-highlight';
import "../node_modules/highlight.js/styles/tomorrow.css";

export default class App extends Component {

    render() {
        return (
            <div className="container">
                <header>
                    <h1>Example</h1>
                </header>
                <Highlight className='js'>{"var test = 'hello'"}</Highlight>
            </div>
        );

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

3 Comments

I just copied the code inside that file into the main.css file and now it highlights the code and gives me no errors
Adding the css file to the client directory should work !
With the import give a relative path to the css file!
0

What is the dev environment of yours? Gulp? Webpack? It seems you do not have a correct handler for css files on React? React does not magically handle css files.

In the webpack, you will need to have a loader handling css, sass and style files. like,

  // css loader
  {
    test: /\.css$/,
    loader: "style-loader!css-loader!postcss-loader"
  },

  // font file loaders
  {
    test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
    loader: "url-loader?limit=10000&minetype=application/font-woff"
  },

  {
    test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
    loader: "file-loader"
  }

You will need to install style-loader, css-load and any other loaders that handles this type of file. So for webpack, it will automatically parse through all these kind of dependencies through the dependency tree, translate and package everything into one js file.

Comments

0

What I did was to create a file "\source\code-highlight.scss" at the root of my project, and import this file in app.js

import "@source/code-highlight.scss"; // could be css

The content of this file is gotten from any style you wish to use in

\node_modules\highlight.js\scss\

or if you use css

\node_modules\highlight.js\styles\

Just copy the style and paste in

\source\code-highlight.scss

In any file now, you could use:

import Highlight from "react-highlight";

<Highlight>{snippet}</Highlight>

Comments

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.