// <nowiki>
(function () {
function replaceAll(matches, text, replacementFunction) {
Array.from(matches).forEach(function (match) {
text = text.replace(match, replacementFunction(match));
});
return text;
}
function escapeHtml(s) {
return s.replace(/&/g, "&").replace(/"/g, """)
.replace(/'/g, "'").replace(/</g, "<");
}
/**
* Parse les sources JS ou Lua pour ajouter des liens vers les URL ou des pages wiki.
*/
function parseScript() {
var e = $(this);
var s = e.text();
if (!s.match(/{\d+}/)) {
var uri = new URL(window.location.href);
var url = uri.protocol + "//" + uri.host + "https://dictious.com/fr/";
// Escape HTML tags
var text = escapeHtml(s);
var match;
// Namespaced pages
if (match = text.match(/^('|")(+?:.*?)\1$/)) {
var page = match;
var quotes = match;
// noinspection HtmlUnknownTarget
text = '{0}<a style="text-decoration:underline;" href="{1}{2}">{2}</a>{0}'
.format(quotes, url, page);
e.html(text.replace(match, text));
}
else {
var matches;
// URLs
if (matches = text.matchAll(/((?:https?:)?\/\/+?\.\w+\/+?)(?=\s|'|"|$)/g)) {
text = replaceAll(matches, text, function (match) {
var page = match;
// noinspection HtmlUnknownTarget
return '<a class="external" style="text-decoration:underline;" href="{0}" target="_blank">{0}</a>'
.format(page);
});
}
// Links
if (matches = text.matchAll(/\])/g)) {
text = replaceAll(matches, text, function (match) {
var page = match.trim();
// noinspection HtmlUnknownTarget
return '[[<a style="text-decoration:underline;" href="{0}{1}">{1}</a>'
.format(url, page);
});
}
// Invoked modules
if (matches = text.matchAll(/{{#invoke:(+?)(?=\||}})/g)) {
text = replaceAll(matches, text, function (match) {
var modulePage = match.trim();
// noinspection HtmlUnknownTarget
return '{{#invoke:<a style="text-decoration:underline;" href="{0}Module:{1}">{1}</a>'
.format(url, modulePage);
});
}
// Templates
if (matches = text.matchAll(/{{(+?)(?=\||}})/g)) {
text = replaceAll(matches, text, function (match) {
var templatePage = match.trim();
// noinspection HtmlUnknownTarget
return '{{<a style="text-decoration:underline;" href="{0}Modèle:{1}">{1}</a>'
.format(url, templatePage);
});
}
// Lua doc @param tags
if (matches = text.matchAll(/@param(\s+)((?:\w+|\.\.\.)+?)(\s+)((?:table|string|boolean|number|function|any|file|thread|void|nil|\||,)+?)(?=\s|$)/g)) {
text = replaceAll(matches, text, function (match) {
var paramName = match;
var ws1 = match;
var paramType = match;
var ws2 = match;
return '<span class="ct">@param</span>{0}<span class="cpn">{1}</span>{2}<span class="cpt">{3}</span>'
.format(paramName, ws1, paramType, ws2);
});
}
// Lua doc @return tag
if (matches = text.matchAll(/@(returns?)(\s+)((?:table|string|boolean|number|function|any|file|thread|void|nil|\||,)+?)(?=\s|$)/g)) {
text = replaceAll(matches, text, function (match) {
var tag = match;
var ws = match;
var type = match;
return '<span class="ct">@{0}</span>{1}<span class="cpt">{2}</span>'
.format(tag, ws, type);
});
}
// Doc comments
if (match = text.match(/^(\s*)---(.*)$/)) {
var ws = match;
var comment = match;
text = '{0}<span class="cd">---{1}</span>'.format(ws, comment);
}
if (matches || match) {
e.html(text);
}
}
}
}
$(".mw-highlight .s1").each(parseScript);
$(".mw-highlight .s2").each(parseScript);
$(".mw-highlight .sb").each(parseScript);
$(".mw-highlight .sx").each(parseScript);
$(".mw-highlight .c1").each(parseScript);
$(".mw-highlight .cm").each(parseScript);
})();
// </nowiki>