public void Does_transform_escaped_html_start_tags() { var markdownText = @"#### Showing Results 1 - 5 ^<div id=""searchresults""> ### Markdown > [About Docs](http://path.com/to/about) ^</div> Text".NormalizeNewLines(); var expectedHtml = @"<h4>Showing Results 1 - 5</h4> <div id=""searchresults""> <h3>Markdown > <a href=""http://path.com/to/about"">About Docs</a></h3> </div> <p>Text</p> ".NormalizeNewLines(); var textBlock = new TextBlock(""); var page = new MarkdownPage { Markdown = new MarkdownFormat() }; textBlock.DoFirstRun(new PageContext(page, null, true)); var html = textBlock.TransformHtml(markdownText); Console.WriteLine(html); Assert.That(html, Is.EqualTo(expectedHtml)); }
/// <summary> /// Creates the template blocks. /// </summary> /// <param name="content">The content.</param> /// <param name="statementBlocks">The statement blocks.</param> /// <returns></returns> public static List<TemplateBlock> CreateTemplateBlocks(this string content, List<StatementExprBlock> statementBlocks) { var blocks = new List<TemplateBlock>(); if (content.IsNullOrEmpty()) return blocks; int pos; var lastPos = 0; while ((pos = content.IndexOf('@', lastPos)) != -1) { var contentBlock = content.Substring(lastPos, pos - lastPos); var prevTextBlock = new TextBlock(contentBlock); blocks.Add(prevTextBlock); pos++; //@ if (content[pos] == '@') { prevTextBlock.Content += "@"; pos++; } else if (content[pos] == StatementPlaceholderChar) { pos++; //^ var index = content.GetNextAlphaNumericExpr(ref pos); int statementNo; if (int.TryParse(index, out statementNo)) { var statementIndex = statementNo - 1; if (statementIndex >= statementBlocks.Count) throw new ArgumentOutOfRangeException( "Expected < " + statementBlocks.Count + " but was " + statementIndex); var statement = statementBlocks[statementIndex]; blocks.Add(statement); } //Strip everything but @^1 in <p>@^1</p>\n prevTextBlock.RemoveIfEndingWith(UnwantedPrefix); content.SkipIfNextIs(ref pos, UnwantedSuffix); content.SkipIfNextIs(ref pos, "\r"); content.SkipIfNextIs(ref pos, "\n"); } else { //ignore email addresses with @ in it var charBeforeAtSymbol = content.SafePeekAt(pos - 3); if (!charBeforeAtSymbol.IsAlphaNumeric()) { var memberExpr = content.GetNextMemberExpr(ref pos); if (memberExpr != null) { blocks.Add(new MemberExprBlock(memberExpr)); } } else { prevTextBlock.Content += "@"; } } lastPos = pos; } if (lastPos != content.Length) { var lastBlock = lastPos == 0 ? content : content.Substring(lastPos); blocks.Add(new TextBlock(lastBlock)); } return blocks; }