netscaper

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2022 License: MIT Imports: 7 Imported by: 0

README

Netscaper

What is it?

A Netscape Bookmark File parser. In case you don't know what that is, it's the bookmarks.html browsers blurt out when you Export bookmarks as HTML.

This library takes such files and outputs an array of bookmarks.

Features

  • ✅ Parse bookmarked items
    • ✅ Title, link, tags, date added, last modified
    • ✅ Descriptions inside <DD>
    • PRIVATE attributes
    • LAST_VISITED attributes
  • ✅ Parse Folders
    • ✅ outputs the full folder path when in flattened mode
    • 🚧 exposes functions to output a folder tree
    • 🚧 handles folder with the same name and level

Usage

package main

import (
	"github.com/abhijit-hota/netscaper"
)

func main() {
    // If you have a file
    pathToFile := "./bookmarks.html"
	books, err := netscaper.ParseFromFile(pathToFile, nil /* default options */)
	if err != nil {
		panic(err)
	}

    // If you have a string with the file contents:
    contents := "..." 
  	books, err := netscaper.Parse(contents, nil /* default options */)
	if err != nil {
		panic(err)
	} 
}

Check the API reference for more.

Notes & References

The code uses regexes to parse HTML. Sigh. I might rewrite this using the html package or using lexical scanning but this was written for a really specific purpose and here we are.

15 years ago this library would be all the rage.

- Me

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bookmark

type Bookmark struct {
	Href         string
	Title        string
	Description  string
	Icon         string
	IconURI      string
	Tags         []string
	FolderPath   string
	AddDate      time.Time
	LastModified time.Time
	LastVisited  time.Time
	Private      bool
}

func Parse

func Parse(str string, opts *Options) ([]Bookmark, error)

func ParseFromFile

func ParseFromFile(path string, opts *Options) ([]Bookmark, error)

type Options

type Options struct {
	// The string used for separating folders in the folder path.
	// Default is ␝
	FolderPathSeparator string

	// Whether to parse description or not.
	// This refers to the <DD> tags
	ParseDescription bool

	// Whether to ignore bookmarklets or not.
	// This refers to URLs starting with javascript:
	IgnoreBookmarklets bool
}

Jump to

Keyboard shortcuts

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