Git Product home page Git Product logo

enml_py's Introduction

ENML_PY

This is a python library for converting ENML (Evernote Markup Language, http://dev.evernote.com/start/core/enml.php) to/from HTML.

Dependencies

Usage

Convert with prettifying

>>> import ENML_PY as enml
>>> note = "<en-note>hello world</en-note>"
>>> html = enml.ENMLToHTML(note)
>>> print html
<html>
 <body>
   hello world
 </body>
</html>

Convert without prettifying

>>> import ENML_PY as enml
>>> note = "<en-note>hello world</en-note>"
>>> html = enml.ENMLToHTML(note, pretty=False)
>>> print html
<html><body>hello world</body></html>

Convert with saving resources

>>> client = EvernoteClient(token=dev_token)
>>> noteStore = client.get_note_store()
>>> mediaStore = enml.FileMediaStore(noteStore, note.guid, 'resources/')
>>> content = noteStore.getNoteContent(note.guid)
>>> html = enml.ENMLToHTML(content, False, media_store=mediaStore)

This will convert ENML to HTML, and save all the resource files related to the note in 'resources/' path, and replace all media inserted in ENML with according HTML tags with link pointing to the resource with 'file://' protocol.

Write your own MediaStore

from ENML_PY import MediaStore, MIME_TO_EXTENSION_MAPPING
class MyMediaStore(MediaStore):
    def __init__ (self, note_store, note_guid):
        super(MyMediaStore, self).__init__(note_store, note_guid)

    def save(self, hash_str, mime_type):
        # hash_str is the hash digest string of the resource file
        # mime_type is the mime_type of the resource that is about to be saved
        # you can get the mime type to file extension mapping by accessing the dict MIME_TO_EXTENSION_MAPPING

        # retrieve the binary data
        data = self._get_resource_by_hash(hash_str)
        # some saving operation
        ...
        # return the URL of the resource that has just been saved
        return some_url

TODO

  • Map other media types to the corresponding HTML tags (Only Image tag currently)
  • Convert from HTML to ENML

enml_py's People

Contributors

carllee avatar

Watchers

James Cloos avatar Li Wu avatar

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.