View Single Post
Old 03-03-2018, 12:05 AM   #799
jjquin
Junior Member
jjquin began at the beginning.
 
jjquin's Avatar
 
Posts: 9
Karma: 10
Join Date: Mar 2018
Device: Android - FBReader
Cool

I use FBReader on my Android Tablet. One of the features of FBReader I missed until recently was the ability to use hierarchical tags. I currently have a hierarchical Genre custom column in my Calibre Library. Unfortunately, FBReader uses the / (slash) to separate the hierarchical tags instead of a period.

So I needed a plugboard that not only appended the custom Genre column to tags but also added a slash between each genre. I also decided to put a period in front of each genre so that the genres would always appear at the top of every page in the FBReader tag browser.

After many hours of testing I came up with this:

{tags:||, }.{#genre:'re_group($,"([^.]+)\.","[[$]]/.")'}

{tags:||, } - starts with tags column and only adds a comma if tags is not blank.

. - places a period before the first genre (always Ficton or Non-ficton).

{#genre: - my custom genre column.

' - changes the following function to template program mode.

re_group( - regroup(column, pattern, template) - searches the column for a pattern and changes that found pattern to the template (note you can have more than one pattern and template).

$, - the $ refers the column defined before the re_group() function: #genre in this case.

"([^.]+)\.", - this is the pattern in parentheses it searches for any character BUT a period then the \. defines each period in the hierarchical genre column. By putting the first part in parantheses you can refer to just that part in the template.

"[[$]]/.") - this is the template it puts the word found in the pattern followed by a slash then a period to go in before the next word.

'} - closing single quote for template program mode and the closing of the #genre field.

I originally tried to use the re() function but it only worked when I had the exact number of genres in the custom column. Unfortunately, my genre column can range from 3 to 5 genres. The re_group() function is nice because when it no longer finds the pattern it just adds the rest of the string (or in this case column) to the end.

So Non-Fiction.Manual.Appliance.Kitchen becomes .Non-Fiction/.Manual/.Appliance/.Manual and is added to the end of tags in the epub.

Fortunately, the strange looking genre tag does not appear in the book details, but it will be at the top of the tag browser in FBReader.
jjquin is offline   Reply With Quote