Git Product home page Git Product logo

draftjs's Introduction

Draft.js Exporter

Go Report Card

Draft.js is a framework for building rich text editors. However, it does not support exporting documents at HTML. This package is designed to take the raw ContentState (output of convertToRaw) from Draft.js and convert it to HTML using Go. Mostly it useful for server-side rendering. I should note this package does not provide any input validation and assumes correct and safe input data.

Usage

func main() {

	// get your contentState JSON-string
	draftState := exampleDraftStateSource

	// make auxiliary variable
	contentState := draftjs.ContentState{}
	json.Unmarshal([]byte(draftState), &contentState) // don't forget error handling

	// prepare some config (HTML here)
	config := draftjs.DefaultConfig()

	// and just render content state to HTML-string
	s := draftjs.Render(&contentState, config)

	// that's it
	fmt.Println(s)
}

For RawContentState like this

{
  "entityMap": {
    "0": {
      "type": "LINK",
      "data": {
        "url": "https://medium.com/@rajaraodv/how-draft-js-represents-rich-text-data-eeabb5f25cf2#.ce9y2wyux"
      }
    }
  },
  "blocks": [
    {
      "text": "Rich text with link",
      "type": "unstyled",
      "depth": 0,
      "inlineStyleRanges": [
        {
          "offset": 0,
          "length": 4,
          "style": "BOLD"
        }, {
          "offset": 2,
          "length": 10,
          "style": "UNDERLINE"
        }, {
          "offset": 5,
          "length": 4,
          "style": "ITALIC"
        }, {
          "offset": 10,
          "length": 4,
          "style": "CODE"
        }
      ],
      "entityRanges": [{
          "offset": 15,
          "length": 4,
          "key": 0
       }]
}]}

It will give something like this but without indention:

<p>
	<strong>Ri</strong>
	<strong>
		<ins>ch</ins>
	</strong>
	<ins>
		<em>text</em>
	</ins>
	<ins>
		<code>wi</code>
	</ins>
	<code>th</code>
	<a href="https://medium.com/@rajaraodv/how-draft-js-represents-rich-text-data-eeabb5f25cf2#.ce9y2wyux" target="_blank">link</a>
</p>

That look like

Ri ch text wi th link

Setup

You'll need Golang installed first :o)

go get github.com/ejilay/draftjs

Testing

To test run the following command in project's root directory:

go test ./...

draftjs's People

Contributors

arimeka avatar arvind-prajapati avatar ejilay avatar mkhazov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

draftjs's Issues

Make tags precached

replace some places like

return fmt.Sprintf("<%s>", tagName)

with

if cachedTag == ""
    cachedTag = fmt.Sprintf("<%s>", tagName)
return cachedTag

add HTML to draft

doest it support html to draft ? by the way , where can i find all api

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.