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

185
Views
Need to convert plain text to code element

I am making a website to display code for a project, and I need a way to read a text file on the server and for every line, I need it to make the text on that line a code element.

Like this:

Input (Example.txt):

Line 1
Line 2
Line 3
Line 4
Line 5

Output:

<code>Line 1</code>
<code>Line 2</code>
<code>Line 3</code>
<code>Line 4</code>
<code>Line 5</code>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Split the string by a newline, then map through the resulting array and wrap each element inside a code element:

 const str = `Line 1 Line 2 Line 3 Line 4 Line 5` const res = str.split("\n").map (e => `<code>${e}</code>`).join('\n') console.log(res)

about 4 years ago · Juan Pablo Isaza Report
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!