Wikipedia:Lua/Modul/TemplateData/Wikitext/en

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

Modul: Dokumentation

Since 2018 it is possible to specify details (custom formats) how the parameter set shall be inserted into source code and which layout is desired.

First, there have been two formats only:

The method explained here is using keywords rather than a cryptic syntax character by character to specify a user defined formatting goal. That should cover common standard cases.

The MediaWiki software does not offer automatic aligning of = depending on the current longest parameter name.

Specification by JSON[Quelltext bearbeiten]

The actual specification is done via component "format" of JSON object in TemplateData.

In addition to the two keywords inline and block in early 2018 MediaWiki has introduced patterns of sprcial characters for definition of source code formatting.

This Lua module generates that syntax from more comprehensive internal keywords.

inline (all in one line)[Quelltext bearbeiten]

That is default, if there is no specification at all.

No line breaks will be inserted; the counterpart is block.

inline (MediaWiki keyword)[Quelltext bearbeiten]

{{trip|from=London|to=Paris}}
Effect All parameters without any space directly concatenated.
JSON "format": "inline"
Character code {{_|_=_}}

inline half (Halfpipe – sparse spaces)[Quelltext bearbeiten]

{{trip |from=London |to=Paris}}
Effect There shall be one space ahead of every pipe symbol, which permits pretty folding of source code lines on long parameter lists. Nevertheless the assignments are grouped in obvious manner.
JSON "format": "inline half"
Character code {{_ |_=_}}

This takes precedence over inline grouped and inline spaced.

inline grouped (grouped assignment)[Quelltext bearbeiten]

{{trip | from=London | to=Paris}}
Effect Every pipe symbol is surrounded by spaces, parameter assignments kept compact.
JSON "format": "inline grouped"
Character code {{_ | _=_}}

This takes precedence over inline spaced.

inline spaced (many spaces)[Quelltext bearbeiten]

{{trip | from = London | to = Paris }}
Effect Every pipe symbol and equal sign is surrounded by spaces, also one space ahead of }}.
JSON "format": "inline spaced"
Character code {{_ | _ = _ }}

inline newlines (single line)[Quelltext bearbeiten]

Before
{{trip|from=London|to=Paris}}
After
Effect Transclusion begins and terminates on a new line.
JSON "format": "inline newlines"
Character code \n{{_|_=_}}\n

This keyword may be combined with all other inline extensions.

This is useful e.g. for table row templates, which are supposed to be written compact in one source code line, but each on its own line.

block (parameters in new lines)[Quelltext bearbeiten]

In this mode every parameter assignment uses a different line. That is recommended for templates with many parameters, like infoboxes or citations.

While the MediaWiki keyword does not emit line breaks outside the brackets, with all additional keywords the transclusions start and end on new lines. By default the pipe symbol is not followed by space.

The \n at begin causes the transclusion on a new line, but not an empty line at begin of the entire page.

block (MediaWiki keyword)[Quelltext bearbeiten]

North{{trip
| from = London
| to = Paris
}}South

Transclusion begins and terminates without line break.

Effect
  • Every pipe symbol is followed by one space, equal signs is surrounded by spaces.
  • }} starts on a new line.
JSON "format": "block"
Character code {{_\n| _ = _\n}}

block newlines (new lines around transclusion)[Quelltext bearbeiten]

North
{{trip
|from = London
|to = Paris
}}
South
Effect

Transclusion begins and terminates on a new line. Inner structure similar to Mediawiki standard keyword, but basically without space after pipe symbol.

JSON "format": "block newlines"
Character code \n{{_\n|_ = _\n}}\n

The keyword newlines is not required elsewhere, since always implied by the other block extensions.

block indent (indented)[Quelltext bearbeiten]

North
{{trip
 |from = London
 |to = Paris
}}
South
Effect Ahead of every pipe symbol one space is inserted at begin of line. The remaining formatting is not influenced.
JSON "format": "block indent"
Character code \n{{_\n |_ = _\n}}\n

This keyword may be combined with all other block extensions.

block compressed (compressed)[Quelltext bearbeiten]

North
{{trip
|from=London
|to=Paris}}
South
Effect Parameter assignments without any space directly concatenated. }} follows immediately the last value.
JSON "format": "block compressed"
Character code \n{{_\n|_=_}}\n

The keywords indent and last may be added.

block align (align equal signs)[Quelltext bearbeiten]

North
{{trip
|from = London
|to   = Paris
}}
South
Effect Equal signs will be aligned in consecutive lines and between the longest parameter name and the equal sign remains one space. Deprecated and aliased names are not considered for fetching maximum name length.
JSON "format": "block align"
Character code \n{{_\n|____ = _\n}}\n

This takes precedence over block after and block dense.

block align nn (align equal signs at fixed position)[Quelltext bearbeiten]

North
{{trip
|from   = London
|to     = Paris
}}
South
Effect Equal signs will be aligned in consecutive lines in a way that between a parameter name of given length and the equal sign remains one space. Instead of “9999” the desired length is to be provided, e.g. 6, but not more than 99.
JSON "format": "block align 9999"
Character code \n{{_\n|______ = _\n}}\n

This is an extension of block align.

block after (space only after equal signs)[Quelltext bearbeiten]

North
{{trip
|from= London
|to= Paris
}}
South
Effect Before equal signs no space shall appear, but afterwards.
JSON "format": "block after"
Character code \n{{_\n|_= _\n}}\n

This takes precedence over block dense.

block dense (no space at equal sign)[Quelltext bearbeiten]

North
{{trip
|from=London
|to=Paris
}}
South
Effect Neither beforen or after equal sign a space shall be inserted.
JSON "format": "block dense"
Character code \n{{_\n|_=_\n}}\n

The effect is like block compressed, but permits block lead.

block lead (space after pipe symbol)[Quelltext bearbeiten]

North
{{trip
| from = London
| to = Paris
}}
South
Effect After pipe symbol | a space shall be inserted.
JSON "format": "block lead"
Character code \n{{_\n| _ = _\n}}\n

This cannot be effective with block compressed.

block last (closing }} position)[Quelltext bearbeiten]

The position of terminating }} shall be changed:

  • On block compressed}} at beginning of a new line.
  • else – }} appended to the last parameter assignment.

Template escaping[Quelltext bearbeiten]

When a template like Template:TemplateData contains JSON source code as parameter value, pipe symbol and brackets }} would break template syntax. Here the pipe symbol may be escaped by | and one closing bracket by }.

The following table shows translation of character codes into keywords and illlustrates principles of generation.

Character code Keywords
{{_|_=_}} inline
{{_ |_=_}} inline half
{{_ | _=_}} inline grouped
{{_ | _ = _ }} inline spaced
\n{{_|_=_}}\n inline newlines
{{_\n| _ = _\n}} block
\n{{_\n|_ = _\n}}\n block newlines
\n{{_\n |_ = _\n}}\n block indent
\n{{_\n|_=_}}\n block compressed
block dense last
\n{{_\n |_=_}}\n block indent compressed
\n{{_\n|_=_\n}}\n block compressed last
\n{{_\n |_=_\n}}\n block indent compressed last
\n{{_\n|_= _\n}}\n block after
\n{{_\n|_=_\n}}\n block dense
\n{{_\n |_= _\n}}\n block indent after
\n{{_\n |_= _ }}\n block indent after last
\n{{_\n | _= _\n}}\n block indent lead after
\n{{_\n | _= _ }}\n block indent lead after last
\n{{_\n |_=_\n}}\n block indent dense
\n{{_\n | _=_\n}}\n block indent lead dense
\n{{_\n| _= _\n}}\n block lead after
\n{{_\n| _=_\n}}\n block lead dense