FlightGear wiki:Instant-Refs: Difference between revisions

Jump to navigation Jump to search
1) Simplify some regexes, 2) Change code blocks from <tt> to <pre>, 3) Underscore replacement 4) Update example
(1) Simplify some regexes, 2) Change code blocks from <tt> to <pre>, 3) Underscore replacement 4) Update example)
Line 23: Line 23:
For more info, I suggest to check out:<br/>
For more info, I suggest to check out:<br/>
<br/>
<br/>
[[MapStructure#Porting_the_map_dialog]]<br/>
[[MapStructure#Porting the map dialog]]<br/>
[[File:MapStructureDialog.png|250px]]  
[[File:MapStructureDialog.png|250px]]  
   |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212558#p212558
   |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212558#p212558
Line 57: Line 57:


== Feature requests & ideas ==
== Feature requests & ideas ==
* when converting links to internal wiki links, remove underscores
* Internet Explorer stuff can be removed.  It seems that Internet Explorer plugins are implemented completely differently. {{Not done}}
* Internet Explorer stuff can be removed.  It seems that Internet Explorer plugins are implemented completely differently. {{Not done}}
* GET-encoded sid arguments should be stripped from forum URLs. {{Not done}}
* GET-encoded SID arguments should be stripped from forum URLs. {{Not done}}
* Links to repositories should be converted to use wiki templates. {{Not done}}
* Links to repositories should be converted to use wiki templates. {{Not done}}
* The {{Abbr|regexes|regular expressions}} used may fail if the HTML DOM of the source changes (e.g., phpBB/theme update)
* The {{Abbr|regexes|regular expressions}} used may fail if the HTML DOM of the source changes (e.g., phpBB/theme update)
Line 75: Line 74:
// @description Automatically converts mailing list and forum quotes into Mediawiki markup.
// @description Automatically converts mailing list and forum quotes into Mediawiki markup.
// @namespace  http://wiki.flightgear.org/
// @namespace  http://wiki.flightgear.org/
// @version    0.14
// @version    0.15
// @icon      http://wiki.flightgear.org/images/6/62/FlightGear_logo.png
// @icon      http://wiki.flightgear.org/images/6/62/FlightGear_logo.png
// @require    http://code.jquery.com/jquery-1.11.1.min.js
// @require    http://code.jquery.com/jquery-1.11.1.min.js
Line 205: Line 204:
function newline2br() {
function newline2br() {
     return function(text) {
     return function(text) {
         return text.replace(/\n/g,"<br/>\n");
         return text.replace(/\n/g, "<br/>\n");
     };
     };
}
}
Line 212: Line 211:
function removeComments() {
function removeComments() {
     return function(html) {
     return function(html) {
         return html.replace(/<!--.*?-->/g,"");
         return html.replace(/<!--.*?-->/g, "");
     };
     };
}
}
Line 221: Line 220:
         // first tries internal links, firstmost links to images (File:xxx), because
         // first tries internal links, firstmost links to images (File:xxx), because
         // they need special treatment, or they get displayed
         // they need special treatment, or they get displayed
         html = html.replace(/<a[^(?:href)]*href="https?:\/\/wiki.flightgear.org\/(File:.*?)".*?>(.*?)<\/a>/g, "[[:$1|$2]]");
         html = html.replace(/<a.*?href="http:\/\/wiki\.flightgear\.org\/(File:.*?)".*?>(.*?)<\/a>/g, "[[:$1|$2]]");
         // automatic links to the wiki (we don't use the displayed text)
         // automatic links to the wiki (we don't use the displayed text)
         html = html.replace(/<a[^(?:href)]*href="https?:\/\/wiki.flightgear.org\/(.*?)".*?>https?:\/\/wiki.flightgear.org.*?<\/a>/g, "[[$1]]");
         html = underscoreToSpace(html.replace(/<a.*?href="http:\/\/wiki\.flightgear\.org\/(.*?)".*?>http:\/\/wiki\.flightgear\.org\/.*?<\/a>/g, "[[$1]]"));
         // links to the wiki with custom text (we preserve it)
         // links to the wiki with custom text (we preserve it)
         html = html.replace(/<a[^(?:href)]*href="https?:\/\/wiki.flightgear.org\/(.*?)".*?>(.*?)<\/a>/g, "[[$1|$2]]");
         html = html.replace(/<a.*?href="http:\/\/wiki\.flightgear\.org\/(.*?)".*?>(.*?)<\/a>/g, "[[$1|$2]]");
   
   
         // then the others
         // then the others
         html = html.replace(/<a[^(?:href)]*href="(.*?)".*?>(.*?)<\/a>/g, "[$1 $2]");
         html = html.replace(/<a.*?href="(.*?)".*?>(.*?)<\/a>/g, "[$1 $2]");
         return html;
         return html;
     };
     };
Line 237: Line 236:
function img2link() {
function img2link() {
     return function(html) {
     return function(html) {
         html = html.replace(/<img.*?src="https?:\/\/wiki.flightgear.org\/images\/.*?\/(?:[0-9]+px-)?([^\/]*?)".*?>/g, "[[File:$1|250px]]");
         html = html.replace(/<img.*?src="http:\/\/wiki\.flightgear\.org\/images\/.*?\/.*?\/(.*?)".*?>/g, "[[File:$1|250px]]");
         return html.replace(/<img.*?src="(.*?)".*?>/g, "(see the [$1 linked image])");
         return html.replace(/<img.*?src="(.*?)".*?>/g, "(see the [$1 linked image])");
     };
     };
Line 268: Line 267:
function phpBB_code2syntaxhighlight() {
function phpBB_code2syntaxhighlight() {
     return function(bbhtml) {
     return function(bbhtml) {
         return bbhtml.replace(/<dl.*?><dt>.*?<\/dt><dd><code>(.*?)<\/code><\/dd><\/dl>/g, "<tt>\n$1\n</tt>");
         return bbhtml.replace(/<dl.*?><dt>.*?<\/dt><dd><code>(.*?)<\/code><\/dd><\/dl>/g, '<pre style="white-space:pre-wrap">\n$1\n</pre>');
     };
     };
}
}
Line 442: Line 441:
var date = new Date(text);
var date = new Date(text);
return MONTHS[date.getMonth()] + " " + date.getDate() + ordAdj(date.getDate()) + ", " + date.getFullYear();
return MONTHS[date.getMonth()] + " " + date.getDate() + ordAdj(date.getDate()) + ", " + date.getFullYear();
}
function underscoreToSpace(str){
return str.replace(/_/g, " ");
}
}
   
   

Navigation menu