Шаблон:Doc/styles.css: различия между версиями

Самозащитой является применение лицом средств противодействия, которые не запрещены законом и не противоречат моральным принципам общества
Перейти к навигации Перейти к поиску
Метка: отменено
Метка: отменено
Строка 1: Строка 1:
<templatestyles src="Sanitized CSS" />
use Wikimedia\CSS\Parser\Parser;
.ts-doc-doc {
use Wikimedia\CSS\Sanitizer\StylesheetSanitizer;
background-color: #eaf3ff;
border: 1px solid #a3caff;
margin-top: 1em;
}
 
.ts-doc-header {
background-color: #c2dcff;
padding: .642857em 1em .5em;
overflow: hidden;
}


.ts-doc-header .ts-tlinks-tlinks {
/** Parse a stylesheet from a string **/
line-height: 24px;
}


.ts-doc-header .ts-tlinks-tlinks a.external {
$parser = Parser::newFromString( $cssText );
color: #0645ad;
$stylesheet = $parser->parseStylesheet();
}


.ts-doc-header .ts-tlinks-tlinks a.external:visited {
/** Report any parser errors **/
color: #0b0080;
}


.ts-doc-header .ts-tlinks-tlinks a.external:active {
foreach ( $parser->getParseErrors() as list( $code, $line, $pos ) ) {
color: #faa700;
// $code is a string that should be suitable as a key for an i18n library.
// See errors.md for details.
$error = lookupI18nMessage( "css-parse-error-$code" );
echo "Parse error: $error at line $line character $pos\n";
}
}


.ts-doc-content {
/** Apply sanitization to the stylesheet **/
padding: .214286em 1em;
}


.ts-doc-content:after {
// If you need to customize the defaults, copy the code of this method and
content: '';
// modify it.
clear: both;
$sanitizer = StylesheetSanitizer::newDefault();
display: block;
$newStylesheet = $sanitizer->sanitize( $stylesheet );
}


.ts-doc-heading {
/** Report any sanitizer errors **/
display: inline-block;
padding-left: 30px;
background: url(//upload.wikimedia.org/wikipedia/commons/c/ca/OOjs_UI_icon_info.svg) center left/24px 24px no-repeat;
height: 24px;
line-height: 24px;
font-size: 13px;
font-weight: 600;
letter-spacing: 1px;
text-transform: uppercase;
}


.ts-doc-content > *:first-child,
foreach ( $sanitizer->getSanitizationErrors() as list( $code, $line, $pos ) ) {
.ts-doc-footer > *:first-child {
// $code is a string that should be suitable as a key for an i18n library.
margin-top: .5em;
// See errors.md for details.
$error = lookupI18nMessage( "css-sanitization-error-$code" );
echo "Sanitization error: $error at line $line character $pos\n";
}
}


.ts-doc-content > *:last-child,
/** Convert the sanitized stylesheet back to text **/
.ts-doc-footer > *:last-child {
margin-bottom: .5em;
}


.ts-doc-footer {
$newText = (string)$newStylesheet;
background-color: #eaf3ff;
border: 1px solid #a3caff;
padding: .214286em 1em;
margin-top: .214286em;
margin-bottom: .214286em;
font-style: italic;
}


@media (max-width: 719px) {
// Or if you'd rather have it minified too
.ts-doc-header .ts-tlinks-tlinks {
$minifiedText = Wikimedia\CSS\Util::stringify( $newStylesheet, [ 'minify' => true ] );
float: none;
}
}
/* [[Категория:Шаблоны:Подстраницы CSS]] */

Версия 12:51, 25 января 2022

use Wikimedia\CSS\Parser\Parser; use Wikimedia\CSS\Sanitizer\StylesheetSanitizer;

/** Parse a stylesheet from a string **/

$parser = Parser::newFromString( $cssText ); $stylesheet = $parser->parseStylesheet();

/** Report any parser errors **/

foreach ( $parser->getParseErrors() as list( $code, $line, $pos ) ) { // $code is a string that should be suitable as a key for an i18n library. // See errors.md for details. $error = lookupI18nMessage( "css-parse-error-$code" ); echo "Parse error: $error at line $line character $pos\n"; }

/** Apply sanitization to the stylesheet **/

// If you need to customize the defaults, copy the code of this method and // modify it. $sanitizer = StylesheetSanitizer::newDefault(); $newStylesheet = $sanitizer->sanitize( $stylesheet );

/** Report any sanitizer errors **/

foreach ( $sanitizer->getSanitizationErrors() as list( $code, $line, $pos ) ) { // $code is a string that should be suitable as a key for an i18n library. // See errors.md for details. $error = lookupI18nMessage( "css-sanitization-error-$code" ); echo "Sanitization error: $error at line $line character $pos\n"; }

/** Convert the sanitized stylesheet back to text **/

$newText = (string)$newStylesheet;

// Or if you'd rather have it minified too $minifiedText = Wikimedia\CSS\Util::stringify( $newStylesheet, [ 'minify' => true ] );