Module:Citation/CS1: Difference between revisions
code cleanup
m>Dragons flight (test whether that is unnecessary) |
m>Dragons flight (code cleanup) |
||
Line 83: | Line 83: | ||
function hyphentodash( str ) | function hyphentodash( str ) | ||
return str:gsub( '-', '–' ); | return str:gsub( '-', '–' ); | ||
end | |||
function safeforitalics( str ) | |||
if str == nil or str == '' then | |||
return str; | |||
else | |||
if str:sub(1,1) == "'" then str = "<span />" .. str; end | |||
if str:sub(-1,-1) == "'" then str = str .. "<span />"; end | |||
return str; | |||
end | |||
end | end | ||
Line 598: | Line 608: | ||
and config.CitationClass ~= "encyclopaedia" | and config.CitationClass ~= "encyclopaedia" | ||
) then | ) then | ||
Chapter = "''" .. safeforitalics(Chapter) .. "''" | |||
else | else | ||
Chapter = "\"" .. Chapter .. "\"" | Chapter = "\"" .. Chapter .. "\"" | ||
Line 627: | Line 635: | ||
Title = "\"" .. Title .. "\"" | Title = "\"" .. Title .. "\"" | ||
else | else | ||
Title = "''" .. safeforitalics(Title) .. "''" | |||
end | end | ||
Title = Title .. TransTitle | Title = Title .. TransTitle | ||
Line 810: | Line 815: | ||
if ( LayDate ~= nil ) then LayDate = " (" .. LayDate .. ")" else LayDate = "" end | if ( LayDate ~= nil ) then LayDate = " (" .. LayDate .. ")" else LayDate = "" end | ||
if ( LaySource ~= nil ) then | if ( LaySource ~= nil ) then | ||
LaySource = " – ''" .. safeforitalics(LaySource) .. "''" | |||
LaySource = " – ''" .. LaySource .. "''" | |||
else | else | ||
LaySource = "" | LaySource = "" | ||
Line 852: | Line 854: | ||
-- Several of the above rely upon detecting this as nil, so do it last. | -- Several of the above rely upon detecting this as nil, so do it last. | ||
if ( Periodical ~= nil and Periodical ~="" ) then | if ( Periodical ~= nil and Periodical ~="" ) then | ||
if ( Title and Title ~= "") then | if ( Title and Title ~= "") then | ||
Periodical = sepc .. " ''" .. Periodical .. "''" | Periodical = sepc .. " ''" .. safeforitalics(Periodical) .. "''" | ||
else | else | ||
Periodical = "''" .. Periodical .. "''" | Periodical = "''" .. safeforitalics(Periodical) .. "''" | ||
end | end | ||
else Periodical = "" end | else Periodical = "" end |