2023-07-16 23:53:45
This commit is contained in:
parent
875f0b9e69
commit
bc3d85fea8
|
@ -0,0 +1 @@
|
|||
.idea/
|
|
@ -0,0 +1,13 @@
|
|||
# Contributing
|
||||
|
||||
- Feedback, wishes and suggestions can be sent by email.
|
||||
- Constructive criticism, bug descriptions and other reports are welcome.
|
||||
- Email: mail@ihub.to
|
||||
|
||||
## Sources
|
||||
|
||||
- [**GitHub**](https://github.com/pkgstore)
|
||||
- [GitLab](https://gitlab.com/pkgstore) (MIRROR)
|
||||
- [Codeberg](https://codeberg.org/pkgstore) (MIRROR)
|
||||
- [MosHub](https://hub.mos.ru/pkgstore) (MIRROR)
|
||||
- [Git.Org.Ru](https://git.org.ru/pkgstore) (MIRROR)
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2023 Package Store
|
||||
Copyright (c) 2023 iHub TO <https://ihub.to>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\PkgStore;
|
||||
|
||||
use MWException;
|
||||
use OutputPage, Parser, PPFrame, Skin;
|
||||
|
||||
/**
|
||||
* Class MW_EXT_Src
|
||||
*/
|
||||
class MW_EXT_Src
|
||||
{
|
||||
/**
|
||||
* Register tag function.
|
||||
*
|
||||
* @param Parser $parser
|
||||
*
|
||||
* @return void
|
||||
* @throws MWException
|
||||
*/
|
||||
public static function onParserFirstCallInit(Parser $parser): void
|
||||
{
|
||||
$parser->setHook('src', [__CLASS__, 'onRenderTag']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render tag function.
|
||||
*
|
||||
* @param $input
|
||||
* @param array $args
|
||||
* @param Parser $parser
|
||||
* @param PPFrame $frame
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function onRenderTag($input, array $args, Parser $parser, PPFrame $frame): ?string
|
||||
{
|
||||
// Message: block title.
|
||||
$msgTitle = MW_EXT_Kernel::getMessageText('src', 'block-title');
|
||||
|
||||
// Argument: type.
|
||||
$getType = MW_EXT_Kernel::outClear($args['type'] ?? '' ?: 'block');
|
||||
$outType = $getType;
|
||||
|
||||
// Argument: title.
|
||||
$getTitle = MW_EXT_Kernel::outClear($args['title'] ?? '' ?: $msgTitle);
|
||||
$outTitle = $getTitle;
|
||||
|
||||
// Argument: lang.
|
||||
$getLang = MW_EXT_Kernel::outClear($args['lang'] ?? '' ?: 'none');
|
||||
$outLang = $getLang;
|
||||
|
||||
// Get content.
|
||||
$getContent = MW_EXT_Kernel::outClear($input);
|
||||
$outContent = $getContent;
|
||||
|
||||
// Out code class.
|
||||
$outClass = ' class="language-' . $outLang . '"';
|
||||
|
||||
// Out HTML.
|
||||
if ($outType === 'block') {
|
||||
$outHTML = '<div class="mw-src mw-src-block navigation-not-searchable">';
|
||||
$outHTML .= '<div class="mw-src-header"><div class="mw-src-title">' . $outTitle . '</div><div class="mw-src-lang">' . $outLang . '</div></div>';
|
||||
$outHTML .= '<div class="mw-src-content"><pre><code' . $outClass . '>' . $outContent . '</code></pre></div>';
|
||||
$outHTML .= '</div>';
|
||||
} elseif ($outType === 'inline') {
|
||||
$outHTML = '<span class="mw-src mw-src-inline"><code' . $outClass . '>' . $outContent . '</code></span>';
|
||||
} else {
|
||||
$parser->addTrackingCategory('mw-src-error-category');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Out parser.
|
||||
return $outHTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load resource function.
|
||||
*
|
||||
* @param OutputPage $out
|
||||
* @param Skin $skin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function onBeforePageDisplay(OutputPage $out, Skin $skin): void
|
||||
{
|
||||
$out->addModuleStyles(['ext.mw.src.styles']);
|
||||
$out->addModules(['ext.mw.src']);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
// Confirm MediaWiki environment.
|
||||
if (!defined('MEDIAWIKI')) {
|
||||
die('This file is a MediaWiki extension and thus not a valid entry point.');
|
||||
}
|
||||
|
||||
if (function_exists('wfLoadExtension')) {
|
||||
wfLoadExtension('MW_EXT_Src');
|
||||
// Keep i18n globals so mergeMessageFileList.php doesn't break.
|
||||
$wgExtensionMessagesFiles['MW_EXT_Src'] = __DIR__ . '/i18n';
|
||||
|
||||
return;
|
||||
} else {
|
||||
die('This version of the MW_EXT_Src extension requires MediaWiki 1.31+');
|
||||
}
|
23
README.md
23
README.md
|
@ -1 +1,22 @@
|
|||
# mediawiki-ext-src
|
||||
# Information
|
||||
|
||||
Интеграция тега кода `SRC` в статью.
|
||||
|
||||
## Install
|
||||
|
||||
1. Загрузите папки и файлы в директорию `extensions/MW_EXT_Src`.
|
||||
2. В самый низ файла `LocalSettings.php` добавьте строку:
|
||||
|
||||
```php
|
||||
wfLoadExtension( 'MW_EXT_Src' );
|
||||
```
|
||||
|
||||
## Syntax
|
||||
|
||||
```html
|
||||
<src type="[TYPE]" lang="[LANGUAGE]">[CONTENT]</src>
|
||||
```
|
||||
|
||||
Где `[TYPE]` это:
|
||||
- `block` - блочное форматирование кода;
|
||||
- `inline` - строчное форматирование кода.
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"name": "pkgstore/mediawiki-ext-src",
|
||||
"type": "mediawiki-extension",
|
||||
"description": "MediaWiki syntax highlight extension.",
|
||||
"license": "MIT",
|
||||
"homepage": "https://ihub.to/",
|
||||
"keywords": [
|
||||
"mediawiki",
|
||||
"src"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "iHub TO",
|
||||
"email": "mail@ihub.to",
|
||||
"homepage": "https://ihub.to/",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Kitsune Solar",
|
||||
"email": "mail@kitsune.solar",
|
||||
"homepage": "https://kitsune.solar/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/pkgstore/mediawiki-ext-src/issues",
|
||||
"source": "https://github.com/pkgstore/mediawiki-ext-src"
|
||||
},
|
||||
"require": {
|
||||
"composer/installers": "^1.0.1",
|
||||
"php": ">=8.2",
|
||||
"pkgstore/mediawiki-ext-kernel": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"MW_EXT_Src.class.php"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"prepend-autoloader": false
|
||||
},
|
||||
"extra": {
|
||||
"installer-name": "MW_EXT_Src"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
"name": "MW_EXT_Src",
|
||||
"version": "2.0.0",
|
||||
"author": [
|
||||
"[https://ihub.to/ iHub TO]",
|
||||
"[https://kitsune.solar/ Kitsune Solar]",
|
||||
"..."
|
||||
],
|
||||
"url": "https://ihub.to/",
|
||||
"descriptionmsg": "mw-src-desc",
|
||||
"license-name": "[https://choosealicense.com/licenses/mit/ MIT]",
|
||||
"type": "parserhook",
|
||||
"require": {
|
||||
"MediaWiki": ">= 1.31.0",
|
||||
"extensions": {
|
||||
"MW_EXT_Kernel": "*"
|
||||
}
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"MediaWiki\\Extension\\PkgStore\\MW_EXT_Src": "MW_EXT_Src.class.php"
|
||||
},
|
||||
"Hooks": {
|
||||
"ParserFirstCallInit": [
|
||||
"MediaWiki\\Extension\\PkgStore\\MW_EXT_Src::onParserFirstCallInit"
|
||||
],
|
||||
"BeforePageDisplay": [
|
||||
"MediaWiki\\Extension\\PkgStore\\MW_EXT_Src::onBeforePageDisplay"
|
||||
]
|
||||
},
|
||||
"MessagesDirs": {
|
||||
"MW_EXT_Src": [
|
||||
"i18n"
|
||||
]
|
||||
},
|
||||
"ResourceModules": {
|
||||
"ext.mw.src": {
|
||||
"scripts": [
|
||||
"scripts/prism.min.js",
|
||||
"scripts/main.min.js"
|
||||
],
|
||||
"position": "bottom",
|
||||
"targets": [
|
||||
"desktop",
|
||||
"mobile"
|
||||
]
|
||||
},
|
||||
"ext.mw.src.styles": {
|
||||
"styles": [
|
||||
"styles/theme.css"
|
||||
],
|
||||
"position": "top",
|
||||
"targets": [
|
||||
"desktop",
|
||||
"mobile"
|
||||
]
|
||||
}
|
||||
},
|
||||
"ResourceFileModulePaths": {
|
||||
"localBasePath": "modules",
|
||||
"remoteExtPath": "MW_EXT_Src/modules"
|
||||
},
|
||||
"manifest_version": 2
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"@metadata": {
|
||||
"authors": [
|
||||
"iHub TO"
|
||||
]
|
||||
},
|
||||
"mw-src-desc": "Подсветка синтаксиса исходного кода на основе библиотеки [http://prismjs.com/ Prism.JS].",
|
||||
"mw-src-error-category": "META:ERROR.EXT.Src",
|
||||
"mw-src-block-title": "Код"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
$(function () {
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
"use strict";$(function(){});
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,47 @@
|
|||
div.mw-src {
|
||||
margin: 1em 0 1em;
|
||||
box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
|
||||
border: 1px solid hsl(0, 0%, 86%);
|
||||
.mw-src-header {
|
||||
overflow: hidden;
|
||||
padding: .4em .8em;
|
||||
background: #f5f5f5;
|
||||
border-bottom: 1px solid hsl(0, 0%, 86%);
|
||||
font-family: 'Fira Mono', monospace;
|
||||
.mw-src-title {
|
||||
float: left;
|
||||
}
|
||||
.mw-src-lang {
|
||||
float: right;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
}
|
||||
pre {
|
||||
display: block;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
white-space: pre;
|
||||
border: 1px solid hsl(0, 0%, 100%);
|
||||
line-height: 1.5;
|
||||
code {
|
||||
display: block;
|
||||
max-height: 50em;
|
||||
overflow: auto;
|
||||
border: none;
|
||||
padding: 1em;
|
||||
border-radius: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
span.mw-src {
|
||||
display: inline-block;
|
||||
code {
|
||||
border: none;
|
||||
padding: .1em .4em .1em;
|
||||
border-radius: .4em;
|
||||
&.hljs {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
/* PrismJS 1.15.0
|
||||
https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+apacheconf+c+csharp+bash+cpp+coffeescript+ruby+diff+markup-templating+go+http+ini+java+json+less+lua+makefile+markdown+nginx+objectivec+perl+php+sql+powershell+python+rust+sass+scss+swift+wiki */
|
||||
/**
|
||||
* prism.js default theme for JavaScript, CSS and HTML
|
||||
* Based on dabblet (http://dabblet.com)
|
||||
* @author Lea Verou
|
||||
*/
|
||||
|
||||
code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
color: black;
|
||||
background: none;
|
||||
text-shadow: 0 1px white;
|
||||
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
|
||||
text-align: left;
|
||||
white-space: pre;
|
||||
word-spacing: normal;
|
||||
word-break: normal;
|
||||
word-wrap: normal;
|
||||
line-height: 1.5;
|
||||
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
|
||||
-webkit-hyphens: none;
|
||||
-moz-hyphens: none;
|
||||
-ms-hyphens: none;
|
||||
hyphens: none;
|
||||
}
|
||||
|
||||
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
|
||||
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
|
||||
text-shadow: none;
|
||||
background: #b3d4fc;
|
||||
}
|
||||
|
||||
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
|
||||
code[class*="language-"]::selection, code[class*="language-"] ::selection {
|
||||
text-shadow: none;
|
||||
background: #b3d4fc;
|
||||
}
|
||||
|
||||
@media print {
|
||||
code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
text-shadow: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Code blocks */
|
||||
pre[class*="language-"] {
|
||||
padding: 1em;
|
||||
margin: .5em 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
:not(pre) > code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
background: #f5f2f0;
|
||||
}
|
||||
|
||||
/* Inline code */
|
||||
:not(pre) > code[class*="language-"] {
|
||||
padding: .1em;
|
||||
border-radius: .3em;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.token.comment,
|
||||
.token.prolog,
|
||||
.token.doctype,
|
||||
.token.cdata {
|
||||
color: slategray;
|
||||
}
|
||||
|
||||
.token.punctuation {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.namespace {
|
||||
opacity: .7;
|
||||
}
|
||||
|
||||
.token.property,
|
||||
.token.tag,
|
||||
.token.boolean,
|
||||
.token.number,
|
||||
.token.constant,
|
||||
.token.symbol,
|
||||
.token.deleted {
|
||||
color: #905;
|
||||
}
|
||||
|
||||
.token.selector,
|
||||
.token.attr-name,
|
||||
.token.string,
|
||||
.token.char,
|
||||
.token.builtin,
|
||||
.token.inserted {
|
||||
color: #690;
|
||||
}
|
||||
|
||||
.token.operator,
|
||||
.token.entity,
|
||||
.token.url,
|
||||
.language-css .token.string,
|
||||
.style .token.string {
|
||||
color: #9a6e3a;
|
||||
background: hsla(0, 0%, 100%, .5);
|
||||
}
|
||||
|
||||
.token.atrule,
|
||||
.token.attr-value,
|
||||
.token.keyword {
|
||||
color: #07a;
|
||||
}
|
||||
|
||||
.token.function,
|
||||
.token.class-name {
|
||||
color: #DD4A68;
|
||||
}
|
||||
|
||||
.token.regex,
|
||||
.token.important,
|
||||
.token.variable {
|
||||
color: #e90;
|
||||
}
|
||||
|
||||
.token.important,
|
||||
.token.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
.token.italic {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.token.entity {
|
||||
cursor: help;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
code[class*="language-"],pre[class*="language-"]{color:black;background:none;text-shadow:0 1px white;font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*="language-"]::-moz-selection,pre[class*="language-"] ::-moz-selection,code[class*="language-"]::-moz-selection,code[class*="language-"] ::-moz-selection{text-shadow:none;background:#b3d4fc}pre[class*="language-"]::selection,pre[class*="language-"] ::selection,code[class*="language-"]::selection,code[class*="language-"] ::selection{text-shadow:none;background:#b3d4fc}@media print{code[class*="language-"],pre[class*="language-"]{text-shadow:none}}pre[class*="language-"]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*="language-"],pre[class*="language-"]{background:#f5f2f0}:not(pre)>code[class*="language-"]{padding:.1em;border-radius:.3em;white-space:normal}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:slategray}.token.punctuation{color:#999}.namespace{opacity:.7}.token.property,.token.tag,.token.boolean,.token.number,.token.constant,.token.symbol,.token.deleted{color:#905}.token.selector,.token.attr-name,.token.string,.token.char,.token.builtin,.token.inserted{color:#690}.token.operator,.token.entity,.token.url,.language-css .token.string,.style .token.string{color:#9a6e3a;background:rgba(255,255,255,0.5)}.token.atrule,.token.attr-value,.token.keyword{color:#07a}.token.function,.token.class-name{color:#DD4A68}.token.regex,.token.important,.token.variable{color:#e90}.token.important,.token.bold{font-weight:bold}.token.italic{font-style:italic}.token.entity{cursor:help}div.mw-src{margin:1em 0 1em;box-shadow:0 1px 1px rgba(0,0,0,0.05);border:1px solid #dbdbdb}div.mw-src .mw-src-header{overflow:hidden;padding:.4em .8em;background:#f5f5f5;border-bottom:1px solid #dbdbdb;font-family:'Fira Mono', monospace}div.mw-src .mw-src-header .mw-src-title{float:left}div.mw-src .mw-src-header .mw-src-lang{float:right;text-transform:uppercase}div.mw-src pre{display:block;margin:0;padding:0;white-space:pre;border:1px solid #fff;line-height:1.5}div.mw-src pre code{display:block;max-height:50em;overflow:auto;border:none;padding:1em;border-radius:0}span.mw-src{display:inline-block}span.mw-src code{border:none;padding:.1em .4em .1em;border-radius:.4em}span.mw-src code.hljs{display:inline}
|
|
@ -0,0 +1,2 @@
|
|||
@import 'prism.scss';
|
||||
@import 'main.scss';
|
Loading…
Reference in New Issue