Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
WISIWYG Text Length Limitation Without Breaking HTML Tags

I am using CKEditor as a WYSIWYG rich text editor with Vue3.

The editor generates its output inside an IFrame, so in the end I guess an HTML body with the text a user entered, wrapped by HTML tags. Accessing the iframe content is done with document.querySelector('iframe').contentDocument which gives me innerTextr and innerHTML, and everything is accessible.

I am trying to limit the text length, so if a user writes this text: I am an example text and this part is bold. and limitation is 23 characters, the . character will be deleted automatically. BTW this will be the output generated by the editor: <p>I am an example text and <b>this part is bold.</b></p>

So I am able to get the stripped text by removing any HTML tag, storing the "clean" text in a variable and then getting its length. Moreover, I am able to delete this letter on a keyup trigger.

Issue is, whenever a letter is deleted, it also modifies the HTML tags and break their structure. So I get this: <p>I am an example text and <b>this part is bold instead of this: <p>I am an example text and <b>this part is bold</b></p>.

Is there any better way of planning this cusomization so I will get ONLY the inner text trimmed.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The way I worked around this problem was to

  1. delete the text, obtaining <p>I am an example text and <b>this part is bold
  2. check for unclosed tags (does the nb of <x> equal the number of </x>?), and close them if needed

There may be a better way, but I wrote that piece of code about 10 years ago and it does the work just fine.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda