Шаблон:Mxt/User CSS for a monospaced coding font: различия между версиями

Материал из Машинное обучение - Кафедра прикладной кибернетики
Перейти к навигации Перейти к поиску
(A more serious test of your font. Update about pages transcluding this.)
 
м (1 версия импортирована)
 
(нет различий)

Текущая версия на 01:21, 30 августа 2021

{{#invoke:Message box|ombox}}{{#if: ||Шаблон:Namespace detect

              }}

You can consistently use a monospaced font with well-designed characters for coding (e.g., to distinguish clearly between l, 1, and I, and between O and 0, and between -, −, –, and —).

Add something like one of the code snippets below into your Special:MyPage/common.css page, replacing "Roboto Mono" with whatever your preferred coding font is (Roboto Mono was picked as a freely-available coding font for this example).

If you don't want to manually add this code to your CSS page but would rather @import (transclude) it, see meta:User:SMcCandlish/codefont.css for quick instructions.

This code will do the following:

  • Apply a consistent monospace font of your choice (and the fallback system-default monospace, should that font go missing or not have characters you need) to all the normally monospaced HTML elements like {{#switch:o
 |c|close =
 |e|empty|s|single|v|void
 |o|open
 |p|pair = <{{#if:|code|code}}{{#if:| {{{attribs}}}}}
}}{{#switch:o
 |c|close = 
 |e|empty|s|single|v|void =  />
 |o|open = >
 |p|pair = {{#ifeq:code|!--||>}}...
}}{{#switch:o
 |e|empty|s|single|v|void
 |o|open =
 |c|close
 |p|pair = {{#ifeq:code|!--|-->|</code>}}
}}, {{#switch:o
 |c|close =
 |e|empty|s|single|v|void
 |o|open
 |p|pair = <{{#if:|pre|pre}}{{#if:| {{{attribs}}}}}
}}{{#switch:o
 |c|close = 
 |e|empty|s|single|v|void =  />
 |o|open = >
 |p|pair = {{#ifeq:pre|!--||>}}...
}}{{#switch:o
 |e|empty|s|single|v|void
 |o|open =
 |c|close
 |p|pair = {{#ifeq:pre|!--|-->|</pre>}}
}}, etc.
  • Do the same for the classes used by {{#Invoke:Template link general|main|code=on}} and other monospaced templates in the {{#Invoke:Template link general|main|code=on}} family
  • Do the same for additional site-wide classes (as identified so far, e.g. .monospaced) that output as monospace.
  • Make the three most frequently encountered editing fields also use this font stack: the main editing window, the edit summary line, and the search entry box.

If you know of an additional class to add here, please update this page or mention it on the talk page.

Horizontal style <syntaxhighlight lang="css">/* Use my font, when available, for code */ code, pre, samp, kbd, tt, .example-mono, .userlinks-username, .monospaced, .keyboard-key, .button, .plaincode { font-family: "Roboto Mono", monospace !important; } /* Make some of the editable stuff monospaced */

  1. wpTextbox1, #wpSummary, #searchInput, #searchText { font-family: "Roboto Mono", monospace !important; }</syntaxhighlight>

Vertical style <syntaxhighlight lang="css">/* Use my font, when available, for code */ code, pre, samp, kbd, tt, .example-mono, .userlinks-username, .monospaced, .keyboard-key, .button .plaincode {

 font-family: "Roboto Mono", monospace !important;

} /* Make some of the editable stuff monospaced */

  1. wpTextbox1,
  2. wpSummary,
  3. searchInput,
  4. searchText {
 font-family: "Roboto Mono", monospace !important;

}</syntaxhighlight>

{{safesubst:#invoke:anchor|main}}Cleanup efforts

If you'd like to help clean up instances of the {{#switch:pair

 |c|close =
 |e|empty|s|single|v|void
 |o|open
 |p|pair = <{{#if:|[[HTML element#{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон
|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}|{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон

|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}]]|{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон

|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}}}{{#if:| {{{attribs}}}}}

}}{{#switch:pair
 |c|close = 
 |e|empty|s|single|v|void =  />
 |o|open = >
 |p|pair = {{#ifeq:{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон
|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}|!--||>}}...

}}{{#switch:pair
 |e|empty|s|single|v|void
 |o|open =
 |c|close
 |p|pair = {{#ifeq:{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон
|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}|!--|-->|</{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон

|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}>}}

}} element – which has not been valid HTML since the 1990s, and should usually be replaced with {{#switch:pair
 |c|close =
 |e|empty|s|single|v|void
 |o|open
 |p|pair = <{{#if:|[[HTML element#{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон
|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|code}}|{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон

|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|code}}]]|{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон

|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|code}}}}{{#if:| {{{attribs}}}}}

}}{{#switch:pair
 |c|close = 
 |e|empty|s|single|v|void =  />
 |o|open = >
 |p|pair = {{#ifeq:{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон
|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|code}}|!--||>}}...

}}{{#switch:pair
 |e|empty|s|single|v|void
 |o|open =
 |c|close
 |p|pair = {{#ifeq:{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон
|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|code}}|!--|-->|</{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон

|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|code}}>}}

}} (this may vary by context) – you can add something like the following to your common.css to make {{#switch:o
 |c|close =
 |e|empty|s|single|v|void
 |o|open
 |p|pair = <{{#if:|[[HTML element#{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон
|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}|{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон

|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}]]|{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон

|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}}}{{#if:| {{{attribs}}}}}

}}{{#switch:o
 |c|close = 
 |e|empty|s|single|v|void =  />
 |o|open = >
 |p|pair = {{#ifeq:{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон
|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}|!--||>}}...

}}{{#switch:o
 |e|empty|s|single|v|void
 |o|open =
 |c|close
 |p|pair = {{#ifeq:{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон
|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}|!--|-->|</{{#ifeq:Шаблон||{{#invoke:Error|error|[[:{{#invoke:TEMPLATENAME|main}}]] is only for examples of style and formatting. Do not use it in actual articles.|tag=}}{{#switch:Шаблон

|Обсуждение
|Участник
|Обсуждение участника
|Шаблон:Ns:Wikipedia talk=
|#default={{#if:|
 |
}}

}}|tt}}>}}

}} stick out like a sore thumb:

<syntaxhighlight lang="css">/* Flag bad code for cleanup */ tt { color: DarkRed; background: Pink; }</syntaxhighlight>

You can also do this with {{#switch:o

 |c|close =
 |e|empty|s|single|v|void
 |o|open
 |p|pair = <{{#if:|font|font}}{{#if:| {{{attribs}}}}}
}}{{#switch:o
 |c|close = 
 |e|empty|s|single|v|void =  />
 |o|open = >
 |p|pair = {{#ifeq:font|!--||>}}...
}}{{#switch:o
 |e|empty|s|single|v|void
 |o|open =
 |c|close
 |p|pair = {{#ifeq:font|!--|-->|</font>}}
}}, {{#switch:o
 |c|close =
 |e|empty|s|single|v|void
 |o|open
 |p|pair = <{{#if:|center|center}}{{#if:| {{{attribs}}}}}
}}{{#switch:o
 |c|close = 
 |e|empty|s|single|v|void =  />
 |o|open = >
 |p|pair = {{#ifeq:center|!--||>}}...
}}{{#switch:o
 |e|empty|s|single|v|void
 |o|open =
 |c|close
 |p|pair = {{#ifeq:center|!--|-->|</center>}}
}}, {{#switch:o
 |c|close =
 |e|empty|s|single|v|void
 |o|open
 |p|pair = <{{#if:|strike|strike}}{{#if:| {{{attribs}}}}}
}}{{#switch:o
 |c|close = 
 |e|empty|s|single|v|void =  />
 |o|open = >
 |p|pair = {{#ifeq:strike|!--||>}}...
}}{{#switch:o
 |e|empty|s|single|v|void
 |o|open =
 |c|close
 |p|pair = {{#ifeq:strike|!--|-->|</strike>}}
}}, and other deprecated elements.  For CSS you can just import for this, see meta:User:SMcCandlish/lint.css.{{#invoke:documentation|main|_content={{ {{#invoke:documentation|contentTitle}}}}}}