KyleRombach / wmd-new

Automatically exported from code.google.com/p/wmd-new
0 stars 0 forks source link

Header only toggles between h1 and h2 #6

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Using the header button toggles between no formatting, h1 and h2 then
back to no formatting

What is the expected output? What do you see instead?
I would expect the headnigs to toggle to at least h3 (or at least be
configurable)

What version of the product are you using? On what operating system?
Latest version on Vista, Firefox

Please provide any additional information below.
This is maybe not a bug, possibly a feature request.  Sorry if this is in
the wrong place.

Original issue reported on code.google.com by theh...@gmail.com on 16 Jul 2009 at 2:40

GoogleCodeExporter commented 8 years ago

-- function to toggle headers from h1 to h6 + create + remove-------    

command.doHeading = function(chunk, postProcessing, useDefaultText){

        //chunk.trimWhitespace();
        // Remove leading/trailing whitespace and reduce internal spaces to single spaces.
        var chunkOrigSel = chunk.selection;
        chunk.selection = chunk.selection.replace(/\s+/g, " ");
        chunk.selection = chunk.selection.replace(/(^\s+|\s+$)/g, "");
        var firstChr = chunk.selection.substring(0, 1);
        // If we clicked the button with no selected text, we just
        // make a level 2 hash header around some default text.
        if(!chunk.selection){
            chunk.findTags(/[^\n]/, /[^\n]/);       
            if(/[^\n]/.test(chunk.startTag))
                chunk.startTag += "\n\n## ";
            else chunk.startTag = "## ";
            chunk.selection = "Heading";
            if(/[^\n]/.test(chunk.startTag))
                chunk.endTag = " ##\n\n" + chunk.endTag;
            else chunk.endTag = " ##";
            return;
        }

        var headerLevel = 0;        // The existing header level of the selected text.

        // Remove any existing hash heading markdown and save the header level.
        chunk.findTags(/#+[ ]*/, /[ ]*#+/);
        if(/#+/.test(chunk.startTag)){
            headerLevel = re.lastMatch.length;
        }
        chunk.startTag = chunk.endTag = "";

        var addNewLine = "";
        if (headerLevel == 0)
        {
            chunk.findTags(/[^\n]/, null);      
            if(/[^\n]/.test(chunk.startTag)){
                addNewLine = chunk.startTag.substring(0,1);
            }
            chunk.startTag = chunk.endTag = "";
        }

        var removeNewLines = false;
        if (headerLevel < 6) headerLevel++;
        else if (headerLevel == 6) 
        {
            headerLevel = 0;
            removeNewLines = true;
        }

        var headerChar = "#";
        var len = headerLevel;
        if (headerLevel > 0)
        {
            if (headerLevel == 1 && addNewLine != "") 
            {
                chunk.startTag = addNewLine.replace(/\s+/g, "") + "\n\n";
            }
            chunk.endTag = " ";
            while(len--){
                chunk.endTag += headerChar;
                chunk.startTag += headerChar;
            }
            chunk.startTag += " ";

            if (headerLevel == 1) 
            {
                chunk.endTag += "\n\n";
                chunk.selection = firstChr + chunk.selection;
            }

        }
        else
        {
            chunk.findTags(/[\n]+/, /[\n]+/);       
            if(/[\n]+/.test(chunk.startTag)){
                chunk.startTag = "";
            }
            if(/[\n]+/.test(chunk.endTag)){
                chunk.endTag = "";
            }
            chunk.selection = chunkOrigSel;     
            chunk.findTags(/[^\n]/, /[^\n]/);       
            if(/[^\n]/.test(chunk.startTag)){
                chunk.startTag = chunk.startTag.substring(0,1) + " ";
                chunk.startTag = chunk.startTag.replace(/\s+/g, " ");
            }
            if(/[^\n]/.test(chunk.endTag)){
                chunk.endTag = " " + chunk.endTag.substring(0,1);
                chunk.endTag = chunk.endTag.replace(/\s+/g, " ");
            }
            chunk.selection = chunkOrigSel;         
        }

    };  

Original comment by uli.h...@gmail.com on 10 Oct 2009 at 4:34