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

136
Views
analice las etiquetas html de la cadena y cree una matriz en javaScript, vue.js

Estoy tratando de hacer una matriz a partir de una cadena. la cadena contiene etiquetas HTML como P , span , a , img . algunos están anidados como la etiqueta span dentro de p , la etiqueta img dentro de a, etc. No reemplazaría ninguna etiqueta o estilo . Estoy tratando de analizar todas las etiquetas y hacer una matriz.

El código de ejemplo se ve así en la variable textData

 var line_array =[]; var textData : ` <img src="imgurl" alt="" /> <p>some text</p> <p style="cssStyle">some text</p> <span style="cssStyle"> some text </span> <p style="cssStyle">some text<span style="cssStyle"> span text </span></p> <a href=""><span style="style">text</span><img src="https://via.placeholder.com/100" alt=""/> </a> ` activate: function (){ let sourceText = document.getElementById('sourceText').innerHTML; line_array = sourceText; }

Estoy tratando de hacer que una matriz se vea así ... de textData

 line_array =[ '<img src="imgurl" alt="" />', '<p>some text</p>', '<p style="cssStyle">some text</p>', '<span style="cssStyle"> some text </span>', '<p style="cssStyle">some text<span style="cssStyle"> span text </span</p>', '<a href=""><span style="style">text</span><img src="imgurl" alt=""/></a>' ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esto es difícil o imposible de hacer solo con expresiones regulares (dependiendo de la complejidad del HTML que desee/necesite permitir). Puedes usar split-html .

 <script src="https://cdn.jsdelivr.net/npm/split-html@1.1.0/index.min.js"></script> <script> const textData = ` <img src="imgurl" alt="" /> <p>some text</p> <p style="cssStyle">some text</p> <span style="cssStyle"> some text </span> <p style="cssStyle">some text<span style="cssStyle"> span text </span></p> <a href=""><span style="style">text</span><img src="https://via.placeholder.com/100" alt=""/> </a> ` const line_array = splitHtml(textData, 'img, a, p').filter(String); console.log(line_array); </script>
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!