1

I'm writing a markdown editor and have an input contenteditable item, which renders formatted markdown onto another div.

<div name = "post" id = "input" class = "w-100" contenteditable></div>
<div id = "display" class = "col-md-6"></div>

Javascript code:

var md = window.markdownit()

$("#input").on("input", target =>{
    $("#display").html(md.render($("#input").text()))
})

How do I get .text() to capture newlines?

KI4JGT
  • 471
  • 2
  • 5
  • 13
  • Does this answer your question? [jQuery text() and newlines](https://stackoverflow.com/questions/4535888/jquery-text-and-newlines) – Sally loves Lightning Jun 30 '23 at 04:56
  • @LightningMcQueen No. ```.text()``` doesn't capture newlines. I finally settled with vanilla JS and innerText. The suggested question deals with text editing. My question is about text capturing. – KI4JGT Jun 30 '23 at 05:07
  • Please update your question to show what you have already tried in a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). tHis will help us to replace issues easily and give you solutions quickly. – Alive to die - Anant Jun 30 '23 at 05:22
  • It's not so much about *capturing* newlines as then outputting them - `.html(...text with newlines...)` will then render without the newlines. The linked question above helps you handle that. – freedomn-m Jun 30 '23 at 07:57
  • 1
    *I finally settled with vanilla JS and innerText.* - so you have a solution? Please add an answer (or close your question). – freedomn-m Jun 30 '23 at 08:00

0 Answers0