04-18-2021, 02:13 PM | #61 |
Grand Sorcerer
Posts: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Still confused. What does it mean to combine numbers into a category? Can you give some examples?
|
04-18-2021, 02:26 PM | #62 |
Custom User Title
Posts: 9,528
Karma: 64500175
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
For the tag browser. I don't have that many book titles starting with numeric characters specifically so I thought to make a single 0-9 instead of 0, 1, 2, 4, 5, 9... |
Advert | |
|
04-18-2021, 02:38 PM | #63 | |
Grand Sorcerer
Posts: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
TPM: Code:
{title_sort:'contains(t=uppercase(re($, '^\W*(\w).*$','\1')), '\d', '0-9', t)'} Code:
program: t = uppercase(re($title_sort, '^\W*(\w).*$','\1')); if '\d' in t then '0-9' else t fi |
|
04-18-2021, 03:50 PM | #64 |
Custom User Title
Posts: 9,528
Karma: 64500175
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
That works. Thank you.
A minor question about the template tester. Heres a template I am making for my 'mark as read' action chain: Code:
program: if check_yes_no('#onkobo', 1, 0, 0) then format_date(today(),'iso') else $$#lastread fi However, changing $$#lastread (raw field) to $#lastread in the else statement changes it slightly. Why does this occur? edit: wait, I think it's because time elapses... Last edited by ownedbycats; 04-18-2021 at 04:00 PM. |
04-18-2021, 05:25 PM | #65 | |
Grand Sorcerer
Posts: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
However $$X and $X are not the same thing. The raw_field version ($$) returns whatever is the raw data for the field. The field version ($) returns a formatted value. How those two differ depends on many things such as tweaks, column formats, and calibre default formats. |
|
Advert | |
|
04-18-2021, 05:37 PM | #66 |
Custom User Title
Posts: 9,528
Karma: 64500175
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
#lastread is a column that shows just the date, so that $#lastread returns only the date (giving me a timestamp of 00:00:00 if I actually run it to modify the column) and $$#lastread gave me the full timestamp.
|
04-20-2021, 08:39 PM | #67 |
Wizard
Posts: 1,139
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
@chaley: is there a way to make the template output new lines. For example if I want to output all formats for a book separated by a new line? Or do I have to wrap the call to the formatter to maybe replace '\\n' with a new line (in Action Chains)?
Edit: Replacing '\\n' with newlines would be a really bad idea it can mess up file paths which can have the same character. I will think of a safer representation for a new line. Maybe a new_line() function that inserts a non-printable character. Last edited by capink; 04-20-2021 at 08:56 PM. |
04-21-2021, 05:04 AM | #68 | |
Grand Sorcerer
Posts: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
If we use a "newline()" function, and presumably strcat(), then why not have it put a real newline in the string? Note that by default leading and trailing whitespace is stripped (strip()). If you don't want that then call the formatter with strip_results=False. EDIT: if strip_results is True then all white space, including newlines, is turned into a single space. Last edited by chaley; 04-21-2021 at 06:01 AM. |
|
04-21-2021, 06:29 AM | #69 |
Grand Sorcerer
Posts: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Here is a test version of formatter.py that supports a newline() function. It returns an actual newline character. As I said above, if you call the formatter with strip_results=False then the character(s) will not be removed.
I tested it with this template and it worked Code:
program: strcat('a', newline(), 'b') |
04-21-2021, 08:21 AM | #70 |
Wizard
Posts: 1,139
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
It is working. I also strip the leading and trailing white space after that using strip().
Code:
def safe_format(fmt, kwargs_, error_value, book, **kwargs): output = SafeFormat().safe_format(fmt, kwargs_, error_value, book, strip_results=False, **kwargs) return output.strip() |
04-21-2021, 10:27 AM | #71 | |
Grand Sorcerer
Posts: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
In addition, I improved the performance of the formatter parser by using table lookup instead of a series of 'if's to generate the interpretable syntax tree. Could you use the new version? I don't think I broke anything, but I have said that before. |
|
04-21-2021, 10:36 AM | #72 |
Wizard
Posts: 1,139
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
Thanks. I am using it now and it seems to be working OK. But newline() is not highlighted and does not appear in the function reference, but it works as expected.
|
04-21-2021, 11:01 AM | #73 | |
Grand Sorcerer
Posts: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
You are right, I forgot to add the function to the function list. I will do that. Question: for most formatter calls the newline() function won't do anything because the result has all contiguous white space converted to a single blank. It is then stripped. For example the template result "\nA \r\t\n B " becomes "A B". I am thinking of changing that behavior for GPM templates (but not SFM templates), removing the conversion-to-one-blank step. If I do then the above string would become "A \r\t\n B" (the leading and trailing whitespace is stripped but internal whitespace is not modified). I could also do strip(' '), removing leading & trailing blanks but leaving other whitespace intact. In this case the example result would be "\nA \r\t\n B" This change would make the newline() function generally usable and would permit formatting using tabs. (Of course that would require adding a tab() function.) It is possible that someone has GPM templates that depend on the current callapse-white-space behavior, but I think the chances are very low, and in any event the template can be changed not to depend on collapsing spaces together. I lean toward removing collapsing internal white space and stripping only blanks. What do you think? BTW: the above change would mean you don't need to set strip_results because it would still do the strip() that you are doing. |
|
04-21-2021, 11:34 AM | #74 |
Grand Sorcerer
Posts: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Another thought: instead of newline() why not have character('name') where 'name' is the letter used in the escape? That lets us add more characters without risk of breaking things or needing to introduce more functions.
We could adapt names from the python standard escape sequence table. Code:
\\ - backslash \' - quote (') \" - double_quote (") \b - backspace \n - newline (LF) \r - return (CR) \t - tab (TAB) Code:
character('newline') returns '\n' character('return') returns '\r' character('tab') returns '\t' character('backspace') returns '\b' character('backslash') returns '\\' |
04-21-2021, 11:56 AM | #75 | |||
Wizard
Posts: 1,139
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
Quote:
Quote:
Quote:
|
|||
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Library Management: various questions not worth their own thread | ownedbycats | Library Management | 171 | 11-02-2024 05:51 PM |
[Metadata Source Plugin] Questions regarding parse select, docs and ref templates | Boilerplate4U | Development | 13 | 07-07-2020 03:35 AM |
Questions on Kobo [Interfered with another thread topic] | spdavies | Kobo Reader | 8 | 10-12-2014 12:37 PM |
[OLD Thread] Some questions before buying the fire. | darthreader13 | Kindle Fire | 7 | 05-10-2013 10:19 PM |
Thread management questions | meme | Feedback | 6 | 01-31-2011 06:07 PM |