_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

User:Omegatron/monobook.js/headingformattingfixer.js

In this article about User:Omegatron/monobook.js/headingformattingfixer.js we are going to delve into a topic that has sparked the interest of many people over time. User:Omegatron/monobook.js/headingformattingfixer.js is a topic that has been the subject of debate, research and reflection, and it is essential to understand its impact on our society. Over the years, User:Omegatron/monobook.js/headingformattingfixer.js has raised different opinions and positions, generating a rich exchange of ideas and perspectives. Through this article, we will explore the various aspects related to User:Omegatron/monobook.js/headingformattingfixer.js, from its origin to its relevance today. We hope that this reading is enriching and allows us to expand our knowledge about User:Omegatron/monobook.js/headingformattingfixer.js.
function headingfixer() {
    var txt = document.editform.wpTextbox1;

    // Format heading markup the way it is generated with the + tab
    // Note: the ? after the * is not redundant, see http://www.regular-expressions.info/repeat.html#lazy
    txt.value = txt.value.replace(/((^|\n)={2,})( |\t)*(.*?)( |\t)*(={2,})/g, '$1 $4 $6\n\n');

    // 1 blank line before the headings 
    // (this is super-kludgy because of the newlines conflicting when one heading is right after another)
    // (seems to work, though, for now.  some other day...)
    txt.value = txt.value.replace(/(\n+={2,}) (.*?) (={2,})/g, '\n\n$1 $2 $3');

    // Remove all extra newlines?
    txt.value = txt.value.replace(/(\n*){2,}/g, '\n\n');

    // One space after * and # lists, and after : and ;
    txt.value = txt.value.replace(/(^|\n)((\*|\#|\;|\:)+)\s*(\w|\[|\"|\'|\{\{)/g, '$1$2 $4');

    // Format External links and See also according to the Manual of Style
    txt.value = txt.value.replace(/\=\= external links? \=\=/ig, '== External links ==');
    txt.value = txt.value.replace(/\=\= see also \=\=/ig, '== See also ==');

    // Add a tag to the summary box
    var txt = document.editform.wpSummary;
    var summary = "]";
    if (txt.value.indexOf(summary) == -1) {
        if (txt.value.match(/?\s*$/)) {
            txt.value += " | ";
        }
        txt.value += summary;
    }

    // Press the diff button to check it
    if( typeof( autoDiffClick ) == 'undefined' || autoDiffClick === true ) {
      document.editform.wpDiff.click();
    }
}

$(function () {
    if(document.forms.editform) {
        mw.util.addPortletLink('p-cactions', 'javascript:headingfixer()', '_', 'ca-headingfixer', 'Fixes heading whitespace and deletes excess newlines', '-', '');
    }
});