Tiptap: How to get selected text?

Created on 20 Jun 2019  路  3Comments  路  Source: ueberdosis/tiptap

Can you provide a method?

feature request

Most helpful comment

This is already possible with textBetween:

const { selection, state } = this.editor
const { from, to } = selection
const text = state.doc.textBetween(from, to, ' ')

All 3 comments

This is already possible with textBetween:

const { selection, state } = this.editor
const { from, to } = selection
const text = state.doc.textBetween(from, to, ' ')

@philippkuehn
Is there possible to get the selected part but the HTML version? So, not only text.

That gets only the text, not a structured kind of content (e. g. headlines, paragraphs), so there鈥檚 nothing that can be transformed to HTML.

If your editor looks like that:

# Headline

Text

And you select #Head only. What would you expect?

This:
<h1>Head

Or this:
<h1>Head</h1>

Both is wrong for different reasons. The first wouldn鈥檛 be the HTML you鈥檇 need to work with. And the second wouldn鈥檛 be the structure from the document.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dolbex picture dolbex  路  3Comments

asseti6 picture asseti6  路  3Comments

git-mischa picture git-mischa  路  3Comments

leandromatos picture leandromatos  路  4Comments

pk-pressf1 picture pk-pressf1  路  3Comments