Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
Ajustar y corregir la posición del texto en el bloque de código HTML en React

Sinopsis : en ReactJS, tengo una cadena de código HTML que he formateado usando js-beautify y estilizado usando react-syntax-highlighter :

 import SyntaxHighlighter from "react-syntax-highlighter"; import { a11yDark } from "react-syntax-highlighter/dist/esm/styles/hljs"; let beautify = require("js-beautify").html; export default function App() { const beautifyHTML = () => { const code = "<div><h1>Small Piece of Text.</h1><div><h2>AReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongPieceOfText.</h2></div><h3>AnotherReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongPieceOfText.</h3></div>"; const beautifiedHTML = beautify(code, { indent_size: 2, brace_style: "expand" }); return beautifiedHTML; }; return ( <div className="App"> <SyntaxHighlighter language="html" style={a11yDark}> {beautifyHTML()} </SyntaxHighlighter> </div> ); }

En la interfaz de usuario, esto es lo que obtengo: ingrese la descripción de la imagen aquí

Aquí está Code Sandbox para verlo todo en acción y para que lo edite .

Problema : Lo que me gustaría que sucediera son dos cosas:

  1. Envuelva la línea en el ancho del div, para que no aparezca el desplazamiento horizontal.
  2. Cuando la línea pasa a la siguiente, el texto desbordado no debe comenzar al principio de la línea, sino justo debajo de donde comenzó la línea original.

Para intentar envolver el texto (Problema 1), intenté agregar lo siguiente como se sugiere en esta publicación , pero parece que solo funciona cuando el código está envuelto en una etiqueta pre , que no tengo aquí...

 .App code { white-space: pre-wrap; word-wrap: break-word; }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!