Модуль:CTD: различия между версиями

<div style="color: #555555; font-size: 80%; font-style: italic; font-family: serif; text-align: center;">Материал из '''Библиотеки Теопедии''', http://ru.teopedia.org/lib</div>
мНет описания правки
м (-output design in literature_origin())
 
(не показано 56 промежуточных версий этого же участника)
Строка 1: Строка 1:
local ctd = {} -- функции для Большого теософского словаря; copied from https://ru.teopedia.org/lib/Module:CTD
local ctd = {} -- функции для Большого теософского словаря; copied from https://ru.teopedia.org/lib/Module:CTD
-- === LOCAL FUNCTIONS ========================================================


local function isempty(s)
local function isempty(s)
Строка 5: Строка 7:
end
end


-- Split string 'inputstr' by separator 'sep' and return values in table
-- Issue: do not insert nil value if in the middle; f.e.: текст@@выражение@
local function split_string(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={}
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        table.insert(t, str)
    end
    return t
end


-- Convert local links [[link|text]] and URL [link text] to plain text.
-- Convert local links [[link|text]] and URL [link text] to plain text.
Строка 52: Строка 66:
return str
return str
end
end
-- === FUNCTIONS FOR EXTERNAL USAGE ===========================================
-- Create origin string for literature
-- Used in : Шаблон:Литература БТС
-- Call example:
-- {{#invoke: CTD | literature_origin
--  | origin =
--  | language =
--  | author  =
--  | title    =
-- }}
function ctd.literature_origin( frame )
local result = ''
-- if 'origin' set, use it and skip other parameters
if not isempty(frame.args['origin']) then
result = frame.args['origin']
else -- check every other parameter for existance
if not isempty(frame.args['language']) then
result = frame.args['language']
if not isempty(frame.args['author']) or not isempty(frame.args['title']) then
result = result .. ': '
end
end
if not isempty(frame.args['author']) then
result = result .. frame.args['author']
if not isempty(frame.args['title']) then
result = result .. ', '
end
end
if not isempty(frame.args['title']) then
result = result .. '<i>' .. frame.args['title'] .. '</i>'
end
end
return result
end


-- Create short description without hyper links
-- Create short description without hyper links
Строка 92: Строка 146:
-- Call example:  
-- Call example:  
-- {{#invoke: CTD | info  
-- {{#invoke: CTD | info  
--  | term        = Term  
--  | term        = Term, that is word or phrase
--  | term_to_show = Term with accent or diacritic marks  
--  | term_to_show = Term with accent or diacritic marks  
--  | lifetime    = Lifetime (for person or conception) or day of issue (for literature and periodical)
--  | shortly      = Short description  
--  | shortly      = Short description  
--  | description  = Full description  
--  | description  = Full description  
--  | origin      = Origin  
--  | origin      = Origin  
--  | wiki_page    = Wiki page title  
--  | wiki_page    = Wiki page title  
--  | userparam    = text@view  
--  | author      = Author of a book or an article; applied to literature
--  | author_short = Name with initials
--  | published    = Book or article published; applied to literature
--  | userparam    = text@view@type@style@specification
-- }}
-- }}
-- Where 'userparam' consist of:
-- Where 'userparam' consist of all the parameters that can not be fetched by symantic property:
-- text = text to show; generally it is the original text of request
-- * text = text to show; generally it is the original text of request - term or name
-- view = style of displaying information; a language dependent parameter (consider changes in code below)
-- * view = style of displaying information in any combination: подсказка, сноска, скобки
-- * type = type of term: понятие (по умолчанию), личность, выражение, литература, периодика / conception, person, expression, literature, periodical
-- * style = серый, оригинал, описание
-- * specification = уточнение к литературному источнику: том, страница, глава и т.п.
-- View, type and style are language dependent parameters, consider changes in code below.
-- TODO: Всплывающую подсказку сделать вики текстом и добавить ссылку [[{{{БТС статья}}}|БТС]]
function ctd.info( frame )
function ctd.info( frame )
local term = ''
local term = '' -- term in simple form, as a title in dictionary = wiki page title (most likely)
local term_to_show = ''
local term_with_link = '' -- term with a link to wiki page
local term_without_link = ''-- term without a link, but with diacritical marks
local reference = ''
local reference = ''
local description = ''
local description = ''
local origin = ''
local origin = ''
local lifetime_str = '' -- date with title
local lifetime = '' -- just date
local term_link = ''
local term_link = ''
local bts = '<span style="border-bottom: 1px dotted gray; cursor:help;" title="Большой теософский словарь">БТС</span>'
local ctd_title = '<span style="border-bottom: 1px dotted gray; cursor:help;" title="Большой теософский словарь">БТС</span>'
local output_str = '' -- result string to show
-- split 'text@view' value of parameter 'userparam' in two variables
-- variables for 'view' parameter
local i, j = string.find(frame.args['userparam'],'@',1,true)
local view_popup, view_footnote, view_brackets, view_link = false
local text = string.sub(frame.args['userparam'], 1, i-1)
-- variables for 'style' parameter
local view = string.sub( string.lower(frame.args['userparam']), j+1 )
local font_grey      = false  -- make font grey
local add_origin      = false  -- add information on origin
local add_description = false  -- add short description
local add_link        = false  -- add hyperlink to wiki page
 
-- split 'userparam' in variables
local t = mw.text.split(frame.args['userparam'],'@')
local text, view, term_type, style, specification = t[1], t[2], t[3], t[4], t[5]
local text_original = text -- keep 'text_original' unchanged
-- set default
if isempty(view)      then view      = 'подсказка' end
if isempty(term_type) then term_type = 'понятие' end
-- parse 'view' for values
if mw.ustring.find(view,'подсказка',1,true) ~= nil then view_popup    = true end
if mw.ustring.find(view,'сноска',1,true)    ~= nil then view_footnote = true end
if mw.ustring.find(view,'скобки',1,true)   ~= nil then view_brackets = true end
if mw.ustring.find(view,'ссылка',1,true)    ~= nil then view_link    = true end
-- parse 'style' for values
if mw.ustring.find(style,'серый',1,true)    ~= nil then font_grey      = true end
if mw.ustring.find(style,'оригинал',1,true) ~= nil then add_origin    = true end
if mw.ustring.find(style,'описание',1,true) ~= nil then add_description= true end
if mw.ustring.find(style,'ссылка',1,true)   ~= nil then add_link      = true end


-- define term to show, i.e. with accent and diacritic
-- define term to show, i.e. with accent and diacritic
if not isempty(frame.args['term_to_show']) then
if not isempty(frame.args['term_to_show']) then
term_to_show = frame.args['term_to_show']
term_without_link = frame.args['term_to_show']
elseif not isempty(frame.args['term']) then
elseif not isempty(frame.args['term']) then
term_to_show = frame.args['term']
term_without_link = frame.args['term']
else
else
term_to_show = text
term_without_link = text
end
end
Строка 136: Строка 223:
if not isempty(frame.args['shortly']) then
if not isempty(frame.args['shortly']) then
description = frame.args['shortly']
description = frame.args['shortly']
elseif not isempty(frame.args['translation']) then -- for term type = expression
description = frame.args['translation']
else
else
description = frame.args['description']
description = frame.args['description']
end
end
-- check if origin specified
-- construct origin string
if not isempty(frame.args['origin']) then
-- style for expression: (lang. origin)
origin = ' (' .. frame.args['origin'] .. ')'
-- all other types: (origin, lifetime)
if    not isempty(frame.args['origin'])
  or not isempty(frame.args['lifetime'])
  or not isempty(frame.args['language'])  then
origin = ' ('
if not isempty(frame.args['language']) then
origin = origin ..frame.args['language'] .. '. '
end
if not isempty(frame.args['origin']) then
origin = origin .. frame.args['origin']
end
if not isempty(frame.args['origin']) and
  ( not isempty(frame.args['lifetime']) or not isempty(frame.args['published']) )then
origin = origin .. ', '
end
if not isempty(frame.args['lifetime']) then
origin = origin .. frame.args['lifetime']
elseif not isempty(frame.args['published']) then
origin = origin .. frame.args['published']
end
origin = origin .. ')'
end
 
-- construct lifetime string for pop-up message
if not isempty(frame.args['lifetime']) then
if term_type == 'личность' then
lifetime_str = ' Время жизни: '.. frame.args['lifetime']
elseif term_type == 'выражение' then
lifetime_str = ' Время применения: '.. frame.args['lifetime']
else
lifetime_str = ' Время существования: '.. frame.args['lifetime']
end
lifetime = frame.args['lifetime']
end
if not isempty(frame.args['published']) then
lifetime_str = ' Время публикации: '.. frame.args['published']
lifetime = frame.args['published']
end
if    not isempty(frame.args['lifetime'])
  or not isempty(frame.args['published']) then
lifetime_str = lifetime_str .. '.'
end
end
-- set hyperlink if there is a wiki page for a term
-- set hyperlink if there is a wiki page for a term
if not isempty(frame.args['wiki_page']) then
if not isempty(frame.args['wiki_page']) then
term_to_show = '[['.. frame.args['wiki_page'] ..'|'.. term_to_show ..']]'
term_with_link = '[['.. frame.args['wiki_page'] ..'|'.. term_without_link ..']]'
else
term_with_link = term_without_link
end
end
-- considering type of view
-- LITERATURE features. Set author
if view == 'подсказка' or view == 'сноска и подсказка' or view == 'подсказка и сноска' then
if not isempty(frame.args['author_short']) then
text = '{{#tag:span|' .. text .. '|style=border-bottom:1px dotted gray; cursor:help;|title=' .. description .. ' (БТС, ' .. term .. ')|}}'  
term_with_link    = frame.args['author_short'] ..', «'.. term_with_link ..'»'
term_without_link = frame.args['author_short'] ..', «'.. term_without_link ..'»'
elseif not isempty(frame.args['author']) then
term_with_link    = frame.args['author'] ..', «'.. term_with_link ..'»'
term_without_link = frame.args['author'] ..', «'.. term_without_link ..'»'
end
end
if view == 'сноска' or view == 'сноска и подсказка' or view == 'подсказка и сноска' then
-- add volume, chapter, page and so on
reference = '<ref>' .. term_to_show .. origin .. ' ' .. description .. ' ('.. bts ..').</ref>'
if not isempty(specification) then
term_with_link    = term_with_link    ..', '.. specification
term_without_link = term_without_link ..', '.. specification
end
end
if view == 'скобки' then
text = text .. ' [' .. description .. ']'
-- add LINK to original text
if view_link then
if not isempty(frame.args['wiki_page']) then
text = '[['.. frame.args['wiki_page'] ..'|'.. text ..']]'
end
end
end
-- DEBUG
--text = '<p>DEBUG: view: '.. view .."; term: ".. term .."; term to show: ".. term_to_show .."; description: ".. description .."; origin: ".. origin ..'</p>'.. text
--return  text .. reference
    return frame:preprocess( text .. reference )
-- POPUP message should be added
end
if view_popup then
if term_type == 'литература' or term_type == 'личность' then
output_str = term_without_link
if add_origin then
output_str = output_str ..' '.. origin
elseif not isempty(lifetime) then
output_str = output_str .. ' ('.. lifetime ..')'
end
if add_description then output_str = output_str ..'. – '.. description end
else -- для 'понятие' и 'выражение'
output_str = term_without_link ..'. '.. description
if add_origin then output_str = output_str ..' '.. origin end
end
text = '<span style="border-bottom: 1px dotted gray; cursor: help;" title="' .. output_str .. ' (БТС).">' .. text .. '</span>' 
end


 
-- FOOTNOTE should be added
-- Invoke information from CTD about a FOREIGN EXPRESSION and shows it in footnote, pop-up or right next to expression in square brackets.
if view_footnote then
-- Used in : Шаблон:О выражении (оформление)
-- всегда добавлять ссылку в сноске
-- Based on: Шаблон:Иноязычное выражение БТС
output_str = term_with_link
-- Call example:
if add_origin then
-- {{#invoke: CTD | expression_info
output_str = output_str ..' '.. origin
--  | expression = Foreing expression
else
--  | language  = Language of expression
if term_type == 'личность' then
--  | origin    = Origin
output_str = output_str .. ' ('.. lifetime ..')'  
--  | translation= Full translation and description
end
--  | shortly    = Short description
--  | additional = Some additional information (historical, etc.)
end
--  | wiki_page  = Wiki page title
if add_description then output_str = output_str ..'. – '.. description end
--  | userparam  = text@view
if font_grey then output_str = '<span style="color: gray;">' .. output_str..' ('.. ctd_title ..')</span>' end
-- }}
text = text ..'<ref>' .. output_str ..'.</ref>'
-- Where 'userparam' consist of:
-- text = text to show; generally it is the original text of request
-- view = style of displaying information; a language dependent parameter (consider changes in code below)
function ctd.expression_info( frame )
local expression = '<i>' .. frame.args['expression'] .. '</i>'
local short_translation = ''
local reference = ''
local language = ''
local origin = ''
local bts = ' (<i>[['.. frame.args['wiki_page'] ..'|БТС]]</i>)'
-- split 'text@view' value of parameter 'userparam' in two variables
local i, j = string.find(frame.args['userparam'],'@',1,true)
local text = string.sub(frame.args['userparam'], 1, i-1)
local view = string.sub( string.lower(frame.args['userparam']), i+1, -1 )
 
-- check if short description is specified
if not isempty(frame.args['shortly']) then
short_translation = frame.args['shortly']
elseif not isempty(frame.args['translation']) then
short_translation = frame.args['translation']
else
short_translation = frame.args['description']
end
-- check if language specified
if not isempty(frame.args['language']) then
language = language..' ('.. frame.args['language'] .. '.)'
end
end
-- check if origin specified
-- BRACKETS should be added
if not isempty(frame.args['origin']) then
if view_brackets then
origin = ' ('  
if term_type == 'литература' or term_type == 'личность' then
if not isempty(frame.args['language']) then
if add_link then
origin = origin ..frame.args['language'] .. '. '
output_str = term_with_link
else
output_str = term_without_link
end
if add_origin then
output_str = output_str ..' '.. origin  
else
output_str = output_str .. ' ('.. lifetime ..')'
end
if add_description then output_str = output_str ..'. – '.. description end
else -- для 'понятие' и 'выражение'
output_str = description
if add_origin then output_str = output_str ..' '.. origin end
end
end
origin = origin .. frame.args['origin'] .. ')'
 
else
output_str = ' <nowiki>[</nowiki>' .. output_str .. ']'
origin = language
if font_grey then output_str = '<span style="color: gray;">' .. output_str ..'</span>' end
text = text .. output_str
end
end
-- considering type of view
-- DEBUG
if view == 'подсказка' or view == 'сноска и подсказка' or view == 'подсказка и сноска' then
--text = 'userparam: '.. frame.args['userparam'] ..'\n- text ='.. text_original ..'\n- view ='.. view ..'\n- type ='.. term_type ..'\n- style ='.. tostring(style) ..' ⇒ font_grey ='.. tostring(font_grey) ..'; add_origin ='.. tostring(add_origin) ..'; add_description ='.. tostring(add_description) ..'; add_link ='.. tostring(add_link) ..'\n- specification ='.. specification ..'\nOUTPUT: '.. text
text = '<span style="border-bottom: 1px dotted gray; cursor: help;" title="'.. short_translation .. language ..' (БТС)">'.. text ..'</span>'
--return  text
end
if view == 'сноска' or view == 'сноска и подсказка' or view == 'подсказка и сноска' then
reference = '<ref><span style="color: grey;"><i><b>' .. frame.args['expression'] .. '</b></i>' .. origin .. ' ' .. frame.args['translation'] .. bts ..'.</span></ref>'
end
if view == 'скобки' then
text = text ..' ['.. short_translation .. language ..']'
end


-- DEBUG.
     return frame:preprocess( text )
--text = '<p>DEBUG: view: ' .. view .. "; term: " .. term .. "; description: " .. description .. "; origin: " .. origin .. '</p>' .. text
    -- return text .. reference ..'; view='.. view ..'; i='.. i
     return frame:preprocess( text .. reference )
end
end


return ctd
return ctd

Текущая версия от 10:01, 24 января 2024

В этом модуле хранятся функции для Большого теософского словаря.

Одна из веток использования:

{{ТД источник}}{{ЕПБ.Источник}}{{Кратко из БТС}}{{Кратко из БТС (оформление)}}Модуль:CTD.info()

Для отладки:

=p.info{ args={
["type"]  = "личность",
["term"]  = "Понятие",
["term_to_show"] = "Поня́тие для показа",
["description"]   = "Полное описание.",
["shortly"]   = "Краткое описание.",
["origin"]    = "происхождение",
["lifetime"]    = "1831-1891",
["wiki_page"]   = "Вики страница",
["userparam"]   = "текст@сноска@личность@серый"
}}

local ctd = {} -- функции для Большого теософского словаря; copied from https://ru.teopedia.org/lib/Module:CTD

-- === LOCAL FUNCTIONS ========================================================

local function isempty(s)
  return s == nil or s == ''
end

-- Split string 'inputstr' by separator 'sep' and return values in table
-- Issue: do not insert nil value if in the middle; f.e.: текст@@выражение@
local function split_string(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={}
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        table.insert(t, str)
    end
    return t
end

-- Convert local links [[link|text]] and URL [link text] to plain text.
-- See original function in module PM.
local function remove_links( wiki_str )
	local str = wiki_str

	-- remove local links
	i = mw.ustring.find(str,'[[',1,true)
	j = mw.ustring.find(str,']]',i,true)
	while i ~= nil do
		local link_text = mw.ustring.sub(str, i+2, j-1)
		local k = mw.ustring.find(link_text, '|', 1, true) 
		if k ~= nil then
			link_text = mw.ustring.sub(link_text, k+1)
		end
		str = mw.ustring.sub(str, 1, i-1) .. link_text .. mw.ustring.sub(str, j+2, -1)
		i = mw.ustring.find(str,'[[',1,true)
		j = mw.ustring.find(str,']]',i,true)
	end	
	
	-- remove URL
	i = mw.ustring.find(str,'[http',1,true)
	j = mw.ustring.find(str,']',i,true)
	while i ~= nil do
		local link_text = mw.ustring.sub(str, i+1, j-1)
		local k = mw.ustring.find(link_text, ' ', 1, true) 
		if k ~= nil then
			link_text = mw.ustring.sub(link_text, k+1)
		end
		str = mw.ustring.sub(str, 1, i-1) .. link_text .. mw.ustring.sub(str, j+1, -1)
		i = mw.ustring.find(str,'[http',1,true)
		j = mw.ustring.find(str,']',i,true)
	end	
	
	return str
end


-- NOT FINISHED
-- Add a point at the end of text, check for ".." and "...."
local function point_at_end( text )
	local str = text .. '.'
	
	-- check for 2 or 4 points at ending restrict to 1 or 3.
	
	return str
end


-- === FUNCTIONS FOR EXTERNAL USAGE ===========================================

-- Create origin string for literature
-- Used in : Шаблон:Литература БТС
-- Call example: 
-- {{#invoke: CTD | literature_origin 
--  | origin = 
--  | language = 
--  | author   = 
--  | title    = 
-- }}
function ctd.literature_origin( frame )
	local result = ''

	-- if 'origin' set, use it and skip other parameters
	if not isempty(frame.args['origin']) then
		result = frame.args['origin']
	else -- check every other parameter for existance
		if not isempty(frame.args['language']) then
			result = frame.args['language'] 
			if not isempty(frame.args['author']) or not isempty(frame.args['title']) then
				result = result .. ': '
			end 
		end 
		if not isempty(frame.args['author']) then
			result = result .. frame.args['author']
			if not isempty(frame.args['title']) then
				result = result .. ', '
			end 
		end 
		if not isempty(frame.args['title']) then
			result = result .. '<i>' .. frame.args['title'] .. '</i>'
		end 
	end 

	return result
end


-- Create short description without hyper links
-- Used in : Шаблон:Понятие БТС
-- Call example: 
-- {{#invoke: CTD | shortly 
--  | short_text = Short description, if exist 
--  | long_text  = Long description
-- }}
function ctd.shortly( frame )
	local result = ''

	-- check if sort description specified
	if not isempty(frame.args['short_text']) then
		result = frame.args['short_text']
	else 
		result = frame.args['long_text']
		-- keep only text before Category
		local i = mw.ustring.find(result,'[[Категория',1,true)
		if i ~= nil then
			result = mw.ustring.sub(result, 1, i-1)
		end
		-- convert all links to plain text
		result = remove_links(result)
		-- take only first 100 characters; string.sub() uses bytes instead of chars
		if mw.ustring.len(result) > 100 then
			result = mw.ustring.sub( result, 1, 100) .. '...'
		end
	end
	
	-- Use function point_at_end() when finished
	-- return point_at_end(result)
	return result
end


-- Invoke information from CTD about a TERM and shows it in footnote, pop-up or right next to term in square brackets.
-- Used in : Шаблон:Кратко из БТС (оформление)
-- Based on: Шаблон:Понятие БТС
-- Call example: 
-- {{#invoke: CTD | info 
--  | term         = Term, that is word or phrase 
--  | term_to_show = Term with accent or diacritic marks 
--  | lifetime     = Lifetime (for person or conception) or day of issue (for literature and periodical)
--  | shortly      = Short description 
--  | description  = Full description 
--  | origin       = Origin 
--  | wiki_page    = Wiki page title 
--  | author       = Author of a book or an article; applied to literature
--  | author_short = Name with initials
--  | published    = Book or article published; applied to literature
--  | userparam    = text@view@type@style@specification 
-- }}
-- Where 'userparam' consist of all the parameters that can not be fetched by symantic property:
-- * text = text to show; generally it is the original text of request - term or name
-- * view = style of displaying information in any combination: подсказка, сноска, скобки
-- * type = type of term: понятие (по умолчанию), личность, выражение, литература, периодика / conception, person, expression, literature, periodical
-- * style = серый, оригинал, описание 
-- * specification = уточнение к литературному источнику: том, страница, глава и т.п.
-- View, type and style are language dependent parameters, consider changes in code below.
-- TODO: Всплывающую подсказку сделать вики текстом и добавить ссылку [[{{{БТС статья}}}|БТС]] 
function ctd.info( frame )
	local term = ''				-- term in simple form, as a title in dictionary = wiki page title (most likely)
	local term_with_link = ''	-- term with a link to wiki page
	local term_without_link = ''-- term without a link, but with diacritical marks
	local reference = ''
	local description = ''
	local origin = ''
	local lifetime_str = ''			-- date with title
	local lifetime = '' 			-- just date
	local term_link = ''
	local ctd_title = '<span style="border-bottom: 1px dotted gray; cursor:help;" title="Большой теософский словарь">БТС</span>'
	local output_str = ''		-- result string to show
	-- variables for 'view' parameter
	local view_popup, view_footnote, view_brackets, view_link = false
	-- variables for 'style' parameter
	local font_grey       = false  -- make font grey
	local add_origin      = false  -- add information on origin
	local add_description = false  -- add short description
	local add_link        = false  -- add hyperlink to wiki page

	-- split 'userparam' in variables
	local t = mw.text.split(frame.args['userparam'],'@')
	local text, view, term_type, style, specification = t[1], t[2], t[3], t[4], t[5]
	local text_original = text			-- keep 'text_original' unchanged
	-- set default
	if isempty(view)      then view      = 'подсказка' end	
	if isempty(term_type) then term_type = 'понятие' end	
	-- parse 'view' for values
	if mw.ustring.find(view,'подсказка',1,true) ~= nil then view_popup    = true end
	if mw.ustring.find(view,'сноска',1,true)    ~= nil then view_footnote = true end
	if mw.ustring.find(view,'скобки',1,true)    ~= nil then view_brackets = true end
	if mw.ustring.find(view,'ссылка',1,true)    ~= nil then view_link     = true end
	-- parse 'style' for values
	if mw.ustring.find(style,'серый',1,true)    ~= nil then font_grey      = true end
	if mw.ustring.find(style,'оригинал',1,true) ~= nil then add_origin     = true end
	if mw.ustring.find(style,'описание',1,true) ~= nil then add_description= true end
	if mw.ustring.find(style,'ссылка',1,true)   ~= nil then add_link       = true end

	-- define term to show, i.e. with accent and diacritic
	if not isempty(frame.args['term_to_show']) then
		term_without_link = frame.args['term_to_show']
	elseif not isempty(frame.args['term']) then
		term_without_link = frame.args['term']
	else
		term_without_link = text
	end
	
	-- define term in a simple form as a title in dictionary
	if not isempty(frame.args['term']) then
		term = frame.args['term']
	else
		term = text
	end
	
	-- check if short description is specified
	if not isempty(frame.args['shortly']) then
		description = frame.args['shortly']
	elseif not isempty(frame.args['translation']) then -- for term type = expression
		description = frame.args['translation']
	else
		description = frame.args['description']
	end
	
	-- construct origin string
	-- style for expression: (lang. origin)
	-- all other types: (origin, lifetime)
	if    not isempty(frame.args['origin']) 
	   or not isempty(frame.args['lifetime']) 
	   or not isempty(frame.args['language'])  then
		origin = ' ('
		if not isempty(frame.args['language']) then
			origin = origin ..frame.args['language'] .. '. '
		end
		if not isempty(frame.args['origin']) then
			origin = origin .. frame.args['origin']
		end
		if not isempty(frame.args['origin']) and 
		   ( not isempty(frame.args['lifetime']) or not isempty(frame.args['published']) )then
			origin = origin .. ', '
		end
		if not isempty(frame.args['lifetime']) then
			origin = origin .. frame.args['lifetime']
		elseif not isempty(frame.args['published']) then
			origin = origin .. frame.args['published']
		end
		origin = origin .. ')'
	end

	-- construct lifetime string for pop-up message
	if not isempty(frame.args['lifetime']) then
		if term_type == 'личность' then
			lifetime_str = ' Время жизни: '.. frame.args['lifetime']
		elseif term_type == 'выражение' then
			lifetime_str = ' Время применения: '.. frame.args['lifetime']
		else
			lifetime_str = ' Время существования: '.. frame.args['lifetime']
		end
		lifetime = frame.args['lifetime']
	end
	if not isempty(frame.args['published']) then
		lifetime_str = ' Время публикации: '.. frame.args['published']
		lifetime = frame.args['published']
	end
	if    not isempty(frame.args['lifetime']) 
	   or not isempty(frame.args['published']) then
		lifetime_str = lifetime_str .. '.'
	end
	
	-- set hyperlink if there is a wiki page for a term
	if not isempty(frame.args['wiki_page']) then
		term_with_link = '[['.. frame.args['wiki_page'] ..'|'.. term_without_link ..']]'
	else
		term_with_link = term_without_link
	end
	
	-- LITERATURE features. Set author 
	if not isempty(frame.args['author_short']) then
		term_with_link    = frame.args['author_short'] ..', «'.. term_with_link ..'»'
		term_without_link = frame.args['author_short'] ..', «'.. term_without_link ..'»'
	elseif not isempty(frame.args['author']) then
		term_with_link    = frame.args['author'] ..', «'.. term_with_link ..'»'
		term_without_link = frame.args['author'] ..', «'.. term_without_link ..'»'
	end
	-- add volume, chapter, page and so on
	if not isempty(specification) then
		term_with_link    = term_with_link    ..', '.. specification
		term_without_link = term_without_link ..', '.. specification
	end
	
	-- add LINK to original text
	if view_link then
		if not isempty(frame.args['wiki_page']) then
			text = '[['.. frame.args['wiki_page'] ..'|'.. text ..']]'
		end
	end
	
	-- POPUP message should be added
	if view_popup then
		if term_type == 'литература' or term_type == 'личность' then
			output_str = term_without_link 
			if add_origin then 	
				output_str = output_str ..' '.. origin 
			elseif not isempty(lifetime) then 
				output_str = output_str .. ' ('.. lifetime ..')' 
			end	
			if add_description then output_str = output_str ..'. – '.. description end	
		else -- для 'понятие' и 'выражение'
			output_str = term_without_link ..'. '.. description
			if add_origin then output_str = output_str ..' '.. origin end			
		end
		text = '<span style="border-bottom: 1px dotted gray; cursor: help;" title="' .. output_str .. ' (БТС).">' .. text .. '</span>'  
	end

	-- FOOTNOTE should be added
	if view_footnote then
		-- всегда добавлять ссылку в сноске
		output_str = term_with_link
		if add_origin then 	
			output_str = output_str ..' '.. origin 
		else 
			if term_type == 'личность' then
				output_str = output_str .. ' ('.. lifetime ..')' 
			end
			
		end	
		if add_description	then output_str = output_str ..'. – '.. description end	
		if font_grey		then output_str = '<span style="color: gray;">' .. output_str..' ('.. ctd_title ..')</span>' end
		text = text ..'<ref>' .. output_str ..'.</ref>'
	end
	
	-- BRACKETS should be added
	if view_brackets then
		if term_type == 'литература' or term_type == 'личность' then
			if add_link	then 
				output_str = term_with_link 
			else 
				output_str = term_without_link 
			end
			if add_origin then 	
				output_str = output_str ..' '.. origin 
			else 
				output_str = output_str .. ' ('.. lifetime ..')'
			end	
			if add_description then output_str = output_str ..'. – '.. description end	
			
		else -- для 'понятие' и 'выражение'
			output_str = description
			if add_origin then output_str = output_str ..' '.. origin end
		end

		output_str = ' <nowiki>[</nowiki>' .. output_str .. ']'
		if font_grey then output_str = '<span style="color: gray;">' .. output_str ..'</span>' end
		text = text .. output_str
	end
	
	-- DEBUG
	--text = 'userparam: '.. frame.args['userparam'] ..'\n- text ='.. text_original ..'\n- view ='.. view ..'\n- type ='.. term_type ..'\n- style ='.. tostring(style) ..' ⇒ font_grey ='.. tostring(font_grey) ..'; add_origin ='.. tostring(add_origin) ..'; add_description ='.. tostring(add_description) ..'; add_link ='.. tostring(add_link) ..'\n- specification ='.. specification ..'\nOUTPUT: '.. text
	--return  text 

    return frame:preprocess( text )
end

return ctd