Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
How to import a markdown or HTML file in react

I'm making a Reactjs app and I have a Readme.md markdown file that I would like to show in my app. I'm confused about how to proceed. I'm describing what I tried below but it looks to me more complicated than it should and makes me feel like I'm approaching this wrong. I'd be interested in knowing how people generally deal with including static markdown or html content in a react app or more generally in javascript.

I see multiple paths:

  1. Translate the markdown file to html and find a way to include the html in the react App.
  2. Use a javascript markdown library (such as maybe https://remark.js.org/) to render the markdown directly

The markdown also contains mathjax.

I'd have thought route 1 was the best, because the markdown is a static file and i don't need to use an extra javascript library to render it dynamically.

So I generated the HTML from the Markdown with pandoc, put it in src/assets/readme.html and tried this in my App.js:

import React from 'react';
import readme from 'assets/method.html';

const App: React.FC = () => {
  return (
      <div dangerouslySetInnerHTML={ { __front: readme } }/>
  );
};

This doesn't work however, as it produces the error:

./src/assets/method.html 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

I checked the pointed URL but couldn't find any pointer to load HTML files.

This looks more complicated than it should, I'm wondering if I'm missing something.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you can check the below code :

   fetchExternalHTML: function(fileName) {
  Ajax.getJSON('/myAPI/getExternalHTML/' + fileName).then(
    response => {
      this.setState({
        extHTML: response
      });
    }, err => {
      //handle your error here
    }
  );
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda