Modul:Wiki: Unterschied zwischen den Versionen

fix wikiTextLimit() fett/kursiv
(+ wikiTextLimit())
(fix wikiTextLimit() fett/kursiv)
 
Zeile 62: Zeile 62:
-- schneidet bei Leerzeichen ab
-- schneidet bei Leerzeichen ab
-- beachtet dabei Links [http:/... linktext] [[page|linktext]]
-- beachtet dabei Links [http:/... linktext] [[page|linktext]]
-- ab fett/kursiv wird immer begrenzt
-- Kommandozeile zum Debuggen: =p.wikiTextLimit("12345 7890", 9)
-- Kommandozeile zum Debuggen: =p.wikiTextLimit("12345 7890", 9)
local text_limited = ""
local text_limited = ""
Zeile 70: Zeile 71:
local link_text = false
local link_text = false
local link_delim_found = false
local link_delim_found = false
local last_char = ""
local fett_kursiv = false
local text_len = mw.ustring.len(text)
local text_len = mw.ustring.len(text)
for i = 1, text_len do
if text_len <= limit then
char = mw.ustring.sub(text, i, i)
text_limited = text
if char == "[" and bracket_count < 2 then -- Klammer auf
else
bracket_count = bracket_count + 1
for i = 1, text_len do
text_cumul_predelim_len = text_cumul_len
local char = mw.ustring.sub(text, i, i)
elseif char == "]" and bracket_count > 0 then -- Klammer zu
fett_kursiv = (char == "'" and last_char == "'")
bracket_count = bracket_count - 1
if char == "[" and bracket_count < 2 then -- Klammer auf
link_text = false
bracket_count = bracket_count + 1
if not link_delim_found then -- bis dahin Leerzeichen bzw. Pipe nicht gefunden?
text_cumul_predelim_len = text_cumul_len
text_cumul_len = text_cumul_predelim_len -- dann Text hinzuzählen
elseif char == "]" and bracket_count > 0 then -- Klammer zu
elseif bracket_count == 0 then
bracket_count = bracket_count - 1
link_delim_found = false
link_text = false
if not link_delim_found then -- bis dahin Leerzeichen bzw. Pipe nicht gefunden?
text_cumul_len = text_cumul_predelim_len -- dann Text hinzuzählen
elseif bracket_count == 0 then
link_delim_found = false
end
elseif (char == " " and bracket_count == 1) or -- [http:/... linktext] Leerzeichen-Erkennung
  (char == "|" and bracket_count == 2) then -- [[page|linktext]] Pipe-Erkennung
link_text = true -- ab hier wieder Text
link_delim_found = true
else
if bracket_count == 0 or link_text then -- normaler Text
text_cumul_len = text_cumul_len + 1
if char == " " then -- Auf Leerzeichen getroffen
text_limited = text_cumul
end
end
text_cumul_predelim_len = text_cumul_predelim_len + 1 -- Auf Verdacht Link mitzählen
end
end
elseif (char == " " and bracket_count == 1) or -- [http:/... linktext] Leerzeichen-Erkennung
--[[ mw.log(
  (char == "|" and bracket_count == 2) then -- [[page|linktext]] Pipe-Erkennung
"i=" .. i .. " char=" .. char .. " last_char=" .. last_char ..
link_text = true -- ab hier wieder Text
" fett_kursiv=" .. tostring(fett_kursiv) ..
link_delim_found = true
" bracket=" .. bracket_count ..
else
" link_text=" .. tostring(link_text) ..
if bracket_count == 0 or link_text then -- normaler Text
" link_delim_found=" .. tostring(link_delim_found) ..
text_cumul_len = text_cumul_len + 1
" text_cumul_len=" .. text_cumul_len ..
if char == " " then -- Auf Leerzeichen getroffen
" text_cumul_predelim_len=" .. text_cumul_predelim_len ..
text_limited = text_cumul
" text_limited=" .. text_limited) ]]
end
if text_cumul_len > limit or fett_kursiv then
break
end
end
text_cumul_predelim_len = text_cumul_predelim_len + 1 -- Auf Verdacht Link mitzählen
text_cumul = text_cumul .. char
last_char = char
-- mw.log("text_cumul=" .. text_cumul)
end
end
if text_cumul_len > limit then
if text_cumul_len <= limit and not fett_kursiv then
break
text_limited = text
end
end
text_cumul = text_cumul .. char
--[[ mw.log(
"i=" .. i .. " char=" .. char .. " bracket=" .. bracket_count ..
" link_text=" .. tostring(link_text) ..
" link_delim_found=" .. tostring(link_delim_found) ..
" text_cumul=" .. text_cumul ..
" text_cumul_len=" .. text_cumul_len ..
" text_cumul_predelim_len=" .. text_cumul_predelim_len ..
" text_limited=" .. text_limited) ]]
end
if text_cumul_len <= limit then
text_limited = text
end
end
-- mw.log("textLimit(\"" .. text .. "\", " .. limit .. ")=\"" .. text_limited .. "\"")
-- mw.log("textLimit(\"" .. text .. "\", " .. limit .. ")=\"" .. text_limited .. "\"")