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

196
Visualizações
How to achieve multi-line output with formatting in JavaScript

I am experimenting with the following codepen.io trinket and trying to achieve multiline output with formatting for the JavaScript text that is returned in response to user-input.

For instance, if the user types "/engage" the following text is returned:

"Follow the white rabbit. I want this to be the second line"

The code is below. I would like the above text to:

a) be output on two separate lines with my being able to control the breaks between lines (like br in HTML) b) allow some basic formatting - specifically to add bold formatting to the word "rabbit". c) allow for changing the font size of "follow" to a larger font/or different style etc.

In short, I want to be able to add formatting (hyperlinks are also a key one) and can't find any direct documentation on this for useful reference. the \n works for line breaks, thank you @epascarello

I have tried various things but they all come up with errors.

RELEVANT CODE

submitForm.addEventListener("submit", function(e) {
    e.preventDefault();
    if (input.value === "/clear") {
        clearCommand();
    } else if (input.value === "/list" || input.value === "help") {
        listAllCommands();
    } else if (input.value === "/connect") {
        goProgress();
    } else if (input.value === "/engage") {
        matrixEffect();
        clearCommand();
        textArea.value = "Follow the white rabbit. I want this to be the second line"
    } else {
        textArea.value +=
            "\nERROR: Unknown command! Type 'help' for list of commands.";
        input.value = "";
    }
    textArea.scrollTop = textArea.scrollHeight;
});

CODEPEN ENTIRE SNIPPET

https://codepen.io/damyco/pen/oyewjR

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