This is an old revision of this page, as edited by Ohconfucius (talk | contribs) at 17:25, 24 April 2024 (tweak). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Revision as of 17:25, 24 April 2024 by Ohconfucius (talk | contribs) (tweak)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Ohconfucius/dashes. |
// --------------------------------------------------------------------------- // // What follows is a fork of ] (forked on 27 May 2020) // The editor who developed the script is no longer active, and changes to // Misplaced Pages have restricted who can edit the old script page. // // Please see the edit history for ] for attribution // // -------------------------------------------------------------------------- // Fix hyphens, dashes, and minus signs per ]. // // See talk page for instructions. // // The user can disable these conversions by putting "nodashes" somewhere // in the text — either temporarily or permanently. You can similarly add // "scores" if the score-detection heuristic doesn't trigger automatically. // // This tool can be used standalone until it is added to AutoEd and wikEd. // This module should follow unicodify.js if it is used. // Testing page is at ]. // Please report false positives on the talk page. function ifNotLink(str) { var pos = arguments; var string = arguments; // Add this condition to check if the position is within an HTML comment tag if (string.substring(pos - 4, pos + 1) === "<!--" && string.substring(pos, pos + 3) !== "-->") { return str; // Skip processing if within an HTML comment } var pat = /\]*$|\{\{*$|<\/?*$|+$|<*$|#\w*expr:.*$/i; if (string.substring(pos - 260, pos + 1).search(pat) >= 0) return str; // it's a link, so don't change it var pat2 = /\{\{(main|see|detail|excerpt|about|for\b|other|redir|conv|coor|sort|anchor|Israel populations|ISBN|DNB(?: ite|)|ite DNB)*$/i; if (string.substring(pos - 260, pos + 1).search(pat2) >= 0) return str; // likely templates with page-name or neg params var pat3 = /\|\s*(CAS_number)\s*=\s*/i; if (string.substring(pos - 260, pos + 1).search(pat3) >= 0) return str; // drugbox CAS_number var pat4 = /\|\s*(doi|elevation|filename|isbn)\s*=\s*/i; if (string.substring(pos - 260, pos + 1).search(pat4) >= 0) return str; // doi or isbn (or elevation parameter in Template:Infobox German location which can contain range marked using hyphen) var m = string.slice(pos).search(/<\/?(math|pre|code|tt|source|syntaxhighlight|gallery)\b/i); if (m >= 0 && string.charAt(pos + m + 1) == '/') return str; // don't break a <math> equation, or source code m = string.slice(pos).search(/\{\{*raph:Chart\b/i); if (m >= 0) return str; // don't break a Graph:Chart if (string.slice(pos).search(/^<>\n]*\.({3,4}\s*|jpg|png|svg)|^.*hyphen/i) >= 0) return str; // it's a file name parameter, or <!--sic hyphen--> if (str.search(/\b/) >= 0) return str.replace(//, "−"); // minus sign else return str.replace(/--+\b/g, "—").replace(/+/g, "–"); // dash }