Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatBook ¶
FormatBook is a default converter a book from internal format to simple text one. Rules of internal representaion and how default format converts it
please read in the description of function 'ParseBook'
parsed - a book in internal format maxWidth - 'screen width', a maximum width of text line in resulting
text
justify - whether add extra space between words to make every string except
the last strings of every paragraph the same width
Retuns a text ready to display for reading
func IsZipFile ¶
IsZipFile checks if the file is ZIP archive. Returns true is the file is ZIP or GZIP archive and false otherwise
func Justify ¶
Justify expand a string up to maxWidth length by adding spaces between words. Words are separate by spaces. If the string is longer than maxWidth or contains no spaces than the original string is returned. Examples:
Justify("a b c", 7) ==> "a b c" Justify("a b c d", 8) ==> "a b c d" Justify("abcde", 10) ==> "abcde"
Types ¶
type BookInfo ¶
type BookInfo struct { FirstName string LastName string Title string Sequence string Language string Genre string }
BookInfo is a short information about FB2 book. It supports few tags only: book title, first and last author names, sequence, genre, and text language (not the original book language)
func ParseBook ¶
ParseBook converts FB2 file to a simple list of strings with some extra information to display the text correctly. So, the parsed text is not for immediate display. It should be preformatted before showing to a user.
fileName - path to file contains FB2 formatted text. It can be ZIP archive,
the function automatically unpack zip files
parseBody - if parseBody is false the function stops right after it hits the
first 'body' tag. By this time all book information is read. The parameter can be used for quick read of book properties without parsing the entire file
Returns information about book[see BookInfo structure] and (if parseBody equals
true) the parsed FB2 text in internal format. Please read more about format below.
All tags are enclosed in double curly brackets, like "{{section}}" Since terminal is not rich with GUI features, only few FB2 tags are added to output text. Existing internal tags: The following tags are always at the very beginning of the line: {{section}} - defines section start. Default format adds extra empty line {{title}} - defines title line. There can be several title lines in a row.
Default format justify the title in the center of screen if title length is smaller than screen width. Otherwise it is displayed as regular paragraph
{{epi}} - defines ephigraph start. Default format takes all consecutive epigraph
lines, calculates the maximal width and then format all epigraph lines to make them right justified in such way that the longest string ends at the right edge of the screen
{{epiauth}} - defines author of the epigraph text start. Default format treats
this tag as if it is {{epi}} one.
The following tags can be in any place of the string, that is why thay have starting and ending markers: {{emon}} and {{emoff}} - defines emphasized text started. Default format skips these tags and does nothing. In original FB2 two tags are mapped to {{emon}}: <strong> and <emphasis>
If a parsed string does not start with "{{" it means the string is regular paragraph of text. Default format separates the section to lines not longer than screen width. If a string is longer and do not have spaces then the string just divided at screen width position. If option 'justify' is set then all string of the paragraph(except the last one) are expanded with extra spaces to make all string the same width