enex

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: MIT Imports: 12 Imported by: 0

README

GoDoc

Go-enex & Unenex

Convert Evernote's export file(*.enex) into HTML(or markdown) and images.

  • go-enex : the package for Go
  • unenex : the executable using go-enex

How to use Unenex

Install

Download the binary package from Releases and extract the executable.

Use go install
go install github.com/hymkor/go-enex/cmd/unenex@latest
Use scoop-installer
scoop install https://raw.githubusercontent.com/hymkor/go-enex/master/unenex.json

or

scoop bucket add hymkor https://github.com/hymkor/scoop-bucket
scoop install unenex
Usage
$ unenex {options} {ENEX-FILENAME.enex}

Available Options

  • -d directory: Specifies the output directory (default is the current directory ".").
  • -markdown: Outputs the content in shrinked markdown format.
  • -sf path: Specifies the path to a stylesheet file.
  • -st stylesheet: Specifies the stylesheet directly as a string.
  • -v: Enables verbose mode to display additional information during execution.
  • -web-clip-only: Outputs only the web-clip content, removing Evernote-specific styling and non-web-clip elements.

Library for Go

package main

import (
    "fmt"
    "io"
    "os"

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

func mains() error {
    data, err := io.ReadAll(os.Stdin)
    if err != nil {
        return err
    }
    notes, err := enex.Parse(data, os.Stderr)
    if err != nil {
        return err
    }
    for _, note := range notes {
        html, bundle := note.Extract(nil)
        baseName := bundle.BaseName
        err := os.WriteFile(baseName+".html", []byte(html), 0644)
        if err != nil {
            return err
        }
        fmt.Fprintf(os.Stderr, "Create File: %s.html (%d bytes)\n", baseName, len(html))

        if len(bundle.Resource) > 0 {
            fmt.Fprintf(os.Stderr, "Create Dir: %s", bundle.Dir)
            os.Mkdir(bundle.Dir, 0755)
            for fname, rsc := range bundle.Resource {
                data, err := rsc.Data()
                if err != nil {
                    return err
                }
                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)
    }
}

License

MIT License

Acknowledgements

Release notes

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilesToHtmls added in v0.4.0

func FilesToHtmls(rootDir, styleSheet string, enexFiles []string, webClipOnly bool, wDebug, wLog io.Writer) error

FilesToHtmls converts multiple ENEX files into HTML format. The output HTML files are saved under the directory specified by rootDir, with each ENEX file being processed. The styleSheet is applied to the HTML, and debug and log information are written to wDebug and wLog, respectively. If webClipOnly is true, only the web-clip content will be output without Evernote styling.

func FilesToMarkdowns added in v0.4.0

func FilesToMarkdowns(rootDir string, htmlToMarkdown func(io.Writer, io.Reader) error, enexFiles []string, wDebug, wLog io.Writer) error

FilesToMarkdowns processes multiple enex files, converts each to markdown, and saves the output in the specified rootDir. The htmlToMarkdown function is used to convert HTML content to markdown. Debug and log information are written to wDebug and wLog, respectively.

func ToHtmls added in v0.4.0

func ToHtmls(rootDir, enexName string, source []byte, styleSheet string, webClipOnly bool, wDebug, wLog io.Writer) error

ToHtmls converts a single ENEX file into HTML format. The output HTML is saved under the directory specified by rootDir, with enexName as the note name. The content is read from source, the styleSheet is applied to the HTML, and debug and log information is written to wDebug and wLog, respectively. If webClipOnly is true, only the web-clip content will be output without Evernote styling.

func ToMarkdowns added in v0.4.0

func ToMarkdowns(rootDir, enexName string, source []byte, htmlToMarkdown func(io.Writer, io.Reader) error, wDebug, wLog io.Writer) error

ToMarkdowns converts an ENEX file to markdown format. The output markdown is saved under the directory specified by rootDir, with the file named enexName. The source contains the ENEX data, and the htmlToMarkdown function is used to convert HTML to markdown. Debug and log information are written to wDebug and wLog, respectively.

Types

type Bundle added in v0.4.1

type Bundle struct {
	Resource map[string]*Resource
	BaseName string
	Dir      string
	// contains filtered or unexported fields
}

Bundle is a type that contains information about attachments.

func (*Bundle) Extract added in v0.4.1

func (B *Bundle) Extract(rootDir string, log io.Writer) error

Extract saves all attachments into subdirectories under rootDir. Each attachment is saved in a subdirectory named after the original note's name, formatted as "(note-name).files", with its respective filename.

type Note added in v0.4.0

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

Note is a type that contains information about note.

func Parse

func Parse(data []byte, warn io.Writer) ([]*Note, error)

Parse reads the content of an enex file and creates instances of Note. Logs are written to the provided warn writer.

func (*Note) Extract added in v0.4.0

func (note *Note) Extract(opt *Option) (html string, bundle *Bundle)

Extract converts the data of the note into HTML and outputs the attachments as a Bundle. The sanitization method and additional headers can be specified via opt.

type Option added in v0.4.0

type Option struct {
	ExHeader    string
	Sanitizer   func(string) string
	WebClipOnly bool // If true, only output the web-clip content without Evernote styling
}

Option represents the sanitization method and additional headers, and may store other relevant information for HTML conversion in the future.

type Resource

type Resource struct {
	Mime        string
	SourceUrl   string
	Hash        string
	FileName    string
	Width       int
	Height      int
	NewFileName string
	// contains filtered or unexported fields
}

Resource represents information about an attachment.

func (*Resource) Data

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

Data returns the attachment data stored in rsc.

func (*Resource) WriteTo

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

WriteTo writes the attachment data from rsc to w.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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