448448
449449function CslEngine :_text (options , content , entry )
450450 local t
451- local link
451+ local variable
452452 if options .macro then
453453 if self .macros [options .macro ] then
454454 -- This is not explicit in the CSL 1.0.2 specification, which mention conditional
@@ -468,7 +468,7 @@ function CslEngine:_text (options, content, entry)
468468 elseif options .term then
469469 t = self :_render_term (options .term , options .form , options .plural )
470470 elseif options .variable then
471- local variable = options .variable
471+ variable = options .variable
472472 t = entry [variable ]
473473 self :_addGroupVariable (variable , t )
474474 if variable == " locator" then
@@ -486,26 +486,51 @@ function CslEngine:_text (options, content, entry)
486486 -- title). If the “short” form is selected but unavailable, the
487487 -- “long” form is rendered instead."
488488 -- But CSL-JSON etc. do not seem to have standard provision for it.
489-
490- if t and (variable == " URL" or variable == " DOI" or variable == " PMID" or variable == " PMCID" ) then
491- link = variable
492- end
493489 elseif options .value then
494490 t = options .value
495491 else
496492 SU .error (" CSL text without macro, term, variable or value" )
497493 end
494+ -- Some styles have strip-periods even on DOI, etc.
498495 t = self :_render_stripPeriods (t , options )
499- t = self :_render_textCase (t , options )
500- t = self :_render_formatting (t , options )
501- t = self :_render_quotes (t , options )
502- t = self :_render_affixes (t , options )
503- if link then
504- t = self :_render_link (t , link )
505- elseif t and options .variable then
506- t = self :_render_text_specials (t )
496+ if t then
497+ if variable and (variable == " DOI" or variable == " PMID" or variable == " PMCID" ) then
498+ -- Some styles have a "http..." as prefix for DOIs, etc.
499+ -- Other add raw text such as "DOI: "
500+ -- Call that a totally ill-defined feature of CSL, with unclear semantics
501+ -- and conflating affixes for styling/presentation and the link itself.
502+ local isURLPrefix = options .prefix and options .prefix :find (" ^http" )
503+ if isURLPrefix then
504+ -- Make the prefix part of the link, we'll want it part of an hyperlink
505+ t = options .prefix .. t
506+ end
507+ t = self :_render_link (t , variable )
508+ t = self :_render_textCase (t , options )
509+ t = self :_render_formatting (t , options )
510+ t = self :_render_quotes (t , options )
511+ t = self :_render_affixes (t , {
512+ prefix = not isURLPrefix and options .prefix or nil ,
513+ suffix = options .suffix ,
514+ })
515+ -- (No "text specials" in DOIs, etc. by nature)
516+ elseif variable == " URL" then
517+ t = self :_render_link (t , variable )
518+ t = self :_render_textCase (t , options )
519+ t = self :_render_formatting (t , options )
520+ t = self :_render_quotes (t , options )
521+ t = self :_render_affixes (t , options )
522+ -- (No "text specials" in URLs by nature)
523+ else
524+ t = self :_render_textCase (t , options )
525+ t = self :_render_formatting (t , options )
526+ t = self :_render_quotes (t , options )
527+ t = self :_render_affixes (t , options )
528+ if t and options .variable then
529+ t = self :_render_text_specials (t )
530+ end
531+ end
532+ t = self :_render_display (t , options )
507533 end
508- t = self :_render_display (t , options )
509534 return t
510535end
511536
0 commit comments