Help:Listor

From mediawiki.org
Jump to navigation Jump to search
This page is a translated version of the page Help:Lists and the translation is 64% complete.
Other languages:
Bahasa Indonesia • ‎Deutsch • ‎English • ‎català • ‎español • ‎français • ‎polski • ‎português • ‎slovenčina • ‎suomi • ‎svenska • ‎русский • ‎العربية • ‎中文 • ‎日本語 • ‎한국어
PD OBS: När du redigerar denna sida samtycker du till att släppa ditt bidrag under CC0. Se hjälpsidorna för Public Domain för mer information.
PD

Den här sidan beskriver skapandet av listor i MediaWiki.

Grundläggande lista

MediaWiki erbjuder tre olika sorters listor: sorterade listor, osorterade listor och definitionslistor. I följande avsnitt används sorterade listor som exempel. Osorterade listor skulle ge motsvarande resultat.

Wikitext Återgivning
* Listor är enkla att göra:
** börja varje rad
* med en stjärna
** fler stjärnor betyder
*** djupare nivåer
  • Listor är enkla att göra:
    • börja varje rad
  • med en stjärna
    • fler stjärnor betyder
      • djupare nivåer
* En ny rad
* i en lista
markerar listans slut
Du kan
* så klart
* börja om
  • En ny rad
  • i en lista

markerar listans slut Du kan

  • så klart
  • börja om
# Numrerade listor är bra
## väldigt organiserade
## lätta att följa
  1. Numrerade listor är bra
    1. väldigt organiserade
    2. lätta att följa
* Du kan också
** bryta rader
** så här
  • Du kan också
    • bryta rader
    • så här
; Definitionslistor
; objekt : definition
; semikolon plus term
: kolon plus definition
Definitionslistor
objekt
definition
semikolon plus term
kolon plus definition
; blandade definitionslistor
; objekt 1 : definition
:; underobjekt 1 plus term
:: två kolon plus definition
:; underobjekt 2 : kolon plus definition
; objekt 2
: tillbaka till huvudlistan
blandade definitionslistor
objekt 1
definition
underobjekt 1 plus term
två kolon plus definition
underobjekt 2
kolon plus definition
objekt 2
tillbaka till huvudlistan
* Eller skapa blandade listor
*# och nästla dem
*#* så här
*#*; definitioner
*#*: jobb:
*#*; äpple
*#*; banan
*#*: frukt
  • Eller skapa blandade listor
    1. och nästla dem
      • så här
        definitioner
        jobb:
        äpple
        banan
        frukt

Paragrafer i listor

For simplicity, list items in wiki markup cannot be longer than a paragraph. A following blank line will end the list and reset the counter on ordered lists. Separating unordered list items usually has no noticeable effects.

Paragraphs can be forced in lists by using HTML tags. Two line break symbols, <br /><br />, will create the desired effect. So will enclosing all but the first paragraph with <p>...</p>.

For a list with items of more than one paragraph long, adding a blank line between items may be necessary to avoid confusion.

Continuing a list item after a sub-item

In HTML, a list item may contain several sublists, not necessarily adjacent; thus there may be parts of the list item not only before the first sublist, but also between sublists, and after the last one. However, in wiki-syntax, sublists follow the same rules as sections of a page: the only possible part of the list item not in sublists is before the first sublist.

In the case of an unnumbered first-level list in wikitext code this limitation can be overcome by splitting the list into multiple lists; indented text between the partial lists may visually serve as part of a list item after a sublist; however, this may give, depending on CSS, a blank line before and after each list, in which case, for uniformity, every first-level list item could be made a separate list.

Numbered lists illustrate that what should look like one list may, for the software, consist of multiple lists; unnumbered lists give a corresponding result, except that the problem of restarting with 1 is not applicable.

<ol>
  <li>listobjekt A1
    <ol>
      <li>listobjekt B1</li>
      <li>listobjekt B2</li>
    </ol>fortsätta listobjekt A1
  </li>
  <li>listobjekt A2</li>
</ol>
  1. listobjekt A1
    1. listobjekt B1
    2. listobjekt B2
    fortsatta listobjekt A1
  2. listobjekt A2
vs.
#listobjekt A1
##listobjekt B1
##listobjektB2
#:fortsatta listobjekt A1
#listobjekt A2
  1. listobjekt A1
    1. listobjekt B1
    2. listobjektB2
    fortsatta listobjekt A1
  2. listobjekt A2

En nivå djupare, med en underlista som fortsätter efter en underlista, en får ännu ljusare rader; fortsättningen däremot av den första nivån påverkas inte:

#listobjekt A1
##listobjekt B1
###listobjekt C1
##:fortsatta listobjekt B1
##listobjekt B2
#listobjekt A2

ger

  1. listobjekt A1
    1. listobjekt B1
      1. listobjekt C1
      fortsatta listobjekt B1
    2. listobjekt B2
  2. listobjekt A2

Se även m:Template:List demo.

It is possible to embed unnumbered bullets inside enclosing numbered items:

# list item A
#* nested bullet A1
#* nested bullet A2
# continuing list item B
#* nested bullet B1
#* nested bullet B2

gives

  1. list item A
    • nested bullet A1
    • nested bullet A2
  2. continuing list item B
    • nested bullet B1
    • nested bullet B2

Ändra listtypen

The list type (which type of marker appears before the list item) can be changed in CSS by setting the list-style-type property:

Wikitext Rendering
<ol style="list-style-type:lower-roman">
  <li>About the author</li>
  <li>Foreword to the first edition</li>
  <li>Foreword to the second edition</li>
</ol>
  1. About the author
  2. Foreword to the first edition
  3. Foreword to the second edition
<ol style="list-style-type:lower-alpha">
  <li>About the author</li>
  <li>Foreword to the first edition</li>
  <li>Foreword to the second edition</li>
</ol>
  1. About the author
  2. Foreword to the first edition
  3. Foreword to the second edition

Extra indentation of lists

In a numbered list in a large font, some browsers do not show more than two digits, unless extra indentation is applied (if there are multiple columns: for each column). This can be done with CSS:

ol { margin-left: 2cm}

or alternatively, like below.

Wikitext Rendering Comments
:#abc
:#def
:#ghi
 
  1. abc
  2. def
  3. ghi
A list of one or more lines starting with a colon creates a definition list without definition terms, and with the items as definition descriptions, hence indented. However, if the colons are in front of the codes "*" or "#" of an unordered or ordered list, the list is treated as one definition description, so the whole list is indented.
<ul>
  <ol>
    <li>abc</li>
    <li>def</li>
    <li>ghi</li>
  </ol>
</ul>
    1. abc
    2. def
    3. ghi
MediaWiki translates an unordered list (ul) without any list items (li) into a div with a style="margin-left: 2em", causing indentation of the contents. This is the most versatile method, as it allows starting with a number other than 1, see below.
<ul>
#abc
#def
#ghi
</ul>
    1. abc
    2. def
    3. ghi
Like above, with the content of the "unordered list without any list items", which itself is an ordered list, expressed with # codes. The HTML produced, and hence the rendering, is the same. This is the recommended method when starting the list at 1.

To demonstrate that all three methods show all digits of 3-digit numbers, see List demo.

Specifying a starting value

Specifying a starting value is possible with HTML syntax.

<ol start="9">
<li>Amsterdam</li>
<li>Rotterdam</li>
<li>Haag</li>
</ol>
  1. Amsterdam
  2. Rotterdam
  3. Haag

Eller:

<ol>
<li value="9">Amsterdam</li>
<li value="8">Rotterdam</li>
<li value="7">Haag</li>
</ol>
  1. Amsterdam
  2. Rotterdam
  3. Haag

Jämförelse med en tabell

Förutom att tillhandahålla en automatisk numrering, fixerar listorna dessutom objektens innehåll, jämfört med e tabellsyntax:

{|
|-
| align=right |  9.|| Amsterdam
|-
| align=right | 10.|| Rotterdam
|-
| align=right | 11.|| Haag
|}

ger:

9. Amsterdam
10. Rotterdam
11. Haag

Denna icke-automatiska numrering har fördelen att om text hänvisar till nummer, insättning eller radering av ett objekt inte förstör sammanhållningen.

Listor i flera kolumner

Se även Template:Col-begin, Template:Col-break, Template:Col-end

Punktlista med flera kolumner

<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
* äpple
* matta
* geografi
* berg
* ingenstans
* post
* sliten
* macka
</div>

ger:

  • äpple
  • matta
  • geografi
  • berg
  • ingenstans
  • post
  • sliten
  • macka
<div style="column-count:3;-moz-column-count:3;-webkit-column-count:3">
* äpple
* matta
* geografi
* berg
* ingenstans
* post
* sliten
* macka
</div>

ger:

  • äpple
  • matta
  • geografi
  • berg
  • ingenstans
  • post
  • sliten
  • macka

Numrerad lista med flera kolumner

<div style="column-count:3;-moz-column-count:3;-webkit-column-count:3">
# äpple
# matta
# geografi
# berg
# ingenstans
# post
# sliten
# macka
</div>

ger:

  1. äpple
  2. matta
  3. geografi
  4. berg
  5. ingenstans
  6. post
  7. sliten
  8. macka

Nedan anges ett startvärde, med HTML-syntax (för den första kolumnen kan antingen wiki-syntax eller HTML-syntax användas).

I kombination med den extra indragningen som förklarats i tidigare avsnitt:

{| valign="top"
|-
|<ul><ol start="125"><li>a<li>bb<li>ccc</ol></ul>
|<ul><ol start="128"><li>ddd<li>ee<li>f</ol></ul>
|}

ger

    1. a
    2. bb
    3. ccc
    1. ddd
    2. ee
    3. f

Using m:Template:multi-column numbered list the computation of the starting values can be automated, and only the first starting value and the number of items in each column except the last has to be specified. Adding an item to, or removing an item from a column requires adjusting only one number, the number of items in that column, instead of changing the starting numbers for all subsequent columns.

{{Multi-column numbered list|125|a<li>bb<li>ccc|3|<li>ddd<li>ee<li>f}}

ger:

    1. a
    2. bb
    3. ccc
    1. ddd
    2. ee
    3. f
{{Multi-column numbered list|lst=lower-alpha|125|a<li>bb<li>ccc|3|<li>ddd<li>ee|2|<li>f}}

ger:

    1. a
    2. bb
    3. ccc
    1. ddd
    2. ee
    1. f
{{Multi-column numbered list|lst=lower-roman|125|a<li>bb<li>ccc|3|<li>ddd<li>ee|2|<li>f}}

ger:

    1. a
    2. bb
    3. ccc
    1. ddd
    2. ee
    1. f
{{Multi-column numbered list|lst=disc||a<li>bb<li>ccc||<li>ddd<li>ee||<li>f}}

ger:

    1. a
    2. bb
    3. ccc
    1. ddd
    2. ee
    1. f

Streamlined style or horizontal style

It is also possible to present short lists using very basic formatting, such as:

''Title of list:'' example 1, example 2, example 3

Title of list: example 1, example 2, example 3

This style requires less space on the page, and is preferred if there are only a few entries in the list, it can be read easily, and a direct edit point is not required. The list items should start with a lowercase letter unless they are proper nouns.

Tabeller

A one-column table is very similar to a list, but it allows sorting. If the wikitext itself is already sorted with the same sortkey, this advantage does not apply. A multiple-column table allows sorting on any column.

See also When to use tables.

Changing unordered lists to ordered ones

With the CSS

ul { list-style: decimal }

unordered lists are changed to ordered ones. This applies (as far as the CSS selector does not restrict this) to all ul-lists in the HTML source code:

  • those produced with *
  • those with <ul> in the wikitext
  • those produced by the system

Since each special page, like other pages, has a class based on the pagename, one can separately specify for each type whether the lists should be ordered, see User contributions and What links here.

However, it does not seem possible to make all page history lists ordered (unless one makes all lists ordered), because the class name is based on the page for which the history is viewed.

Se även