View Single Post
Old 04-24-2021, 12:45 AM   #2
chinax
Member
chinax composes epic poetry in binary.chinax composes epic poetry in binary.chinax composes epic poetry in binary.chinax composes epic poetry in binary.chinax composes epic poetry in binary.chinax composes epic poetry in binary.chinax composes epic poetry in binary.chinax composes epic poetry in binary.chinax composes epic poetry in binary.chinax composes epic poetry in binary.chinax composes epic poetry in binary.
 
Posts: 24
Karma: 90156
Join Date: Jul 2017
Device: Nook Glowlight, Sony DPT-CP1
simplest solution is adding:
Quote:
strcat(authors, '<br>', field('publisher'));
at the end.

i've done a little explainer which hopefully adds clarity for you or anyone who passes by, but the important bit is above. these comments are probably best read in your template tester!

Quote:
program:
# ok so you know pound signs are comments
authors = field('authors');
publisher = field('publisher');
# these two lines let us call a metadata field by a normal name throughout the program. my "short
# answer" avoids needing this second line by using the built-in field() name instead of assigning
# a nickname, since we don't really transform publisher the way we transform the list of authors

num = count(authors, ' &amp; ');
authors = sublist(authors, 0, 2, ' &amp; ');
# counts the number of authors (we've told it to add one for every '&' sign)
# then reorganizes them into a list ("sublist")

authors = list_re(authors, ' &amp; ', '(.+)', '<b>\1');
authors = re(authors, ' &amp; ', ' <br>');
# these two perform search and replace on the list of authors to remove
# separators and add bold <b> & line break <br> tags in their place

authors = re(authors, '&amp; &amp;', ' <br>');
# this is for if there's accidentally two '&&' signs after the first S&R. it wasn't
# assigned a variable because it was the final output before, but now needs 'authors ='
# since we'll want this incorporated into 'authors' when we use it again below

# re(publisher, '&amp; &amp;', ' <br>'); --- you don't need this. never more than 1 publisher, so no '&&' to replace

# finally, we always 'print' whatever comes last, so you'll have to string everything together with strcat()
# i italicized the publisher to distinguish them but you can remove that if you want
strcat(authors, '<br>', '<i>', publisher)

without comments:
Quote:
program:

authors = field('authors');
publisher = field('publisher');
num = count(authors, ' &amp; ');
authors = sublist(authors, 0, 2, ' &amp; ');
authors = list_re(authors, ' &amp; ', '(.+)', '<b>\1');
authors = re(authors, ' &amp; ', ' <br>');
authors = re(authors, '&amp; &amp;', ' <br>');
strcat(authors, '<br>', '<i>', publisher)
chinax is offline   Reply With Quote