locopablo / markdownsharp

Automatically exported from code.google.com/p/markdownsharp
0 stars 0 forks source link

Add option to avoid Paragraph around single element #59

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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: