User:Nardog/ExpandContractions
Warning: You take full responsibility for any action you perform using ExpandContractions. You must read and understand Wikipedia policies and use this tool within these policies, or risk being blocked from editing. |
Description | Expands contractions |
---|---|
Updated | October 9, 2024 (50 days ago) |
Browsers | Chrome, Firefox, etc. |
Source | User:Nardog/ExpandContractions.js |
This script adds a button to the sidebar that expands contractions when editing in source mode (not 2017 editor). Specifically, it replaces
- "it's" etc. with "... is" or "... has"
- "it'd" etc. with "... would" or "... had"
- "'re" with " are"
- "'ve" with " have"
- "'ll" with " will"
- "can't" with "cannot"
- "won't" with "will not"
- "n't" with " not"
It will not replace "I'm", "I'd", or "ain't" because they don't typically appear in encyclopedic prose (if they do, the contractions are likely the least of the article's problems). "'ll" is assumed to be short for "will" because who uses "shall" anymore—certainly not someone who leaves contractions in.
It does its best to distinguish between "is" and "has" for "'s" and between "would" and "had" for "'d", but this is not perfect so you'll be reminded to review the result if the replacements include "'s" or "'d".
Links, references, quotes, poems, hatnotes, comments, headings, etc. are excluded from replacements, but don't rely too much on it as it might still replace contractions where it shouldn't, e.g. a template parameter for a filename. Italic and bold text is also excluded because it tends to be legitimate titles, aliases, etc. Anything after a heading named "References", "Sources", "Bibliography", "Further reading", or "External links" is also ignored.
If the script incorrectly replaces a contraction inside an inline quote (or misses one outside it), it likely means the paragraph has missing or misnested quotes (e.g. "... "..." ..." where it should be "... '...' ...").
Installation
[edit]Add the following to your common.js:
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Nardog/ExpandContractions.js&action=raw&ctype=text/javascript');
Or you may enable the script installer in Preferences → Gadgets and click "Install" in the infobox on this page.
Acknowledgements
[edit]This script relies on Pathoschild's TemplateScript framework. Its escape feature was buggy, however, so the script implements its own.