Module:toc-test
Module:toc-test » Module:toc-test/param « Module:toc-test/τεκμηρίωση/documentation
test at Template:toc-test - full numbering at wikt:el:Template:toc/style.css
- test manual at wikt:el:θωριά (wikt:el:Template:test-ol) - pattern at Συζήτηση προτύπου:toc/style.css
- Module:TemplateStyles (to get css)
- Module:table - Module:array - Module:fun
- wikt:en:Wiktionary:Grease_pit/2023/February#Asking_for_help_from_volunteer_programmers_for_TOC
- wikt:en:Module:character info - w:en:Module:List
--[=[ test at [[wikt:el:Template:toc-test]]
2023.02.08. Get a TOC with parameters (make columns for L2 headings, make TOC horizontal)
* full numbering at [[wikt:el:Template:toc/style.css]]
[[wikt:en:Wiktionary:Grease_pit/2023/February#Asking_for_help_from_volunteer_programmers_for_TOC]]
* manual [[wikt:el:Template:test-ol]] for tests: how it would look like
special characters: ( ) % . + - * [ ? ^ $
* move all greek el.wiktiionary-specific things at [[Module:toc-test/param]]
-- ?? why does not work?
]=]--
-----PLAN---- get header
-- find the titles of sections by the number of equal = = = symbols
-- normally, there is no =header= with one equal symbol (this is the actual page)
-- except at https://en.wikipedia.org/wiki/Wikipedia:Help_desk
-- at mainspace, we always have Level2 = = .... = = headings.
-- at wiktionaries L2 headings are always the language-name
-- but at appendices, documentations etc we often use only L3 and L4 headings
-- if find in page "==header==" then get "header"
-- get headers with added numberings = = header 1 = =
-- get repetitions of identical headers under differere L2s
-- OUTSIDE MAINSPACE: headers give 'headings' sometimes with templates (cf /param page)
-- handle style for headings (limits to Ls, columns)
-- add it in a table with correct margins
local export = {}
-- ============= REQUIRED
local pos = require("Module:PartOfSpeech/pos") -- needed for el.wiktionary headings
-- also required: [[Module:lang]] (see languages, Level2, below)
-- ============================= make 'table' -- this is not a real table, it is a 'table' of correspondences
function export.main(frame)
local args = frame:getParent().args -- only for Templates
local output = {}
local page = mw.title.getCurrentTitle()
local header_numbered = {}
local header_count = {}
local content = page:getContent()
-- will not accept an equal symbol = within the header?
for start_equals, header, end_equals in content:gmatch("%f[^\n%z](=+)([^=\n]+)(=+)") do
header = mw.text.trim(header)
-- mw.addWarning is just to demonstrate some of the possible error conditions.
local start_level, end_level = #start_equals, #end_equals
if start_level ~= end_level then
mw.addWarning("Header " .. start_equals .. header .. end_equals .. " has mismatched equals")
end
-- if start_level == 1 then
-- mw.addWarning("Header " .. start_equals .. header .. end_equals .. " has level 1, which is not expected in an entry")
-- else
--levels
local level = args['level'] or '' -- test not used
local new_col = args['cols'] or '' -- test not used
if start_level == 1 then id = "L1" end
if start_level == 2 then id = "L2" end
if start_level == 3 then id = "L3" end
if start_level == 4 then id = "L4" end
if start_level == 5 then id = "L5" end
if start_level == 6 then id = "L6" end
-- level 7...
-- get headers
local head = ''
-- ======== SPECIFICALLY for el.wiktionary MAINSPACE ============ --
-- LANGUAGE headings always Level 2 =={{-xxx-}}== ('^[a-z][%-0-9a-z]*[0-9a-z]$')
-- {{-xx-}} This is iso for Language links From [[Module:Languages]] keyowrd: link
-- language links like {{-xx-}} with require("Module:lang").langiso_to_langlink(iso)
-- test {{-el-cyp-}}
if mw.ustring.find(header, "{{-([%-a-z]*)-}}")
then
head = require("Module:lang").langiso_to_langlink(mw.ustring.sub(mw.ustring.match(header, "{{%-([%-a-z]*)%-}}"), 1, -1))
-- α...ω PART of SPEECH headings with language code too
-- {{xxxxx|zz}} require("Module:PartOfSpeech/pos")
-- require("Module:PartOfSpeech/pos")['ουσιαστικό']['link']
-- Can i do them all together? No, some will be excdluded.
elseif mw.ustring.find(header, "^{{αντωνυμία") then head = pos['αντωνυμία']['link']
elseif mw.ustring.find(header, "^{{απαρέμφατο") then head = pos['απαρέμφαγο']['link']
elseif mw.ustring.find(header, "^{{άρθρο") then head = pos['άρθρο']['link']
elseif mw.ustring.find(header, "^{{αριθμητικό") then head = pos['αριθμητικό']['link']
elseif mw.ustring.find(header, "^{{βιβλίο φράσεων") then head = pos['βιβλίο φράσεων']['link']
elseif mw.ustring.find(header, "^{{γερουνδιακό") then head = pos['γερουνδιακό']['link']
elseif mw.ustring.find(header, "^{{γερούνιο") then head = pos['γερούνδιο']['link']
elseif mw.ustring.find(header, "^{{έκφραση") then head = pos['έκφραση']['link']
elseif mw.ustring.find(header, "^{{ένθημα") then head = pos['ένθημα']['link']
elseif mw.ustring.find(header, "^{{επίθετο") then head = pos['επίθετο']['link']
elseif mw.ustring.find(header, "^{{επίθημα") then head = pos['επίθημα']['link']
elseif mw.ustring.find(header, "^{{επίρρημα") then head = pos['επίρρημα']['link']
elseif mw.ustring.find(header, "^{{επιρρηματική έκφραση") then head = pos['επιρρηματική έκφραση']['link']
elseif mw.ustring.find(header, "^{{επιφώνημα") then head = pos['επιφώνημα']['link']
elseif mw.ustring.find(header, "^{{κύριο όνομα") then head = pos['κύριο όνομα']['link']
elseif mw.ustring.find(header, "^{{μεταγραφή") then head = pos['μεταγραφή']['link']
elseif mw.ustring.find(header, "^{{μετοχή") then head = pos['μετοχή']['link']
elseif mw.ustring.find(header, "^{{μόριο") then head = pos['μόριο']['link']
elseif mw.ustring.find(header, "^{{ουσιαστικό") then head = pos['ουσιαστικό']['link']
elseif mw.ustring.find(header, "^{{παροιμία") then head = pos['παροιμία']['link']
elseif mw.ustring.find(header, "^{{πολυλεκτικός όρος") then head = pos['πολυλεκτικός όρος']['link']
elseif mw.ustring.find(header, "^{{πρόθεση") then head = pos['πρόθεση']['link']
elseif mw.ustring.find(header, "^{{πρόθημα") then head = pos['πρόθημα']['link']
elseif mw.ustring.find(header, "^{{προσδιοριστής") then head = pos['προσδιοριστής']['link']
elseif mw.ustring.find(header, "^{{πρόσφυμα") then head = pos['πρόσφυμα']['link']
elseif mw.ustring.find(header, "^{{ρήμα") then head = pos['ρήμα']['link']
elseif mw.ustring.find(header, "^{{ρηματική έκφραση") then head = pos['ρηματική έκφραση']['link']
elseif mw.ustring.find(header, "^{{ρίζα") then head = pos['ρίζα']['link']
elseif mw.ustring.find(header, "^{{σουπίνο") then head = pos['σουπίνο']['link']
elseif mw.ustring.find(header, "^{{συγχώνευση") then head = pos['συγχώνευση']['link']
elseif mw.ustring.find(header, "^{{σύμβολο") then head = pos['σύμβολο']['link']
elseif mw.ustring.find(header, "^{{σύνδεσμος") then head = pos['σύνδεσμος']['link']
elseif mw.ustring.find(header, "^{{συντομομορφή") then head = pos['συντομομορφή']['link']
elseif mw.ustring.find(header, "^{{φράση") then head = pos['φράση']['link']
elseif mw.ustring.find(header, "^{{χαρακτήρας") then head = pos['χαρακτήρας']['link']
-- τύποι -- inflectionarl forms
elseif mw.ustring.find(header, "^{{μορφή αντωνυμίας") then head = pos['μορφή αντωνυμίας']['link']
elseif mw.ustring.find(header, "^{{μορφή αριθμητικού") then head = pos['μορφή αριθμητικού']['link']
elseif mw.ustring.find(header, "^{{μορφή άρθρου") then head = pos['μορφή άρθρου']['link']
elseif mw.ustring.find(header, "^{{μορφή γερουνδιακού") then head = pos['μορφή γερουνδιακού']['link']
elseif mw.ustring.find(header, "^{{μορφή επιθέτου") then head = pos['μορφή επιθέτου']['link']
elseif mw.ustring.find(header, "^{{μορφή επιθήματος") then head = pos['μορφή επιθήματος']['link']
elseif mw.ustring.find(header, "^{{μορφή επιρρήματος") then head = pos['μορφή επιρρήματος']['link']
elseif mw.ustring.find(header, "^{{μορφή κυρίου ονόματος") then head = pos['μορφή κυρίου ονόματος']['link']
elseif mw.ustring.find(header, "^{{μορφή μετοχής") then head = pos['μορφή μετοχής']['link']
elseif mw.ustring.find(header, "^{{μορφή ουσιαστικού") then head = pos['μορφή ουσιαστικού']['link']
elseif mw.ustring.find(header, "^{{μορφή πολυλεκτικού όρου") then head = pos['μορφή πολυλεκτικού όρου']['link']
elseif mw.ustring.find(header, "^{{μορφή ρήματος") then head = pos['μορφή ρήματος']['link']
elseif mw.ustring.find(header, "^{{ρηματική φωνή") then head = pos['ρηματική φωνή']['link']
elseif mw.ustring.find(header, "^{{μορφή σύνθετου όρου") then head = pos['μορφή σύνθετου όρου']['link']
-- Headings for LISTS (usually L4 level)
-- standard templates for headings of el.wiktionary as in [[Help:Δομή λημμάτων]] plus alias
-- for header = head + numbered like {{ετυμολογία}} 1
-- extract header from templates (they will be links as simple-text headers)
elseif mw.ustring.find(header, "^{{άλλες γραφές") then head = 'Άλλες γραφές'
elseif mw.ustring.find(header, "^{{άλλη γραφή") then head = 'Άλλες γραφές'
elseif mw.ustring.find(header, "^{{αλλόγλωσσα") then head = 'Αλλόγλωσσα παράγωγα'
elseif mw.ustring.find(header, "^{{αναγραμματισμοί") then head = 'Αναγραμματισμοί'
elseif mw.ustring.find(header, "^{{αναφορές") then head = 'Αναφορές'
elseif mw.ustring.find(header, "^{{αντώνυμα") then head = 'Αντώνυμα'
elseif mw.ustring.find(header, "^{{απόγονοι") then head = 'Απόγονοι'
elseif mw.ustring.find(header, "^{{βλέπε") then head = 'Δείτε επίσης'
elseif mw.ustring.find(header, "^{{εκφράσεις") then head = 'Εκφράσεις'
elseif mw.ustring.find(header, "^{{ετυμολογία") then head = 'Ετυμολογία'
elseif mw.ustring.find(header, "^{{κλίση") then head = 'Κλίση'
elseif mw.ustring.find(header, "^{{μεγεθυντικά") then head = 'Μεγεθυντικά'
elseif mw.ustring.find(header, "^{{μερώνυμα") then head = 'Μερώνυμα'
elseif mw.ustring.find(header, "^{{μεταγραφές") then head = 'Μεταγραφές'
elseif mw.ustring.find(header, "^{{μεταφράσεις") then head = 'Μεταφράσεις'
elseif mw.ustring.find(header, "^{{μορφές") then head = 'Άλλες μορφές'
elseif mw.ustring.find(header, "^{{ομώνυμα") then head = 'Ομώνυμα / Ομόηχα' -- make Ομόηχα -- withdraw
elseif mw.ustring.find(header, "^{{παράγωγα") then head = 'Παράγωγα'
elseif mw.ustring.find(header, "^{{παροιμίες") then head = 'Παροιμίες'
elseif mw.ustring.find(header, "^{{παρώνυμα") then head = 'Παρώνυμα'
elseif mw.ustring.find(header, "^{{πηγές") then head = 'Πηγές'
elseif mw.ustring.find(header, "^{{πηγή") then head = 'Πηγές'
elseif mw.ustring.find(header, "^{{πολυλεκτικοί όροι") then head = 'Πολυλεκτικοί όροι'
elseif mw.ustring.find(header, "^{{προφορά") then head = 'Προφορά'
elseif mw.ustring.find(header, "^{{συγγενικά") then head = 'Συγγενικά'
elseif mw.ustring.find(header, "^{{σημειώσεις") then head = 'Σημειώσεις'
elseif mw.ustring.find(header, "^{{σημείωση") then head = 'Σημειώσεις'
elseif mw.ustring.find(header, "^{{σύνθετα") then head = 'Σύνθετα'
elseif mw.ustring.find(header, "^{{συνώνυμα") then head = 'Συνώνυμα'
elseif mw.ustring.find(header, "^{{σχετικό λεξικόγιο") then head = 'Σχετικό λεξιλόγιο'
elseif mw.ustring.find(header, "^{{ταυτόσημα") then head = 'Ταυτόσημα'
elseif mw.ustring.find(header, "^{{υπερώνυμα") then head = 'Υπερώνυμα'
elseif mw.ustring.find(header, "^{{υποκοριστικά") then head = 'Υποκοριστικά'
elseif mw.ustring.find(header, "^{{υπώνυμα") then head = 'Υπώνυμα'
-- ======== and in el.wiktionary Appendices, Talks =============
-- {{λ|ωωωω|<iso code>|altxxx}} there could be xxx {{λ|xxx|iso|altxxx}} xxx
-- iso has latin small letters, and my have hyphen -
elseif mw.ustring.find(header, "{{λ%|(.*[^{%|}])%|([%-a-z]*)%|(.*[^{%|}])}}")
then lalthead1 = mw.ustring.gsub(header, "{{λ%|(.*[^{%|}])%|", "")
lalthead2 = mw.ustring.gsub(lalthead1, "%|([%-a-z]*)%|", "")
lalthead3 = mw.ustring.gsub(lalthead2, "}", "")
head = mw.ustring.gsub(lalthead3, "[%|{}]", "")
-- {{λ|ωωωω|<iso code>}} there could be xxx {{λ|xxx|iso}} xxx
-- iso has latin small letters, and my have hyphen -
elseif mw.ustring.find(header, "{{λ%|(.*[^{%|}])%|([%-a-z]*)}}")
then lhead1 = mw.ustring.gsub(header, "{{λ", "")
lhead2 = mw.ustring.gsub(lhead1, "%|([%-a-z]*)}}", "")
head = mw.ustring.gsub(lhead2, "[%|{}]", "")
-- ======== at all wikiprojects ============ --
-- there could be xxxx [[zzz|xxx]] xxx
-- [[zzz|xxx]]
elseif mw.ustring.find(header, "%[%[(.+[^%[%|%]])%|(.+[^%[%|%]])%]%]")
then althead1 = mw.ustring.gsub(header, "%[%[(.+[^%[%|%]])%|", "")
head = mw.ustring.gsub(althead1, "[]]", "")
-- there could be xxxx [[xxx]]] xxx
-- [[xxx]]
elseif mw.ustring.find(header, "%[%[(.+[^%|%]])%]%]")
then head = mw.ustring.gsub(header, "[%[%]]", "")
-- ?# TO DO: both the above links together
-- instead, make little functions
-- xxx xxx xxx
else
head = header
end -- close elseifs for head
-- header_numbered as in ===Etymology 1===, ===Etymology 2=== (for same languageSection) ==={{ετυμολογία}} 1===
-- %s means whitespace, and %S means anything other than whitespace
-- %d digit
-- * means zero or more times -- $ at the end
local numbered = ''
if mw.ustring.find(header, "%s(%d*)$") then
--this is wrong if just words e.g. Etymology 1 Etymology 2 and Etymology 1 again.
-- the {{ετυμολογία are OK.
numbered = mw.ustring.sub(mw.ustring.match(header, "%s(%d*)$"), 1, -1)
header = head .. ' ' .. numbered
elseif mw.ustring.find(header, "(.*)") and not mw.ustring.find(header, "%s(%d*)$") then
header = head
elseif not mw.ustring.find(header, "(.*))") and not mw.ustring.find(header, "%s(%d*)$") then
header = head
end
-- repetitions of identical headings (repeated under multiple language-sections)
header_count[header] = (header_count[header] or 0) + 1
local number = ''
if header_count[header] > 1 then
number = '_' .. header_count[header]
end
-- make headings linked ================ -- ?# TO DO numbers are not linked inline, as they are to real TOC
local heading = ''
heading = '[[#' .. header .. number .. '|' .. header .. ']]'
-- ## PUT L2, L3 etc (level) instead of ('#')
-- ## make params if top-level is other than 2
-- if no level one, Subtract 1 because the top-level header in an entry is level 2 (==).
table.insert(output, ('#'):rep(start_level - 1) .. heading .. "\n")
end -- close for
-- ## WHERE do ti put this result, to formate it?
if level == 2 then return '</td><td class="tocwikt">' .. table.concat(output)
else return table.concat(output)
end
-- ? need also: if level = 2 does not exist, start with level 3 (with correct margin)
--[=[ ? HOW?
local listyle = args['listyle'] or '' args['listyle'] = args['listyle'] or ''
-- need padding-top:0px; not just padding-top:0;
listyle = 'display:block; margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-size:13px; line-height:1.5em;'
local liclass = liclass or ''
heading = '<li id="' .. id .. '" style="' .. listyle .. '" class="' .. liclass .. '">'
.. '[[#' .. header .. number .. '|' .. header .. ']]</li>'
-- Find the first heading. If it is level 1, do this. If it is level 2, do that, If it is level 3...
-- There are many pages (appenices) with only level 3 headings.
-- the first ^ means: at the beginning / The other ^ means: except
-- if mw.ustring.find(content, "^=^=") then
-- table.insert(output, ("#"):rep(start_level) .. heading .. "\n")
-- end
-- if mw.ustring.find(content, "^==^=") and not mw.ustring.find(content, "^=^=") then
-- if no level one, Subtract 1 because the top-level header in an entry is level 2 (==).
table.insert(output, (''):rep(start_level - 1) .. heading .. "\n")
-- end
-- if start_level == 3 then
-- table.insert(output, ("#"):rep(start_level - 2) .. heading .. "\n")
-- end
-- ?# how <td><ol><li style=args style>
local ol = mw.html.create('ol')
-- the style
ol:css{
['display'] = 'display:block;',
['margin-top'] = '0px;',
['margin-bottom'] = '0px;',
['padding-top'] = '0px;',
['padding-bottom'] = '0px;',
['font-size'] = '13px;',
['line-height'] = '1.5em;',
}
'ol > li:first-child':css{
['counter-reset'] = 'item', -- start counting again
}
'ol > li':css{
['counter-increment'] = 'item', -- increment = ?? start where you stopped previously)
}
'ol > li:before':css{
['content'] = 'counters(item, ".") " "', -- this is what it looks like -- can take away the full stop
}
-- the text
ol
:tag('ol')
:css() -- the above
:wikitext(ol)
-- put here the headings <li>
-- tag </ol>
:tag('ol', {selfClosing = false}):done()
return tostring(ol)
end -- close for
return table.concat(output)
-- move it left: ?# DO IT BETTER
-- at [[Template:toc/style.css]] margin-left:-30px;
-- plus, at tha table I add div style="margin-left:-1em;
--return "__NOTOC__" -- .. '<div style="margin-left:0">' -- not working
-- <noinclude><templatestyles src="toc/style.css " /></noinclude>
-- NEED css class and style parameters to break L2 columns
]=]--
end -- close function
return export