enex

package module
v0.0.0-...-e62dc8d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2021 License: MIT Imports: 10 Imported by: 0

README

go-enex - Convert Evernote's export file(*.enex) into HTML and images

Library for Go

package main

import (
    "fmt"
    "io"
    "os"

    "github.com/zetamatta/go-enex"
)

func mains() error {
    data, err := io.ReadAll(os.Stdin)
    if err != nil {
        return err
    }
    export, err := enex.Parse(data)
    if err != nil {
        return err
    }
    html, images := export.Html("images-")
    fmt.Println(html)

    for fname, data := range images {
        fmt.Fprintf(os.Stderr, "Create File: %s (%d bytes)\n", fname, len(data))
        os.WriteFile(fname, data, 0666)
    }
    return nil
}
func main() {
    if err := mains(); err != nil {
        fmt.Fprintln(os.Stderr, err.Error())
        os.Exit(1)
    }
}
$ go run example.go < sample.enex > sample.html
Create File: images-image_19.png (7232 bytes)
Create File: images-image_21.png (3633 bytes)
Create File: images-image_4.png (50815 bytes)
Create File: images-image_9.png (54726 bytes)
Create File: images-image_11.png (52430 bytes)
Create File: images-image_13.png (52293 bytes)

Executable

$ cd cmd/enexToHtml
$ go build
$ ./enexToHtml           [-prefix=PREFIX] < ENEX-FILENAME.enex > ENEX-FILENAME.html
$ ./enexToHtml -markdown [-prefix=PREFIX] < ENEX-FILENAME.enex > ENEX-FILENAME.md
$ ./enexToHtml [-markdown] [-prefix=PREFIX] ENEX-FILENAME.enex
  • The PREFIX is used as filename-header for image-files.
  • -markdown option is by mattn/go-godown

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRenamer

func DefaultRenamer(imagePathHeader string) func(string, int) string

func ShrinkMarkdown

func ShrinkMarkdown(r io.Reader, w io.Writer)

Types

type Export

type Export struct {
	Content  string
	Resource map[string][]*Resource // filename to the multi resources
	Hash     map[string]*Resource   // hash to the one resource
}

func Parse

func Parse(data []byte) (*Export, error)

func (*Export) Html

func (exp *Export) Html(imagePathHeader string) (html string, images map[string][]byte)

func (*Export) HtmlAndImagesWithRenamer

func (exp *Export) HtmlAndImagesWithRenamer(renamer func(string, int) string) (html string, images map[string]*Resource)

type Resource

type Resource struct {
	Mime      string
	SourceUrl string
	Hash      string

	FileName string
	Width    int
	Height   int
	// contains filtered or unexported fields
}

func (*Resource) Data

func (rsc *Resource) Data() []byte

func (*Resource) WriteTo

func (rsc *Resource) WriteTo(w io.Writer) (int64, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL