hey-red / Markdown

Open source C# implementation of Markdown processor, as featured on Stack Overflow.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add option to avoid Paragraph around single element

GoogleCodeExporter opened this issue · comments

What steps will reproduce the problem?
1. I need to have this block of text "test" to be translated into "test" and 
not in "<p>test</p>"

I've modified source code to obtain this, but i like to download this fix with 
your future fixes.

Also i will send you my fix so you can evaluate if this modification can be 
embedded in main project :-)


In few words: i have added WrapWithParagraph option and modified some code in 
FormParagraph method:
private string FormParagraphs(string text)
        {
            // split on two or more newlines
            string[] grafs = _newlinesMultiple.Split(_newlinesLeadingTrailing.Replace(text, ""));

            //20130426 - Michele Piccinini - if there is only one graf i don't wrap it with P tag
            if (!_WrapWithParagraph && grafs.Length == 1)
            {
                if (grafs[0].StartsWith("\x1A"))
                {
                    grafs[0] = _htmlBlocks[grafs[0]];
                }
            }
            else
            {
                for (int i = 0; i < grafs.Length; i++)
                {
                    if (grafs[i].StartsWith("\x1A"))
                    {
                        // unhashify HTML blocks
                        grafs[i] = _htmlBlocks[grafs[i]];
                    }
                    else
                    {
                        // do span level processing inside the block, then wrap result in <p> tags
                        grafs[i] = _leadingWhitespace.Replace(RunSpanGamut(grafs[i]), "<p>") + "</p>";
                    }
                }
            }
            return string.Join("\n\n", grafs);
        }

Original issue reported on code.google.com by mich...@jeminet.it on 26 Apr 2013 at 12:50

Attachments: