قالب:Mxt/User CSS for a monospaced coding font

من أرابيكا، الموسوعة الحرة

هذه هي النسخة الحالية من هذه الصفحة، وقام بتعديلها عبود السكاف (نقاش | مساهمات) في 22:54، 2 أكتوبر 2023 (بوت: تعريب V2.1). العنوان الحالي (URL) هو وصلة دائمة لهذه النسخة.

(فرق) → نسخة أقدم | نسخة حالية (فرق) | نسخة أحدث ← (فرق)
اذهب إلى التنقل اذهب إلى البحث

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 خاص: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 <code></code>, <pre></pre>, etc.
  • Do the same for the classes used by {{mxt}} and other monospaced templates in the {{نص ملون أخضر}} 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 [English].

Horizontal style

/* 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 */
#wpTextbox1, #wpSummary, #searchInput, #searchText { font-family: "Roboto Mono", monospace !important; }

Vertical style

/* 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 */
#wpTextbox1,
#wpSummary,
#searchInput,
#searchText {
  font-family: "Roboto Mono", monospace !important;
}

Cleanup efforts

If you'd like to help clean up instances of the <tt></tt> element – which has not been valid HTML since the 1990s, and should usually be replaced with <code></code> (this may vary by context) – you can add something like the following to your common.css to make <tt></tt> stick out like a sore thumb:

/* Flag bad code for cleanup */
tt { color: DarkRed; background: Pink; }

You can also do this with <font></font>, <center></center>, <strike></strike>, and other deprecated elements ‏. For CSS you can just import for this, see meta:User:SMcCandlish/lint.css.