User:Aplucas0703/common.js

function formatReferences(text) { // Find all references or series of references that come directly before a comma or period. var matches = text.match(/(?<=\w)\[(? [^\]]+\])(?=\,|\.)/g);

// For each match, move the references after the comma or period. for (var i = 0; i < matches.length; i++) { var reference = matches[i].match(/\[(? [^\]]+\])/)[0];   text = text.replace(matches[i], reference); }

// Replace all smart quotes with straight quotes. text = text.replace(/“|”/g, '"'); text = text.replace(/‘|’/g, "'");

// Move periods or commas that come before a quotation mark to come after the quotation mark. text = text.replace(/(?<=\s)([,.])(?=\s)/g, "$1");

return text; }