how can i add data attribute in a 'a href' link htmlToDraft html-to-draftjs

Viewed 188

When i write

<a data-x='test' href='testlink' target='_blank'>testlinnk</a>

in a string and i try to add it the editor by code i got in the editor

<a href='testlink' target='_blank'>testlinnk</a>

any suggestion how to bring data-x='test' to the editor with the a tag?

This is my code

const readMoreLink = ` <a data-x='test' href='testlink' target='_blank'>testlinnk</a>`;

const newContent = Modifier.replaceWithFragment(
 editorState.getCurrentContent(),
 editorState.getSelection(), 
 BlockMapBuilder.createFromArray(htmlToDraft(readMoreLink).contentBlocks)
);
  
  const newState = EditorState.push(
    editorState,
    newContent,
    "insert-fragment"
  );
0 Answers
Related