Модуль:SummaryII/types/page
< Модуль:SummaryII | types
Перейти к навигации
Перейти к поиску
<<=re~ param <- ( quoted / plain / tail ) !. quoted <- item ( separator? item )* tail? item <- {| prefix? link suffix? |} link <- open !screen %s* value_quoted ( %s* pipe %s* alias )? %s* close atom <- screened / ( !open . ) prefix <- {:prefix: atom+ :} alias <- {:alias: ( !close . )+ :} suffix <- {:suffix: ( !separator atom )+ :} tail <- {:tail: atom+ :} plain <- {| value_plain |} ( separator {| value_plain |} )* tail? screened <- open screen (!close .)* close value_plain <- ( {:namespace: ns %s* ":" %s* :} )?{:value: ( !separator legal )+ ( {:section: hashtag ( !pipe !close . )+ :} )? :} value_quoted <- ( {:namespace: ns %s* ":" %s* :} )?{:value: ( !pipe !close legal )+ ( {:section: hashtag ( !pipe !close . )+ :} )? :} open <- "[[" screen <- ":" pipe <- "|" close <- "]]" separator <- {:separator: ( ( "<br" ( %s* "/" )? ">" ) / [,;%nl] %s* ) %s* :} ns <- "Обсуждение" / "Talk" / "Участник" / "User" / "Участница" / "Обсуждение участника" / "User talk" / "Обсуждение участницы" / "Традиция" / "Project" / "Т" / "Traditio" / "Обсуждение Традиции" / "Project talk" / "Обсуждение Traditio" / "Файл" / "File" / "Изображение" / "Image" / "Обсуждение файла" / "File talk" / "Обсуждение изображения" / "Image talk" / "MediaWiki" / "MediaWiki" / "Обсуждение MediaWiki" / "MediaWiki talk" / "Шаблон" / "Template" / "Обсуждение шаблона" / "Template talk" / "Справка" / "Help" / "Обсуждение справки" / "Help talk" / "Категория" / "Category" / "Обсуждение категории" / "Category talk" / "Rule" / "Rule" / "Обсуждение текста" / "Обсуждение текста" / "Text talk" / "Служебная" / "Special" / "Медиа" / "Media" / "TimedText talk" / "TimedText talk" / "GeoJson" / "GeoJson" / "Обсуждение определения гаджета" / "Gadget definition talk" / "Обсуждение портала" / "Обсуждение портала" / "Черновик" / "Черновик" / "Draft" / "Обсуждение свойства" / "Обсуждение свойства" / "Property talk" / "" / "" / "(Основное)" / "Обсуждение формы" / "Form talk" / "Обсуждение концепции" / "Обсуждение концепции" / "Concept talk" / "Определение гаджета" / "Gadget definition" / "smw/schema talk" / "smw/schema talk" / "Rule talk" / "Rule talk" / "Обсуждение черновика" / "Обсуждение черновика" / "Draft talk" / "Campaign" / "Campaign" / "TimedText" / "TimedText" / "Свойство" / "Свойство" / "Property" / "Модуль" / "Module" / "Campaign talk" / "Campaign talk" / "Обсуждение модуля" / "Module talk" / "Текст" / "Текст" / "Text" / "Портал" / "Портал" / "GeoJson talk" / "GeoJson talk" / "Форма" / "Form" / "Концепция" / "Концепция" / "Concept" / "Обсуждение гаджета" / "Gadget talk" / "smw/schema" / "smw/schema" / "Гаджет" / "Gadget" legal <- [^]#<>[|{}_] hashtag <- "#"~|<<|<<#|<<?prefix>>[[Has property::<<|<<namespace>>:|>><<value>><<|\|<<alias>>|>>]]<<?suffix>><<,|<<?separator>>>>|>>>><<?tail>>>>
function
Case | Wikitext | Formatted |
---|---|---|
Screened and some plain | screened and some plain | [[:screened]] and some plain
|
Quoted section | Title#section 1 | [[Has property::Title#section 1]]
|
Quoted | Title | [[Has property::Title]]
|
Plain section | Title#section 1 | [[Has property::Title#section 1]]
|
Quoted, ,-separated | Title1, title2 | [[Has property::Title1]], [[Has property::title2]]
|
Plain text, NL-separated | Plain 1
Plain 2 |
[[Has property::Plain 1]]
[[Has property::Plain 2]]
|
Aliases, prefixes | Two titles 1 and 2 | Two titles [[Has property::Title1|1]] and [[Has property::Title2|2]]
|
Quoted, ,-separated, suffices | Title1 (before), title2 (now) | [[Has property::Title1]] (before), [[Has property::title2]] (now)
|
Only screened | screened | [[:screened]]
|
Plain text | Plain text 1 | [[Has property::Plain text 1]]
|
Alias and no alias | Alias, Title2 | [[Has property::Title1|Alias]], [[Has property::Title2]]
|
Screened | Title (in 1942) | [[Has property::Title]] (in [[:1942]])
|
Quoted, not separated | Title1 and title2 | [[Has property::Title1]] and [[Has property::title2]]
|
Tail | Title (in 1942), allegedly | [[Has property::Title]] (in [[:1942]]), allegedly
|
Alias | Alias | [[Has property::Title|Alias]]
|
Plain text, ,-separated | Plain text 1, plain text 2 | [[Has property::Plain text 1]], [[Has property::plain text 2]]
|
local dependencies = require 'Module:SummaryII/dependencies'
local p = require 'Module:SummaryII/types'
local concat = dependencies.join
local gsub = dependencies.gsub
local function ns (...)
local namespaces = {...}
local content = namespaces[1] == 'content'
local subject = namespaces[1] == 'subject'
local list
if namespaces [1] == 0 then
-- main namespace:
list = ''
else
-- another namespace(s):
namespaces = #namespaces == 0 and dependencies.namespace_ids.all
or namespaces [1] == 'content' and dependencies.namespace_ids.content
or namespaces [1] == 'subject' and dependencies.namespace_ids.subject
or namespaces
local aliases = {}
for _, id in ipairs (namespaces) do
local config = dependencies.namespaces [id]
if config then
aliases [#aliases + 1] = config.name
aliases [#aliases + 1] = config.canonicalName
if config.displayName then
aliases [#aliases + 1] = config.displayName
end
for _, alias in ipairs (config.aliases) do
aliases [#aliases + 1] = alias
end
end
end
list = gsub (concat (aliases, '" / "'), '_', ' ')
end
return '\n ns <- "' .. list .. '"',
namespace and dependencies.namespaces [namespaces [1]].name or ''
end
local optional_ns = '( {:namespace: ns %s* ":" %s* :} )?'
local section = '( {:section: hashtag ( !pipe !close . )+ :} )?'
local plain = optional_ns .. '{:value: ( !separator legal )+ ' .. section .. ' :}'
local quoted = optional_ns .. '{:value: ( !pipe !close legal )+ ' .. section .. ' :}'
local hashtag = '"#"'
local value_grammar = p.value
p.legal = '[^]#<>[|{}_]'
function p.value (value_plain, value_quoted, separator, namespace)
local ns_variants, ns_default = ns (namespace)
local flavour, regex = value_grammar (
value_plain,
value_quoted,
p.open,
p.property,
p.screen,
p.pipe,
p.close,
separator
)
return flavour, regex
.. ns_variants
.. '\n legal <- ' .. p.legal
.. '\n hashtag <- ' .. hashtag
end
function p.format (property, default_ns)
return '<<|<<#|'
.. '<<?prefix>>'
.. p.open .. (property and property .. p.four_dots or '')
.. '<<|<<namespace>>:|' .. (default_ns and default_ns .. p.screen or '') .. '>>'
.. '<<value>>'
.. '<<|' .. '\\' .. p.pipe .. '<<alias>>|>>' .. p.close
.. '<<?suffix>><<,|<<?separator>>>>'
.. '|>>>><<?tail>>'
end
function p.test (frame)
local tokens = dependencies.tokens
local open, pipe, close, equals, delim = tokens.open, tokens.pipe, tokens.close, tokens.equals, tokens.delim
local flavour, regex = p.value (plain, quoted)
local format = open
.. equals .. flavour .. delim .. regex .. delim
.. pipe .. p.format 'Has property'
.. close
local formatter = dependencies.formatter (format)
local cases = {
['Plain text'] = 'Plain text 1',
['Plain text, ,-separated'] = 'Plain text 1, plain text 2',
['Plain text, NL-separated'] = [[Plain 1
Plain 2]],
['Quoted'] = '[[Title]]',
['Quoted, ,-separated'] = '[[Title1]], [[title2]]',
['Quoted, not separated'] = '[[Title1]] and [[title2]]',
['Quoted, ,-separated, suffices'] = '[[Title1]] (before), [[title2]] (now)',
['Tail'] = '[[Title]] (in [[:1942]]), allegedly',
['Screened'] = '[[Title]] (in [[:1942]])',
['Alias'] = '[[Title|Alias]]',
['Alias and no alias'] = '[[Title1|Alias]], [[Title2]]',
['Aliases, prefixes'] = 'Two titles [[Title1|1]] and [[Title2|2]]',
['Quoted section'] = '[[Title#section 1]]',
['Plain section'] = 'Title#section 1',
['Only screened'] = '[[:screened]]',
['Screened and some plain'] = '[[:screened]] and some plain'
}
local result = {
frame:preprocess ( '<pre><nowiki>' .. format .. '</nowiki></pre>' ),
'----', tostring (formatter),
'{| class="wikitable"', '! Case !! Wikitext !! Formatted'
}
for title, wikitext in pairs (cases) do
local tbl = { param = wikitext }
result [#result + 1] = '|-'
result [#result + 1] = '| ' .. title
result [#result + 1] = '| ' .. wikitext
result [#result + 1] = '| ' .. frame:preprocess ('<code><nowiki>'.. (type (formatter) == 'function'
and formatter (tbl)
or tostring (formatter)
) .. '</nowiki></code>')
end
result [#result + 1] = '|}'
return table.concat (result, '\n')
end
return p