Documentation
¶
Overview ¶
Package doc imports documents into scripts: plain text and Markdown, EPUB, DOCX and subtitles (SRT/WebVTT) are built in; PDF is plugged in by the app (PDFKit through the Swift helper) with Register. It also writes chapter cue sheets. Subtitle parsing and writing live in doc/subtitle.
Every importer is bounded by Limits (file size, decompressed size, ZIP entries, output length) so a hostile file cannot exhaust memory.
Index ¶
- Constants
- Variables
- func CueSheet(marks []Mark, untitled func(n int) string) string
- func Extensions() []string
- func IsChapterHeading(line string) bool
- func MarkdownText(src string) string
- func Register(f Format, exts []string, x Extractor)
- type Chapter
- type Document
- type Extractor
- type ExtractorFunc
- type Format
- type Limits
- type Mark
- type RenderedChapter
Constants ¶
const ( DefaultMaxFileBytes = 64 << 20 DefaultMaxUncompressed = 256 << 20 DefaultMaxEntries = 20000 DefaultMaxChars = 5_000_000 )
Defaults.
const MaxHeadingChars = 60
MaxHeadingChars is the longest line plain-text chapter detection treats as a heading.
Variables ¶
var ( ErrUnsupported = errors.New("doc: unsupported format") ErrTooLarge = errors.New("doc: file too large") ErrNoText = errors.New("doc: no text found") ErrCorrupt = errors.New("doc: file is damaged or not of its format") )
Errors. Importers wrap them with detail; test with errors.Is.
Functions ¶
func CueSheet ¶
CueSheet writes the chapter cue sheet: one "HH:MM:SS<TAB>Title" line per mark, no trailing newline. Tabs and line breaks in titles collapse to spaces; an untitled chapter n (1-based) is named by untitled, or "Chapter n" when untitled is nil.
func Extensions ¶
func Extensions() []string
Formats lists the extensions that have an extractor, for an open dialog.
func IsChapterHeading ¶
IsChapterHeading reports whether a line of plain text looks like a chapter heading: "# Title", or a short line such as "Chapter 1", "CHAPTER IV: The End", "Prologue", "第一章 开始", "第3話", "제1장".
func MarkdownText ¶
MarkdownText converts Markdown to an AudioSmith script: "# " headings stay chapter headings, deeper headings become paragraphs, and code, images, link targets, emphasis marks, HTML, tables' pipes and list bullets are removed.
Types ¶
type Chapter ¶
Chapter is a titled run of text. Text holds paragraphs separated by one blank line, without the title.
func Chapterize ¶
Chapterize splits plain text into chapters at headings (see IsChapterHeading). Text before the first heading becomes an untitled chapter. Runs of blank lines collapse to one.
type Document ¶
type Document struct {
Format Format
Title string // from metadata, "" when unknown
Author string
Language string // BCP-47 from metadata, "" when unknown
Chapters []Chapter
}
Document is an imported document.
type Extractor ¶
type Extractor interface {
Extract(ctx context.Context, r io.ReaderAt, size int64, lim Limits) (*Document, error)
}
Extractor reads one format. Implementations must honour lim (already defaulted) and ctx, and return ErrNoText when nothing readable is found. A PDF extractor plugged in from the app can call Chapterize on the text it extracts.
type ExtractorFunc ¶
type ExtractorFunc func(ctx context.Context, r io.ReaderAt, size int64, lim Limits) (*Document, error)
ExtractorFunc adapts a function to Extractor.
type Limits ¶
type Limits struct {
MaxFileBytes int64 // the input file; default 64 MiB
MaxUncompressed int64 // total bytes inflated from a ZIP container; default 256 MiB
MaxEntries int // ZIP entries; default 20 000
MaxChars int // runes of text in the result; default 5 000 000
}
Limits bound an import. Zero fields take the defaults below; a negative field means no limit.
type Mark ¶
Mark is a chapter start in rendered audio.
func MarksFromDurations ¶
func MarksFromDurations(chs []RenderedChapter) []Mark
MarksFromDurations turns rendered chapter durations into start marks, summing in whole milliseconds and skipping failed chapters.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package subtitle parses and writes subtitles: SRT and WebVTT in both directions, ASS (with karaoke word highlighting) for writing, and Netflix-style segmentation of timed words into readable cues.
|
Package subtitle parses and writes subtitles: SRT and WebVTT in both directions, ASS (with karaoke word highlighting) for writing, and Netflix-style segmentation of timed words into readable cues. |
|
Package textenc decodes text files of unknown encoding to UTF-8: BOMs, UTF-16 without a BOM, and the legacy encodings scripts arrive in (GB18030/GBK, Big5, Shift_JIS, EUC-KR, Windows-1252).
|
Package textenc decodes text files of unknown encoding to UTF-8: BOMs, UTF-16 without a BOM, and the legacy encodings scripts arrive in (GB18030/GBK, Big5, Shift_JIS, EUC-KR, Windows-1252). |