Este módulo genera varios tipos de listas. Actualmente, admite listas con viñetas, listas sin viñetas, listas horizontales, listas ordenadas (numeradas o alfabéticas) y listas ordenadas horizontales. Permite aplicar estilos CSS fácilmente a la lista o a los elementos individuales de la lista.
{{#invoke:list| función | primer elemento | segundo elemento | tercer elemento |...}}
{{#invoke:list| función | primer elemento | segundo elemento | tercer elemento |...|start = número de inicio para listas ordenadas |type = tipo de numeración para listas ordenadas |list_style_type = tipo de marcador para listas ordenadas (usa CSS) |class = clase |style = estilo |list_style = estilo para la lista |item_style = estilo para todos los elementos de la lista |item1_style = estilo para el primer elemento de la lista |item2_style = estilo para el segundo elemento de la lista |...|item1_value = valor para el primer elemento de la lista |item2_value = valor para el segundo elemento de la lista |...|indent = sangría para listas horizontales }}
{{#invoke:list| función }}
1
, 2
, 3
...): son los elementos de la lista. Si no hay elementos de la lista, el módulo no mostrará nada.start
- Establece el elemento inicial para listas ordenadas. Puede ser un número inicial para listas numeradas o una letra inicial para listas alfabéticas. Las listas ordenadas horizontalmente solo admiten números.type
- el tipo de marcador utilizado en listas ordenadas. Los valores posibles son "1" para números (predeterminado), "A" para letras mayúsculas, "a" para letras minúsculas, "I" para números romanos en mayúsculas y "i" para números romanos en minúsculas. No se admite en listas ordenadas horizontales. Consulte también el list_style_type
parámetro.list_style_type
- el tipo de marcador utilizado en listas ordenadas. Utiliza estilos CSS y tiene más tipos disponibles que el type
parámetro, que utiliza un atributo html . Los valores posibles se enumeran en la página list-style-type de MDN. La compatibilidad puede variar según el navegador. list-style-type
es un alias para este parámetro.class
- una clase personalizada para las <div>...</div>
etiquetas que rodean la lista, por ejemplo plainlinks
.style
- un estilo CSS personalizado para las <div>...</div>
etiquetas que rodean la lista, por ejemplo font-size: 90%;
.list_style
- un estilo CSS personalizado para la lista en sí. El formato es el mismo que el del |style=
parámetro.item_style
- un estilo CSS personalizado para todos los elementos de la lista (las <li>...</li>
etiquetas). El formato es el mismo que el del |style=
parámetro.item1_style
, item2_style
, item3_style
... - estilos CSS personalizados para cada uno de los elementos de la lista. El formato es el mismo que el del |style=
parámetro.item1_value
, item2_value
, item3_value
... - valor personalizado para el elemento de lista indicado. Los elementos de lista que siguen al indicado se incrementarán a partir del valor especificado. El valor debe ser un entero positivo. (Tenga en cuenta que esta opción solo tiene efecto en listas ordenadas).indent
- este parámetro sangra la lista, solo para listas horizontales y ordenadas horizontalmente. El valor debe ser un número, por ejemplo 2
. La sangría se calcula en em y es 1,6 veces el valor especificado. Si no se especifica ninguna sangría, el valor predeterminado es cero.local libUtil = require ( 'libraryUtil' ) local checkType = libUtil . checkType local mTableTools = require ( 'Module:TableTools' ) local p = {} local listTypes = { [ 'bulleted' ] = true , [ 'unbulleted' ] = true , [ 'horizontal' ] = true , [ 'ordered' ] = true , [ 'horizontal_ordered' ] = true } function p . makeListData ( listType , args ) -- Construye una tabla de datos para pasarla a p.renderList. local data = {} -- Clases y TemplateStyles data . classes = {} data . templatestyles = '' if listType == 'horizontal' or listType == 'horizontal_ordered' then table. insert ( data . classes , 'hlist' ) data . templatestyles = mw . getCurrentFrame ( ) : extensionTag { nombre = 'templatestyles' , args = { src = 'Hlist/styles.css' } } elseif listType == 'unbulleted' then tabla.insert ( datos.classes , 'plainlist' ) datos.templatestyles = mw.getCurrentFrame ( ) : extensionTag { nombre = ' templatestyles ' , args = { src = ' Plainlist / styles.css' } } fin tabla.insert ( datos.classes ,argumentos . class ) -- Estilo div principal data . style = args . style -- Sangría para listas horizontales if listType == 'horizontal' or listType == 'horizontal_ordered' then local indent = tonumber ( args . indent ) indent = indent and indent * 1.6 or 0 if indent > 0 then data . marginLeft = indent .. 'em' end end -- Tipos de estilo de lista para listas ordenadas -- Puede ser "1, 2, 3", "a, b, c" o algún otro. El tipo de estilo de lista se establece mediante el atributo "type" o la propiedad CSS "list-style-type". if listType == 'ordered' or listType == 'horizontal_ordered' then data . listStyleType = args . list_style_type or args [ 'list-style-type' ] data . type = args [ 'type' ] - Detecta atributos de tipo no válidos e intenta convertirlos en propiedades CSS list-style-type. if data . type y no data . listStyleType y no tostring ( data . type ): find ( '^%s*[1AaIi]%s*$' ) then data . listStyleType = data . type data . type = nil end end - Tipo de etiqueta de lista if listType == 'ordered' or listType == 'horizontal_ordered' then data . listTag = 'ol' else data . listTag = 'ul' end - Número de inicio para listas ordenadas data . start = args .empezar si listType == 'horizontal_ordered' then -- Aplicar corrección para que los números iniciales funcionen con listas ordenadas horizontalmente. local startNum = tonumber(data.start) if startNum then data.counterReset = 'listitem' .. tostring(startNum - 1 ) end end -- Estilo de lista -- ul_style y ol_style están incluidos para compatibilidad con versiones anteriores . No -- se hace distinción entre listas ordenadas o no ordenadas. data.listStyle = args.list_style -- Elementos de lista -- li_style está incluido para compatibilidad con versiones anteriores. item_style fue incluido -- para que sea más fácil de entender para quienes no saben codificar. data.itemStyle = args.item_style or args.li_style data.items = { } for _ , num in ipairs ( mTableTools.numKeys ( args ) ) do local item = { } item.content = args [ num ] item . estilo = args [ 'item' .. tostring ( num ) .. '_style' ] o args [ 'item_style' .. tostring ( num )] item .value = args [ ' item ' .. tostring ( num ) .. ' _value ' ] o args [ ' item_value ' .. tostring ( num ) ] tabla.insert ( data .items , item ) end return data end función p .renderList ( data ) -- Representa la lista HTML . -- Devuelve la cadena en blanco si no hay elementos en la lista . if tipo ( datos.items ) ~ = ' tabla' o # datos.items < 1 entonces devuelve ' ' fin - Representa la etiqueta div principal. raíz local = mw.html.create ( ' div ' ) para _ , clase en ipairs ( datos.classes o { } ) hacer raíz : addClass ( clase ) fin raíz : css { [ 'margin-left' ] = datos.marginLeft } si datos.style entonces raíz : cssText ( datos.style ) fin - Representa la etiqueta lista. lista local = raíz : etiqueta ( datos.listTag o ' ul ' ) lista : attr { inicio = datos.start , tipo = datos.type } : css { [ ' counter - reset ' ] = datos.counterReset , [ ' list - style - type ' ] = datos.listStyleType } si datos . listStyle entonces list : cssText ( data . listStyle ) fin - Representa los elementos de la lista para _ , t en ipairs ( data . items o {}) do local item = list : tag ( 'li' ) if data . itemStyle then item : cssText ( data . itemStyle ) fin if t . style then elemento : cssText ( t.style ) fin elemento : attr { valor = t.value } : wikitext ( t.content ) fin devolver datos.templatestyles..tostring ( root ) fin función p.renderTrackingCategories ( args ) local isDeprecated = false -- Realiza un seguimiento de los parámetros obsoletos. para k, v en pares(args) hacer k = tostring ( k ) si k : find ( ' ^ item_style % d + $ ' ) o k : find ( ' ^ item_value % d + $ ' ) entonces isDeprecated = true break fin fin local ret = ' ' si isDeprecated entonces ret = ret .. ' [ [ Categoría :Plantillas de lista con parámetros obsoletos ] ] ' fin devolver ret fin función p . makeList ( listType , args ) si no es listType o no listTypes [ listType ] entonces error ( string.format ( "argumento incorrecto n.° 1 para 'makeList' ('%s' no es un tipo de lista válido)" , tostring ( listType ) ) , 2 ) fin checkType ( 'makeList ' , 2 , args , ' table ' ) datos locales = p.makeListData ( listType , args ) lista local = p.renderList ( data ) categorías de seguimiento locales = p.renderTrackingCategories ( args ) devuelve lista .. trackingCategories fin para listType en pares ( listTypes ) hacer p [ listType ] = función ( frame ) local mArguments = require ( 'Module:Arguments' ) local origArgs = mArguments . getArgs ( frame , { frameOnly = (( frame y frame . args y frame . args . frameonly o '' ) ~= '' ), valueFunc = función ( key , value ) si no value o no mw . ustring . find ( value , '%S' ) entonces devuelve nil fin si mw . ustring . find ( value , '^%s*[%*#;:]' ) entonces devuelve valor de lo contrario devuelve valor : match ( '^%s*(.-)%s*$' ) fin devuelve nil fin }) - Copiar todos los argumentos a una nueva tabla, para una indexación más rápida. argumentos locales = {} para k , v en pares ( origArgs ) do args [ k ] = v end return p . makeList ( listType , args ) fin fin retorno p