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

117
Views
How to replace p tag with br tag when user clicks enter wiht medium editor js

The library medium editor default behavior is to add a p tag when the user hits enter. This can cause layout and styling issues within the editable tag. Instead I would like to insert a br tag when the user hits enter.

I found this code that works as expected

 editor.subscribe("editableKeydownEnter", (event, element) => {
    //       debugger
    // if (event.shiftKey) {
    //   debugger
        event.preventDefault()
        event.stopPropagation()
        MediumEditor.selection.getSelectionStart(editor.options.ownerDocument)
        MediumEditor.util.insertHTMLCommand(editor.options.ownerDocument, "<br>")
    // }
  })

It inserts the br tag after the string of character within the editable div. However the cursor of the user stays behind the br tag so in the end the cursor doesent really goes to the line.

Is there a solution to this ?

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