In my React component I use draft-js library. In my text input there is onPaste event…
- User
In my React component I use draft-js library. In my text input there is onPaste event that pastes text with the type of 'ordered-list-item'. It results in the list being pasted with numerical order. However after I send the message it just sends text itself without numbers for each line. What can I do in order to send numbers as well?
- Assistant
- User
I have a plain text. How do I convert it to BlockMap using draft-js?
- Assistant
To convert a plain text to a
BlockMapusingdraft-js, you can create aContentStateand extract the necessary components from it. Here's an example of how you can achieve this:import { EditorState, convertFromRaw, ContentState, ContentBlock, genKey } from 'draft-js'; const convertPlainTextToBlockMap = (plainText) => { const blocks = plainText.split('\n').map((text) => new ContentBlock({ key: genKey(), type: 'unstyled', text, characterList: Array(text.length).fill(), }) ); const contentState = ContentState.createFromBlockArray(blocks); return contentState.getBlockMap(); }; const plainText = "Line 1\nLine 2\nLine 3"; const blockMap = convertPlainTextToBlockMap(plainText); console.log(blockMap);In the code snippet above, the
convertPlainTextToBlockMapfunction takes a plain text as input and splits it into separate lines usingsplit('\n'). It then maps over each line to create an array ofContentBlockobjects, with each line being converted into a block. The function is used to assign a unique key to each block.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.