Modul:Citace

V článku Modul:Citace prozkoumáme téma, které je předmětem velkého zájmu a debat v dnešní společnosti. V průběhu let Modul:Citace upoutal pozornost akademiků, odborníků i široké veřejnosti a vytvořil širokou škálu názorů a pohledů. Od svého dopadu na každodenní život až po vliv na kulturní trendy, Modul:Citace zanechal významnou stopu v různých oblastech. Tento článek se bude snažit ponořit do historie, dopadu a budoucích důsledků Modul:Citace s cílem poskytnout komplexní a obohacující vizi na toto téma. Prostřednictvím podrobné a zasvěcené analýzy se čtenář bude moci ponořit do složitosti a dimenzí Modul:Citace, což obohatí jeho porozumění a pohled na něj.

Dokumentace  

Prozatímní dokumentace

Nejdůležitější změny proti starým šablonám:

  • Přidána podpora pro harvardské citace, vázaná na parametr ref = harv
  • Zrušena mezera před dvojtečkou - dle ISO 690 z dubna 2011, https://www.citace.com/CSN-ISO-690
  • Revize zavlečených mezer dle zásady: mezeru vkládat co nejpozději.
  • Ošetřeny duplikované koncové tečky.

--Jvs 30. 12. 2017, 10:45 (CET)

Odkazy:

require('strict')

local p = {
}

function p.trace(c, dbgInfo, s)
  table.insert(c.r, "{p." .. dbgInfo.name .. (s and s or "") .. "}")
end

function p.citaceInit(c)
  c.r = {} -- result
  c.state = {}

  if type(c.frame.callParserFunction) == 'function' then
    -- running as wiki module
    local aModule = require('Modul:Arguments')
    c.args = aModule.getArgs(c.frame)
    c.parentArgs = aModule.getArgs(c.frame:getParent())
    p.frame = c.frame -- zmena reseni, 30.12.2017 12:30:06
  else
    -- running in console
    c.localTest = 1
    c.args = c.frame
    c.parentArgs = {}
    -- makety vybranych fci pro lokalni testovani
    mw = {
      uri = {
        encode = p.identity
      }
    }
    -- debugging options
    c.noCoins = 1
    c.trace = 1
    -- c.dbg = 1
  end

  if c.trace then p.trace(c, debug.getinfo(1, "n"), ':' .. c.type) end

  -- zpětná kompatibilita
  c.args = p.convertUnderscoreArgs(c.args)
  p.provideArgs(c.args, {
    --  = "DEST",
     = "příjmení1",
     = "jméno1",
     = "autor1",
     = "odkaz na autora1",

     = "příjmení sestavitele1",
     = "jméno sestavitele1",
     = "sestavitel1",
     = "odkaz na sestavitele1",

     = "periodikum",
     = "periodikum",
     = "odkaz na periodikum",
     = "odkaz na periodikum",

     = "datum",
     = "den",
     = "měsíc",
     = "rok",

     = "strany",
     = "poznámky",
     = "titul původní",
     = "url2",

     = "isbn",
     = "issn",
  })

  c.printAnchor = not p.empty(c.args.ref)
  c.useHarvardFormat = c.printAnchor and c.args ~= "normální"

  if c.dbg then
    table.insert(c.r, "((DBG: ")
    for k, v in pairs(c.args) do
      table.insert(c.r, k .. ' = ' .. v .. ';')
    end
    table.insert(c.r, "((PARENT)): ")
    for k, v in pairs(c.parentArgs) do
      table.insert(c.r, k .. ' = ' .. v .. ';')
    end
    table.insert(c.r, " DBG_END))\n")
  end
end

function p.citace(frame)
  local c = {
    frame = frame
  }
  p.citaceInit(c)
  if not p.empty(c.args) then
    c.args = c.args
    c.args = c.args
    return p.citaceSborniku(frame)
  elseif not p.empty(c.args) then
    return p.citacePeriodika(frame)
  else
    return p.citaceMonografie(frame)
  end
end

function p.citaceMonografie(frame)
  local c = {
    frame = frame
  }
  c.type = 'citaceMonografie'
  p.citaceInit(c)

  table.insert(c.r, '<cite class="book" style="font-style:normal;' .. p.style(c) .. '"')
  p.citAnchorId(c)
  table.insert(c.r, '>')
  p.citAuthors(c, { maxAuthors = 7, honorCorporation = true })
  p.citTitle(c)
  p.citOtherPersons(c)
  p.citEdition(c)
  p.citVolume(c)
  p.citPlacePublisher(c)
  p.citDate(c)
  p.citNumberOfVolumesPagesAppendices(c)
  p.citBookSeries(c)
  p.citUrl(c)
  p.citIsbn(c)
  p.citDoi(c)
  p.citPmid(c)
  p.citJstor(c)
  p.citS2cid(c)
  p.citBibcode(c)
  p.citArxiv(c)
  p.citOclc(c)
  p.citId(c)
  p.citChapterPage(c)
  p.citLanguage(c)
  p.citNotes(c)
  table.insert(c.r, '</cite>')
  p.citCoinsMonografie(c)
  p.tearDown(c)
  return table.concat(c.r)
end

function p.citaceElMonografie(frame)
  local c = {
    frame = frame
  }
  c.type = 'citaceElMonografie'
  p.citaceInit(c)

  table.insert(c.r, '<cite class="book" style="font-style:normal;' .. p.style(c) .. '"')
  p.citAnchorId(c)
  table.insert(c.r, '>')
  p.citAuthors(c, { maxAuthors = 7, honorCorporation = true })
  p.citTitle(c)
  p.citOtherPersons(c)
  p.citEdition(c)
  -- p.citVolume(c)
  p.citPlacePublisher(c)
  p.citDate(c)
  -- p.citNumberOfVolumesPagesAppendices(c)
  p.citBookSeries(c)
  p.citChapterPage(c)
  p.citNotes(c)
  p.citUrl(c)
  p.citIsbn(c)
  p.citDoi(c)
  p.citPmid(c)
  p.citJstor(c)
  p.citS2cid(c)
  p.citBibcode(c)
  p.citArxiv(c)
  p.citOclc(c)
  p.citId(c)
  p.citLanguage(c)

  table.insert(c.r, '</cite>')
  p.citCoinsMonografie(c)
  p.tearDown(c)
  return table.concat(c.r)
end

function p.citacePeriodika(frame)
  local c = {
    frame = frame
  }
  c.type = 'citacePeriodika'
  p.citaceInit(c)

  p.supplyPeriodical(c)

  table.insert(c.r, '<cite style="font-style:normal;' .. p.style(c) .. '"')
  p.citAnchorId(c)
  table.insert(c.r, '>')
  p.citAuthors(c, { maxAuthors = 7, honorCorporation = false })
  p.citTitle(c)
  p.citOtherPersons(c)
  -- table.insert(c.r, " ")
  p.citPeriodical(c)
  -- table.insert(c.r, " ")
  p.citPlacePublisher(c)
  p.citDate(c)
  p.citYearNumberPage(c)
  -- table.insert(c.r, ".")
  p.citNotes(c)
  p.citUrl(c)
  p.citIssn(c)
  p.citIsbn(c)
  p.citDoi(c)
  p.citPmid(c)
  p.citJstor(c)
  p.citS2cid(c)
  p.citBibcode(c)
  p.citArxiv(c)
  p.citId(c)
  p.citLanguage(c)

  p.checkPeriodical(c)

  table.insert(c.r, '</cite>')
  p.citCoinsPeriodikum(c)
  p.tearDown(c)
  return table.concat(c.r)
end

function p.citaceElPeriodika(frame)
  local c = {
    frame = frame
  }
  c.type = 'citaceElPeriodika'
  p.citaceInit(c)

  p.supplyPeriodical(c)

  table.insert(c.r, '<cite style="font-style:normal;' .. p.style(c) .. '"')
  p.citAnchorId(c)
  table.insert(c.r, '>')
  p.citAuthors(c, { maxAuthors = 7, honorCorporation = false })
  p.citTitle(c)
  p.citChapterPage(c)
  p.citOtherPersons(c)
  -- table.insert(c.r, " ")
  p.citPeriodical(c)
  -- table.insert(c.r, " ")
  p.citPlacePublisher(c)
  p.citDate(c)
  p.citYearNumberPage(c)
  -- table.insert(c.r, ".")
  p.citNotes(c)
  p.citUrl(c)
  p.citIssn(c)
  p.citIsbn(c)
  p.citArxiv(c)
  p.citDoi(c)
  p.citBibcode(c)
  p.citPmid(c)
  p.citJstor(c)
  p.citS2cid(c)
  p.citId(c)
  p.citLanguage(c)

  p.checkPeriodical(c)

  table.insert(c.r, '</cite>')
  p.citCoinsPeriodikum(c)
  p.tearDown(c)
  return table.concat(c.r)
end

function p.citaceSborniku(frame)
  local c = {
    frame = frame
  }
  c.type = 'citaceSborniku'
  p.citaceInit(c)

  table.insert(c.r, '<cite style="font-style:normal;' .. p.style(c) .. '"')
  p.citAnchorId(c)
  table.insert(c.r, '>')
  p.citAuthors(c, { maxAuthors = 3, honorCorporation = true })
  p.citTitle(c)
  table.insert(c.r, ' In: ')
  p.citCompilers(c, { maxAuthors = 3, honorCorporation = true })
  p.citCompilation(c)
  p.citEdition(c)
  p.citPlacePublisher(c)
  p.citDate(c)
  p.citNotes(c)
  p.citUrl(c)
  p.citIsbn(c)
  p.citIssn(c)
  p.citDoi(c)
  p.citId(c)
  p.citVolume(c)
  p.citChapterPage(c)
  p.citLanguage(c)
  table.insert(c.r, '</cite>')
  -- p.citCoinsSbornik(c)
  p.tearDown(c)

  return table.concat(c.r)
end

function p.debug(frame)

  --[[
  if frame.callParserFunction ~= nil and type(callParserFunction) == 'function' then
   local aModule = require('Modul:Arguments')
   local args = aModule.getArgs(frame)
  end
  --]]

  -- local a = ''
  -- return 'Titul: ' .. args.titul .. ';'

  result = {}

  table.insert(result, type(frame))


  for k, v in pairs(frame) do
    table.insert(result, k .. ' = ' .. type(v) .. '; ')
  end

  return table.concat(result)
end

function p.nowiki(c, txt)
  if type(c.frame.extensionTag) == 'function' then
    return c.frame:extensionTag('nowiki', (txt and txt or ''), {})
  else
    if not p.empty(txt) then
      return "<nowiki>" .. txt .. "</nowiki>"
    else
      return "<nowiki/>"
    end
  end
end

function p.identity(x)
  return x
end

function p.empty(x)
  -- return x == nil or x == 0 or x == ""
  return x == nil or x == ""
end

-- vrátí první neprázdný argument
function p.coalesce(x, y)
  return ((x and x ~= "") and x or ((y and y ~= "") and y or ""))
end

function p.coalesceN(len, args)
  for i = 1, len do
    local v = args
    if v ~= nil and v ~= "" then
      return v
    end
  end
  return ""
end

function p.provideArg(args, x, y)
  if args == nil then
    args = args
  end
end

function p.convertUnderscoreArgs(args)
  local t = {}
  t.args = {}
  for k, v in pairs(args) do
    k = tostring(k)
    t.k, t.count = k:gsub('_', ' ')
    t.args = v
  end
  return t.args
end

function p.provideArgs(args, map)
  for src, dest in pairs(map) do
    if (args == nil or args == "") and (args ~= nil and args ~= "") then
      args = args
    end
  end
end

function p.plural(num, s1, s2, s3)
  num = tonumber(num) or 0
  return (num == 1 and s1) or (1 < num and num < 5 and s2 or s3)
end

function p.lastChar(s)
  if p.frame then
    return mw.ustring.sub(s, -1)
  else
    return string.sub(s, -1)
  end
end

-- nevim, zda lze nejak nastavit locale pro systemovy upper
function p.upper(s)
  -- return "<span style='text-transform: uppercase'>" .. s .. "</span>"
  if p.frame then
    -- return p.frame:callParserFunction('uc', s)
    return mw.ustring.upper(s)
  else
    return s:upper()
  end
end

function p.upperFirst(s)
  if p.frame then
    return p.upper(mw.ustring.sub(s, 1, 1)) .. mw.ustring.sub(s, 2)
  else
    return p.upper(s:sub(1, 1)) .. s:sub(2)
  end
end

function p.wikilink(odkaz, popis)
  if not p.empty(odkaz) then
    if not p.empty(popis) then
      return "]"
    else
      return "]"
    end
  else
    return popis
  end
end

function p.wikiextlink(odkaz, popis)
  if not p.empty(odkaz) then
    if not p.empty(popis) then
      return ""
    else
      return ""
    end
  else
    return popis
  end
end

function p.date(args, params)
  local r = {}
  local postfix = ""
  if (params and params.postfix) then
    postfix = params.postfix
  end

  if not p.empty(args) then
    table.insert(r, ""
      .. args
    )
  elseif not p.empty(args) then
    table.insert(r, ""
      .. args
      .. (not p.empty(args)
        and "-" .. args .. (not p.empty(args) and "-" .. args or "")
        or ""
      )
    )
  end
  return table.concat(r)
end

function p.dateCs(args, params)
  local r = {}
  local postfix = ""
  if (params and params.postfix) then
    postfix = params.postfix
  end

  if not p.empty(args) then
    table.insert(r, ""
      .. args
    )
  elseif not p.empty(args) then
    table.insert(r, ""
      .. (not p.empty(args)
        and (not p.empty(args) and args .. ". " or "")
          -- za měsícem vyjádřeným číslem uvedeme tečku
          .. args .. (string.match(args, "^+$") and "." or "") .. " "
        or ""
      )
      .. args
    )
  end
  return table.concat(r)
end

-- normalizace data, aby se dalo použít jako vstup pro #time
-- existuje take mw.ustring.gsub
-- https://www.lua.org/pil/20.2.html
-- '%.' matches a dot
function p.normDate(d)
  return d:gsub('%. ', '.')
end

function p.style(c)
  return (not p.empty(c.args) and "background:" .. c.args .. ";" or "")
end

function p.supplyPeriodical(c)
  local t = {}
  if p.empty(c.args) and not p.empty(c.args) then
    t.urlRegex = "^https?://(*)"
    if p.frame then
      t.periodikum = mw.ustring.match(c.args, t.urlRegex)
    else
      t.periodikum = string.match(c.args, t.urlRegex)
    end
    if t.periodikum then
      c.args = t.periodikum
    end
  end
end

-- *** Pomocné funkce přidávající výstup do pole c.r ***
-- Odkazy pro harvardské citace
-- Srovnej cs:Modul:Footnotes / core() / grep CITEREF
-- Srovnej en:Module:Citation/CS1 fce / anchor_id() -- tam je trochu jiné řešení, bere v úvahu více polí
function p.citAnchorId(c)
  local t = {}
  if c.printAnchor then
    if c.args.ref == "harv" then
      t.r = {}
      if not p.empty(c.args) then
        for i = 1, 4 do
          if not p.empty(c.args) then
            table.insert(t.r, c.args)
          end
        end
        if not p.empty(c.args) then
          table.insert(t.r, c.args)
        end
      end
      t.ref = "CITEREF" .. table.concat(t.r)
    else
      t.ref = "CITEREF" .. c.args.ref
    end
    table.insert(c.r, ' id="' .. t.ref .. '"')
  end
end

function p.citAuthors(c, params)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  local i

  if params.honorCorporation and not p.empty(c.args) then
    c.state.lastAuthor = c.args
    table.insert(c.r, ""
      .. p.wikilink(c.args, c.args)
    )
  else
    for i = 1, params.maxAuthors do
      p.citAuthor(t, c, i)
    end
  end

  -- if not p.empty(c.args) or not p.empty(c.args) or not p.empty(c.args) then
  if not p.empty(c.state.lastAuthor) then
    if not p.empty(c.args) then
      c.state.lastAuthor = c.args
      table.insert(c.r, ", " .. c.args)
    end
  end

  if c.useHarvardFormat and not p.empty(c.args) then
    c.state.lastAuthor = c.args
    table.insert(c.r, ", " .. c.args)
  end

  -- pokud posledni jmeno nekonci teckou, pak ji vlozime
  -- DBG
  if nil and c.state.lastAuthor then
    table.insert(c.r, "")
  end

  if c.state.lastAuthor and p.lastChar(c.state.lastAuthor) ~= '.' then
    table.insert(c.r, ".")
  end
end

function p.citAuthor(t, c, i)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}

  if not p.empty(c.args) then
    t = c.args
  elseif not p.empty(c.args) then
    t = p.upper(c.args)
      .. (not p.empty(c.args) and (', ' .. c.args) or "")
  end

  if t ~= nil then
    c.state.lastAuthor = t.autor
    table.insert(c.r, ""
      .. (i == 1 and "" or "; ")
      .. p.wikilink(c.args, t.autor)
    )
  end
end

function p.citCompilers(c, params)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  local i

  if params.honorCorporation and not p.empty(c.args) then
    c.state.lastCompiler = c.args
    table.insert(c.r, ""
      .. p.wikilink(c.args, c.args)
    )
  else
    for i = 1, 1 do
      p.citCompiler(c, t, i)
    end
  end

  if not p.empty(c.state.lastCompiler) then
    if not p.empty(c.args) then
      c.state.lastCompiler = c.args
      table.insert(c.r, ", " .. c.args)
    else
      for i = 2, params.maxAuthors do
        p.citCompiler(c, t, i)
      end
    end
  end

  -- pokud posledni jmeno nekonci teckou, pak ji vlozime
  if c.state.lastCompiler ~= nil and p.lastChar(c.state.lastCompiler) ~= '.' then
    table.insert(c.r, ".")
  end
end

function p.citCompiler(c, t, i)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}

  if not p.empty(c.args) then
    t = c.args
  elseif not p.empty(c.args) then
    t = p.upper(c.args)
      .. (not p.empty(c.args) and (', ' .. c.args) or "")
  end

  if t ~= nil then
    c.state.lastCompiler = t.sestavitel
    table.insert(c.r, ""
      .. (i == 1 and "" or "; ")
      .. p.wikilink(c.args, t.sestavitel)
    )
  end
end

-- editor, preklad apod.
-- NOTE: texty převzaty ze šablony "citace monografie" V š. "citace periodika" byly drobné rozdíly ve std. textech.
function p.citOtherPersons(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  local i
  t.dalsi = {}

  if not p.empty(c.args) then
    table.insert(t.dalsi, "příprava vydání " .. c.args)
  end
  if not p.empty(c.args) then
    table.insert(t.dalsi, "redakce " .. c.args)
  end
  if not p.empty(c.args) then
    table.insert(t.dalsi, "překlad " .. c.args)
  end
  if not p.empty(c.args) then
    table.insert(t.dalsi, "ilustrace " .. c.args)
  end
  if not p.empty(c.args) then
    table.insert(t.dalsi, "fotografie " .. c.args)
  end
  if not p.empty(c.args) then
    table.insert(t.dalsi, c.args)
  end

  i = 0
  for k, v in pairs(t.dalsi) do
    t.v = i == 0 and " " .. p.upperFirst(v) or "; " .. v
    table.insert(c.r, t.v)
    i = i + 1
  end

  if i > 0 then
    table.insert(c.r, ".")
  end
end

function p.citTitle(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " ")
    if c.type == 'citaceMonografie' then
      table.insert(c.r, ""
        .. "''" .. p.nowiki(c)
        .. p.wikilink(c.args, c.args)
        .. p.nowiki(c) .. "''"
        .. (not p.empty(c.args) and " (původním názvem: ''" .. p.nowiki(c) .. c.args .. p.nowiki(c) .. "'')" or "")
        .. "."
      )
    elseif c.type == 'citaceElMonografie' then
      table.insert(c.r, ""
        .. "''" .. p.nowiki(c)
        .. p.wikilink(c.args, c.args)
        .. p.nowiki(c) .. "''"
        .. " " .. p.nowiki(c, ", c.args, "online" }) .. p.nowiki(c, "]")
        .. "."
      )
    else
      table.insert(c.r, ""
        .. p.wikilink(c.args, c.args)
        .. "."
      )
    end
  end
end

function p.citCompilation(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " "
      .. "''" .. p.nowiki(c)
      .. p.wikilink(c.args, c.args)
      .. p.nowiki(c) .. "''"
      .. "."
    )
  end
end

function p.citPeriodical(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " "
      .. "''" .. p.nowiki(c)
      .. p.wikilink(c.args, c.args)
      .. p.nowiki(c) .. "''"
      .. (c.type == "citaceElPeriodika"
        and " " .. p.nowiki(c, ", c.args, "online" }) .. p.nowiki(c, "]")
        or ""
      )
      .. "."
    )
  else
    table.insert(c.r, '<small>Chybí název periodika!</small>')
  end
end

function p.citEdition(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " "
      .. c.args .. "."
      .. (not p.empty(c.args) and ", " .. c.args or "")
      .. " vyd."
    )
  end
end

function p.citVolume(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " "
      .. (not p.empty(c.args) and p.upperFirst(c.args) or "Svazek")
      .. " " .. c.args .. "."
    )
  end
end

-- dle ISO 690 platne od dubna 2011 uz neni vyzadovana mezera pred ":"
function p.citPlacePublisher(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if c.type == 'citacePeriodika' or c.type == 'citaceElMonografie' or c.type == 'citaceElPeriodika' then
    table.insert(c.r, ""
      .. ((not p.empty(c.args) or not p.empty(c.args)) and " " or "")
      .. "" .. (not p.empty(c.args) and " " .. c.args .. ": " or "")
      .. "" .. (not p.empty(c.args) and p.wikilink(c.args, c.args) or "")
    )
  else
    table.insert(c.r, ""
      .. " " .. (not p.empty(c.args) and c.args or "")
      .. ": " .. (not p.empty(c.args) and p.wikilink(c.args, c.args) or "")
    )
  end
end

-- NOTE: Neprehledny kod. Pokud mozno zjednodusit, pripadne take sjednotit format data.
function p.citDate(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  t.datum = not p.empty(c.args) and c.args or p.dateCs(c.args)

  if c.type == 'citaceElMonografie' or c.type == 'citaceElPeriodika' then
    if not p.empty(c.args) then
      t.finalDot = true
    end

    if not p.empty(t.datum) then
      t.finalDot = true
      table.insert(c.r, ""
        .. (not p.empty(c.args) and ", " .. t.datum or " " .. p.upperFirst(t.datum))
      )
    end

    if not p.empty(c.args) then
      t.finalDot = true
      if not p.empty(c.args) or not p.empty(t.datum) then
        table.insert(c.r, ", " .. p.coalesce(c.args, "rev."))
      elseif not p.empty(c.args) then
        table.insert(c.r, " " .. p.coalesce(c.args, "rev."))
      else
        table.insert(c.r, " " .. p.upperFirst(p.coalesce(c.args, "rev.")))
      end
      table.insert(c.r, " " .. c.args)
    end

    if not p.empty(c.args) then
      t.finalDot = true
      table.insert(c.r, " ")
      if not c.localTest and c.type == 'citaceElMonografie' then
        table.insert(c.r, ")) .. "]")
      else
        table.insert(c.r, ") .. "]")
      end
    end

    if (t.finalDot) then
      table.insert(c.r, ".")
    end
  elseif c.type == "citacePeriodika" then
    if not p.empty(c.args) then
      t.finalDot = true
    end
    t.datum = p.dateCs(c.args)
    if c.useHarvardFormat and t.datum == c.args then
      t.datum = ""
    end
    if not p.empty(t.datum) then
      c.state.isDatum = true
      if not p.empty(c.args) then
        table.insert(c.r, ", " .. t.datum)
      else
        table.insert(c.r, " " .. p.upperFirst(t.datum))
      end
    else
      if t.finalDot then
        table.insert(c.r, ".")
      end
    end
  else
    t.datum = p.dateCs(c.args) -- was p.date

    if c.useHarvardFormat and t.datum == c.args then
      t.datum = ""
      t.finalDot = true
    end

    if t.datum ~= "" then
      table.insert(c.r, ", " .. t.datum)
    elseif not p.empty(c.args) then
      table.insert(c.r, ", c" .. c.args)
    end

    if not p.empty(c.args) then
      if not p.empty(c.args) or not p.empty(c.args)  then
        table.insert(c.r, " (")
      else
        table.insert(c.r, ", ")
      end
      table.insert(c.r, p.dateCs(c.args, { postfix = " tisku" }) .. " tisk") -- was p.date
      if not p.empty(c.args) or not p.empty(c.args)  then
        table.insert(c.r, ")")
      end
    end

    if t.datum ~= "" or not p.empty(c.args) or t.finalDot then
      table.insert(c.r, ".")
    end
  end
end

-- refact/fix 1.6.2018
function p.citYearNumberPage(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  t.ar = {}

  if not p.empty(c.args) then
    table.insert(t.ar, (not p.empty(c.args) and c.args or "roč.") .. " " .. c.args)
  end

  if not p.empty(c.args) then
    table.insert(t.ar, (not p.empty(c.args) and c.args or "čís.") .. " " .. c.args)
  end

  if not p.empty(c.args) then
    table.insert(t.ar, "s. " .. c.args)
  end

  -- test array length
  if #t.ar > 0 then
    if c.state.isDatum then
      table.insert(c.r, ", " .. table.concat(t.ar, ", ") .. ".")
    else
      table.insert(c.r, " " .. p.upperFirst(table.concat(t.ar, ", ")) .. ".")
    end
  elseif c.state.isDatum then
    table.insert(c.r, ".")
  end
end

-- refact 8.5.2018
function p.citChapterPage(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  t.ar = {}

  if not p.empty(c.args) then
    table.insert(t.ar, ""
      .. (not p.empty(c.args) and p.upperFirst(c.args) or "Kapitola")
      .. " "
      .. p.wikiextlink(c.args, c.args)
    )
  end
  if not p.empty(c.args) then
    table.insert(t.ar, c.args)
  end
  if not p.empty(c.args) then
    table.insert(t.ar, "s.&nbsp;" .. c.args)
  end
  if not p.empty(c.args) then
    table.insert(t.ar, c.args)
  end

  -- test array length
  if #t.ar > 0 then
    table.insert(c.r, " " .. p.upperFirst(table.concat(t.ar, ", ")) .. ".")
  end
end

-- pocetSvazku, pocetStranPlusPrilohy
function p.citNumberOfVolumesPagesAppendices(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  t.pocetSvazku = ""
  if not p.empty(c.args) and (tonumber(c.args) or 0) > 1 then
    t.pocetSvazku = " "
      .. c.args
      .. "&nbsp;"
      .. p.plural(c.args, "svazek", "svazky", "svazků")
  end
  if not p.empty(c.args) then
    t.pocetStranPlusPrilohy = ""
      .. c.args .. "&nbsp;s."
      .. (not p.empty(c.args) and ", " .. c.args or "")
  else
    t.pocetStranPlusPrilohy = ""
      .. (not p.empty(c.args) and c.args or "")
  end
  if t.pocetSvazku ~= "" then
    if (t.pocetStranPlusPrilohy ~= "") then
      table.insert(c.r, t.pocetSvazku .. " (" .. t.pocetStranPlusPrilohy .. ").")
    else
      table.insert(c.r, t.pocetSvazku .. ".")
    end
  else
    if (t.pocetStranPlusPrilohy ~= "") then
      table.insert(c.r, " " .. t.pocetStranPlusPrilohy)
      if p.lastChar(t.pocetStranPlusPrilohy) ~= "." then
        table.insert(c.r, ".")
      end
    end
  end
end

function p.citBookSeries(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " "
      .. "("
      .. p.upperFirst(c.args)
      .. (not p.empty(c.args) and ". " .. p.upperFirst(c.args) or "")
      .. (not p.empty(c.args) and p.nowiki(c, ';') .. " sv.&nbsp;" .. c.args or "")
      .. ")."
    )
  end
end

function p.citUrl(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}

  if c.type == 'citacePeriodika' then
    if not p.empty(c.args) then
      t.afterUrl = {}

      if not p.empty(c.args) then
        table.insert(t.afterUrl, c.args)
      end

      if not p.empty(c.args) then
        table.insert(t.afterUrl, "cit. " .. c.args)
      elseif not p.empty(c.args) then
        table.insert(t.afterUrl, "cit. " .. c.args
          .. (not p.empty(c.args)
            and "-" .. c.args .. (not p.empty(c.args) and "-" .. c.args or "")
            or ""
          ))
      end

      t.afterUrlStr = table.concat(t.afterUrl, ", ")
      if t.afterUrlStr ~= "" then
        t.afterUrlStr = " " .. p.nowiki(c, ""
      end

      c.state.afterUrlStr = t.afterUrlStr

      p.citUrlInnerFn(c)
    end
  else
    if not p.empty(c.args) then
      p.citUrlInnerFn(c)
    end
  end

  -- citacePeriodika
  --if not p.empty(c.args) then
  --table.insert(c.r, "  .. " (Alternativní odkaz)]")
  --end
  -- citaceElMonografie, citaceElPeriodika
  if not p.empty(c.args) then
    table.insert(c.r, " "
      .. p.coalesce(c.args, "Dostupné také na:")
      .. " "
      .. p.wikiextlink(c.args)
      .. "."
    )
  end
  if not p.empty(c.args) then
    table.insert(c.r, " "
      .. p.coalesce(c.args, "Dále dostupné na:")
      .. " "
      .. p.wikiextlink(c.args)
      .. "."
    )
  end
end

function p.citUrlInnerFn(c)
  local t = {}
  if not p.empty(c.args) then
    t.liveUrl = c.args ~= "ano" and c.args ~= "yes" and c.args ~= "yes"
    table.insert(c.r, " "
      .. p.wikiextlink(c.args, p.coalesce(c.args, "Dostupné v&nbsp;archivu"))
      .. ((t.liveUrl or not p.empty(c.args)) and " pořízeném" or "")
      .. (t.liveUrl and " z&nbsp;" .. p.wikiextlink(c.args, "originálu") or "")
      .. (not p.empty(c.args) and " dne&nbsp;" .. c.args or "")
      .. "."
    )
  else
    table.insert(c.r, " "
      .. p.wikiextlink(c.args, p.coalesce(c.args, "Dostupné online"))
      .. (c.state.afterUrlStr and c.state.afterUrlStr or "")
      .. "."
    )
  end
end

function p.citIsbn(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    -- OLD
    -- table.insert(c.r, " .]  .. " " .. c.args .. "].")
    -- NEW
    if c.localTest then
      table.insert(c.r, " "
        .. "{{ISBN|{{{isbn}}}}}"
        .. (not p.empty(c.args) and ", {{ISBN|{{{isbn2}}}}}" or "")
        .. "."
      )
    else
      table.insert(c.r, " "
        .. c.frame:expandTemplate{title = 'ISBN', args = { c.args }}
        .. (not p.empty(c.args) and ", " .. c.frame:expandTemplate{title = 'ISBN', args = { c.args }} or "")
        .. "."
      )
    end
  end
end

function p.citIssn(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " ]  .. " " .. c.args .. "].")
  end
end

function p.citDoi(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " ]:) .. " " .. mw.text.nowiki(c.args) .. "].")
  end
end

function p.citOclc(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " ] ) .. " " .. c.args .. "]")
  end
end

function p.citPmid(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " ]  .. " <span class='PMID'>" .. c.args .. "</span>].")
  end
end

function p.citJstor(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " ]  .. " <span class='JSTOR'>" .. c.args .. "</span>].")
  end
end

function p.citS2cid(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " ]  .. " <span class='S2CID'>" .. c.args .. "</span>].")
  end
end

function p.citBibcode(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " ] ) .. " " .. c.args .. "].")
  end
end

function p.citArxiv(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " ] ) .. " " .. c.args .. "].")
  end
end

function p.citId(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " " .. c.args .. ".")
  end
end

function p.citNotes(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args) then
    table.insert(c.r, " " .. p.upperFirst(c.args) .. ".")
  end
end

function p.checkPeriodical(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  if p.empty(c.args) then
    if c.localTest then
      t.chyba = '{{chyba|Chybí povinný parametr: V šabloně {{šablona|Citace periodika}} je nutno určit zdrojové "<code>periodikum</code>" odkazu!|kategorie=Údržba:Chybná volání citačních šablon|skrytý=skrytý}}'
    else
      t.chyba = c.frame:expandTemplate{title = 'chyba', args = {
        'Chybí povinný parametr: V šabloně '
          .. c.frame:expandTemplate{title = 'šablona', args = {'Citace periodika'}}
          .. ' je nutno určit zdrojové "<code>periodikum</code>" odkazu!',
         = 'Údržba:Chybná volání citačních šablon',
         = 'skrytý'
      }}
    end
    table.insert(c.r, t.chyba)
  end
end

-- Return only primary language subtag from IETF language tag
function p.sanitizeLang(s)
  if type(s) ~= 'string' then return s end
  return mw.ustring.match(s, "^(?)-?$") or s
end

function p.citLanguage(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  if not p.empty(c.args) then
    if c.localTest then
      t.jazykem = c.args
    else
      local jazyk = p.sanitizeLang(c.args)
      if jazyk ~= 'cs' then -- rychlotest
        local langModule = require('Modul:Language')
        local name = langModule._getNameVJazyce(jazyk)
        if name then
          t.jazykem = name
        elseif jazyk ~= langModule._getName('cs') and jazyk ~= langModule._getNameVJazyce('cs') then
          t.jazykem = jazyk
        end
      end
    end
    if t.jazykem then
      table.insert(c.r, " (" .. t.jazykem .. ")")
    end
  end
end

function p.citCoinsMonografie(c)
  if c.noCoins then return end
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  if c.type == 'citaceElMonografie' then
    t.tplName = 'citaceelmonografie'
  else
    t.tplName = 'citacemonografie'
  end
  t.coins = 'ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rfr_id=info:sid/cs.wikipedia.org:template' .. t.tplName
    .. '&rft.btitle=' .. mw.uri.encode(p.coalesce(c.args))
    .. (not p.empty(c.args) and "&rft_id=info:doi/" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft_id=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.isbn=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.aulast=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.aufirst=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.au=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.au=" .. mw.uri.encode(c.args .. ", " .. p.coalesce(c.args)) or "")
    .. (not p.empty(c.args) and "&rft.au=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.au=" .. mw.uri.encode(c.args .. ", " .. p.coalesce(c.args)) or "")
    .. (not p.empty(c.args) and "&rft.au=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.aucorp=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.atitle=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.place=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.pub=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.date=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.edition=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.tpages=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.series=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.pages=" .. mw.uri.encode(c.args) or "")

  if c.localTest then
    t.coins = "(COinS:" .. t.coins .. ")"
  else
    t.coins = c.frame:expandTemplate{title = 'COinS', args = { obj = t.coins }}
  end
  table.insert(c.r, t.coins)
end

function p.citCoinsPeriodikum(c)
  if c.noCoins then return end
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  if c.type == 'citaceElPeriodika' then
    t.tplName = 'citaceelperiodika'
  else
    t.tplName = 'citaceperiodika'
  end
  t.coins = 'ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rfr_id=info:sid/cs.wikipedia.org:template' .. t.tplName
    .. '&rft.jtitle=' .. mw.uri.encode(p.coalesce(c.args))
    .. (not p.empty(c.args) and "&rft_id=info:doi/" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft_id=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.atitle=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args)
      and "&rft.date=" .. mw.uri.encode(c.args)
      or (not p.empty(c.args)
        and "&rft.date=" .. mw.uri.encode(c.args)
          .. (not p.empty(c.args)
            and "&rft.chron=" .. (not p.empty(c.args)
              and mw.uri.encode(c.args) .. ". "
              or ""
            ) .. mw.uri.encode(c.args)
            or ""
          )
        or ""
      )
    )
    .. (not p.empty(c.args) and "&rft.volume=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.issue=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.pages=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.issn=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.aulast=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.aufirst=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.au=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.au=" .. mw.uri.encode(c.args .. ", " .. p.coalesce(c.args)) or "")
    .. (not p.empty(c.args) and "&rft.au=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.au=" .. mw.uri.encode(c.args .. ", " .. p.coalesce(c.args)) or "")
    .. (not p.empty(c.args) and "&rft.au=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.aucorp=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.place=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.pub=" .. mw.uri.encode(c.args) or "")
    .. (not p.empty(c.args) and "&rft.tpages=" .. mw.uri.encode(c.args) or "")

  if c.localTest then
    t.coins = "(COinS:" .. t.coins .. ")"
  else
    t.coins = c.frame:expandTemplate{title = 'COinS', args = { obj = t.coins }}
  end
  table.insert(c.r, t.coins)
end

function p.tearDown(c)
  if not p.empty(c.args) then  -- jako string kvůli p.convertUnderscoreArgs
    table.insert(c.r, ']')
  end
end

return p