Documentation
¶
Overview ¶
Package dictgen simplifies creating full-featured dictionaries for Kobo eReaders, with support for images, unicode prefixes, raw html, markdown, and more.
A marisa implementation must be provided by github.com/pgaskin/kobodict/marisa or a custom one for this package to work.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DictFile ¶
type DictFile []*DictFileEntry
A DictFile is a high-level representation of a Kobo dictionary.
func ParseDictFile ¶
ParseDictFile parses a DictFile from it's textual representation (usually stored in a file with the extension .df).
func (DictFile) Prefixed ¶
Prefixed shards the DictFile into the different word prefixes. The original DictFile is unchanged, but the entries are still pointers to the originals (i.e. the result will become out of date if you modify the entries).
The DictFile is not validated.
If a variamt has a different prefix, the entire entry is duplicated as necessary.
func (DictFile) Validate ¶
Validate validates the entries in the DictFile. Note that duplicate entries are fine, and are encouraged if necessary (Kobo will merge them).
func (DictFile) WriteDictFile ¶
WriteDictFile validates the DictFile and writes it to w in the dictfile format.
func (DictFile) WriteDictzip ¶
WriteDictzip writes the dictfile to a kobodict.Writer, which should not have been used yet. The writer is not closed automatically. If the ImageHandler requires a file to be opened (i.e. not ImageHandlerRemove), the provided ImageFunc will be called.
type DictFileEntry ¶
type DictFileEntry struct { Headword string Variant []string NoHeader bool HeaderInfo string RawHTML bool Definition string PostRawHTML string // will not be parsed or saved, only to be used for runtime additions before generating // contains filtered or unexported fields }
DictFileEntry represents a single entry in the DictFile.
type ImageFunc ¶
ImageFunc reads an image from the path (it may be absolute or relative) src, and returns an io.Reader for the image contents. If the returned reader implements io.Closer, it will automatically be called after the image has been processed.
type ImageHandler ¶
type ImageHandler interface { // Transform transforms an image read from ir, and returns a new value for // the img tag's src attribute. As a special case, if an empty string is // returned and the error is nil, the image tag is removed entirely. In // addition, custom CSS (which must not contain any double quotes) can be // returned to be set on the img tag. Transform(src string, ir io.Reader, dw *kobodict.Writer) (nsrc string, css string, err error) // Description returns a human-readable description of what the handler does. Description() string }
ImageHandler transforms images referenced in a DictFile.
type ImageHandlerBase64 ¶
type ImageHandlerBase64 struct { // Images will be resized to fit within these dimensions, while preserving // aspect ratio. If not specified, the default is 1000x1000. MaxSize image.Point // NoGrayscale will prevent images from being grayscaled. NoGrayscale bool // JPEGQuality sets the JPEG quality for the encoded images. If not set, it // defaults to 60. JPEGQuality int }
ImageHandlerBase64 optimizes the image and encodes it as base64. This is the most compatible option, but it comes at the expense of space and speed. In addition, if there are too many images, it can lead to nickel running out of memory when parsing the dictionary (and sickel should reboot it).
In addition, it adds CSS to fix sizing issues (by default, images appear really small when rendered in the dictionary due to default styling).
This is currently the recommended option for adding images.
You must import image/* yourself for format support.
func (*ImageHandlerBase64) Description ¶
func (ih *ImageHandlerBase64) Description() string
Description implements ImageHandler.
type ImageHandlerEmbed ¶
type ImageHandlerEmbed struct{}
ImageHandlerEmbed adds the images to the dictzip without any additional modifications. Usually, this would be the best choice, but unfortunately, it is too buggy as of firmware 4.19.14123.
func (*ImageHandlerEmbed) Description ¶
func (*ImageHandlerEmbed) Description() string
Description implements ImageHandler.
type ImageHandlerRemove ¶
type ImageHandlerRemove struct{}
ImageHandlerRemove removes images from the dicthtml.
func (*ImageHandlerRemove) Description ¶
func (*ImageHandlerRemove) Description() string
Description implements ImageHandler.