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

129
Visualizações
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 Respostas
Responde à pergunta

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 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