michelson / dante2

A complete rewrite of dante editor in draft-js
https://michelson.github.io/dante2/
Other
912 stars 121 forks source link

convertToHTML Anchor Tag #213

Closed tringas closed 4 years ago

tringas commented 4 years ago

Thank you for your work on this, Btw I don't have experience with Draftjs but I'm successfully using Dante2 on my project but I'm having one problem with anchor tag when I use convertToHTML they are rendering as unstyled paragraph instead of anchor.

const html = convertToHTML({
  styleToHTML: style => {
    if (style.startsWith("CUSTOM_COLOR_")) {
      return (
        <span
          style={{
            color: style.substr(style.length - 7),
          }}
        />
      )
    }
  },
  blockToHTML: block => {
    if (block.type === "image") {
      return (
        <img src={block.data.url} alt={block.text} />
      )
    }
    if (block.type === "code-block") {
      return (
        <code>
          <pre>{block.text}</pre>
        </code>
      )
  }
},
})(editor.state.editorState._immutable.currentContent)

Is there a easy way I can specify how the anchor tag should looks like I'm doing with images

if (block.type === "image") {
  return (
    <img src={block.data.url} alt={block.text} />
  )
}

thank you

michelson commented 4 years ago

add this to the convertToHTML:

entityToHTML: (entity, originalText) => {
        if (entity.type === 'LINK') {
          return <a href={entity.data.url}>{originalText}</a>;
        }
        return originalText;
      }