public void warningbox_token_with_nowiki_adds_pre_and_renders_token_html() { // Arrange..make sure expectedHtml uses \n and not \r\n string expectedHtml = @"<p><div class=""alert alert-warning"">ENTER YOUR CONTENT HERE <pre>here is my C#code </pre> </p> <p></div><br style=""clear:both""/> </p>"; expectedHtml = expectedHtml.Replace("\r\n", "\n"); // fix line ending issues // Act ; string actualHtml = _markupConverter.ToHtml(@"@@warningbox:ENTER YOUR CONTENT HERE here is my C#code @@"); Console.WriteLine(actualHtml); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Code_Blocks_Should_Allow_Quotes() { // Issue #82 // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); string markdownText = "Here is some `// code with a 'quote' in it and another \"quote\"`\n\n" + " var x = \"some tabbed code\";\n\n"; // 2 line breaks followed by 4 spaces (tab stop) at the start indicates a code block string expectedHtml = "<p>Here is some <code>// code with a 'quote' in it and another \"quote\"</code></p>\n\n" + "<pre><code>var x = \"some tabbed code\";\n" + "</code></pre>\n"; // Act string actualHtml = converter.ToHtml(markdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public override string BeforeParse(string markupText) { // Check for the jumbotron token if (COMPILED_REGEX.IsMatch(markupText)) { MatchCollection matches = COMPILED_REGEX.Matches(markupText); // All instances of the token if (matches.Count > 0) { Match match = matches[0]; // Grab the markdown after the [[[jumbotron=..]]] and parse it, // and put it back in. string innerMarkDown = match.Groups["inner"].Value; string html = _converter.ToHtml(innerMarkDown); // _preContainerHtml is returned later and it contains the HTML that lives // outside the container, that this plugin provides. _preContainerHtml = HTMLTEMPLATE.Replace("${inner}", html); } // Remove the token from the markdown/creole markupText = Regex.Replace(markupText, REGEX_STRING, "", COMPILED_REGEX.Options); } return(markupText); }
public void internal_links_should_resolve_with_id() { // Bug #87 // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; var settingsRepository = new SettingsRepositoryMock(); settingsRepository.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; PageRepositoryMock pageRepositoryStub = new PageRepositoryMock(); pageRepositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; UrlResolverMock resolver = new UrlResolverMock(); resolver.InternalUrl = "blah"; MarkupConverter converter = new MarkupConverter(settings, settingsRepository, pageRepositoryStub, _pluginFactory); converter.UrlResolver = resolver; string markdownText = "[Link](My-first-page)"; string invalidMarkdownText = "[Link](My first page)"; // Act string expectedHtml = "<p><a href=\"blah\">Link</a></p>\n"; string expectedInvalidLinkHtml = "<p>[Link](My first page)</p>\n"; string actualHtml = converter.ToHtml(markdownText); string actualHtmlInvalidLink = converter.ToHtml(invalidMarkdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); Assert.That(actualHtmlInvalidLink, Is.EqualTo(expectedInvalidLinkHtml)); }
public PageViewModel(PageContent pageContent, MarkupConverter converter) { if (pageContent == null) { throw new ArgumentNullException("pageContent"); } if (pageContent.Page == null) { throw new ArgumentNullException("pageContent.Page"); } if (converter == null) { throw new ArgumentNullException("converter"); } RoadkillContext = ObjectFactory.GetInstance <IUserContext>(); Id = pageContent.Page.Id; Title = pageContent.Page.Title; PreviousTitle = pageContent.Page.Title; CreatedBy = pageContent.Page.CreatedBy; CreatedOn = pageContent.Page.CreatedOn; IsLocked = pageContent.Page.IsLocked; ModifiedBy = pageContent.Page.ModifiedBy; ModifiedOn = pageContent.Page.ModifiedOn; RawTags = pageContent.Page.Tags; Content = pageContent.Text; VersionNumber = pageContent.VersionNumber; ProjectStart = pageContent.Page.ProjectStart; ProjectEnd = pageContent.ProjectEnd; ProjectEstimatedTime = pageContent.ProjectEstimatedTime; ProjectStatus = pageContent.ProjectStatus; ProjectLanguage = pageContent.ProjectLanguage; orgID = pageContent.orgID; Rel = RelToUserToPage(Id); Relationships = GetRelationships(); PageHtml pageHtml = converter.ToHtml(pageContent.Text); ContentAsHtml = pageHtml.Html; IsCacheable = pageHtml.IsCacheable; PluginHeadHtml = pageHtml.HeadHtml; PluginFooterHtml = pageHtml.FooterHtml; PluginPreContainer = pageHtml.PreContainerHtml; PluginPostContainer = pageHtml.PostContainerHtml; CreatedOn = DateTime.SpecifyKind(CreatedOn, DateTimeKind.Utc); ModifiedOn = DateTime.SpecifyKind(ModifiedOn, DateTimeKind.Utc); AllTags = new List <TagViewModel>(); }
public void WarningBox_Token_With_NoWiki_Adds_Pre_And_Renders_Token_HTML() { // Arrange string expectedHtml = @"<p><div class=""alert alert-warning"">ENTER YOUR CONTENT HERE <pre>here is my C#code </pre> </p> <p></div><br style=""clear:both""/> </p>"; // Act string actualHtml = _markupConverter.ToHtml(@"@@warningbox:ENTER YOUR CONTENT HERE {{{ here is my C#code }}} @@"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public ActionResult GetPreview(string id) { PageHtml pagehtml = ""; if (!string.IsNullOrEmpty(id)) { MarkupConverter converter = _pageService.GetMarkupConverter(); pagehtml = converter.ToHtml(id); } return(JavaScript(pagehtml.Html)); }
public void Links_Starting_With_Https_Or_Hash_Are_Not_Rewritten_As_Internal() { // Arrange _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"#myanchortag\">hello world</a> <a href=\"https://www.google.com\">google</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[#myanchortag|hello world]] [[https://www.google.com|google]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Links_With_Dashes_Or_23_Are_Rewritten_And_Not_Parsed_As_Encoded_Hashes() { // Arrange _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"#myanchortag\">hello world</a> <a href=\"https://www.google.com/some-page-23\">google</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[#myanchortag|hello world]] [[https://www.google.com/some-page-23|google]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Links_Starting_With_Http_Www_Mailto_Tag_Are_No_Rewritten_As_Internal() { // Arrange _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"http://www.blah.com\">link1</a> <a href=\"www.blah.com\">link2</a> <a href=\"mailto:spam@gmail.com\">spam</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.blah.com|link1]] [[www.blah.com|link2]] [[mailto:[email protected]|spam]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Links_Starting_With_SpecialColon_Should_Resolve_As_Full_SpecialPage() { // Arrange _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/Special:Foo\">My special page</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[Special:Foo|My special page]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Links_Starting_With_AttachmentColon_Should_Resolve_As_Attachment_Paths() { // Arrange _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"/Attachments/my/folder/image1.jpg\">hello world</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[attachment:/my/folder/image1.jpg|hello world]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void links_to_named_anchors_should_not_have_external_css_class() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"#myanchortag\">hello world</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[#myanchortag|hello world]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void should_allow_style_tags() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Markdown"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><b style=\"color: black\"></b></p>\n"; // Act string actualHtml = _markupConverter.ToHtml("<b style='color:black'><script>alert('foo')</script></b>"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void links_starting_with_http_www_mailto_tag_are_no_rewritten_as_internal() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"http://www.blah.com/\" class=\"external-link\">link1</a> <a rel=\"nofollow\" href=\"www.blah.com\" class=\"external-link\">link2</a> <a rel=\"nofollow\" href=\"mailto:[email protected]\" class=\"external-link\">spam</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.blah.com|link1]] [[www.blah.com|link2]] [[mailto:[email protected]|spam]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void links_starting_with_specialcolon_should_resolve_as_full_specialpage() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/Special:Foo\">My special page</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[Special:Foo|My special page]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void SpecialUrl_Link_Should_Not_Have_NoFollow_Attribute() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/Special:Random\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[Special:Random|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Links_To_Named_Anchors_Should_Not_Have_External_CSS_Class() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"#myanchortag\">hello world</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[#myanchortag|hello world]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Links_With_The_Word_Script_In_Url_Should_Not_Be_Cleaned() { // Issue #159 // Arrange _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.descriptionattribute.aspx\">ComponentModel.Description</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://msdn.microsoft.com/en-us/library/system.componentmodel.descriptionattribute.aspx|ComponentModel.Description]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void links_with_dashes_or_23_are_rewritten_and_not_parsed_as_encoded_hashes() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"#myanchortag\">hello world</a> <a rel=\"nofollow\" href=\"https://www.google.com/some-page-23\" class=\"external-link\">google</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[#myanchortag|hello world]] [[https://www.google.com/some-page-23|google]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Links_With_Angle_Brackets_And_Quotes_Should_Be_Encoded() { // Issue #159 // Arrange _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"http://www.google.com/">javascript:alert('hello')\">ComponentModel</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.google.com/\">javascript:alert('hello')|ComponentModel]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void attachment_link_should_not_have_nofollow_attribute() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/Attachments/folder/myfile.jpg\">Some link text</a> <a href=\"/Attachments/folder2/myfile.jpg\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[~/folder/myfile.jpg|Some link text]] [[attachment:/folder2/myfile.jpg|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void specialurl_link_should_not_have_nofollow_attribute() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/Special:Random\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[Special:Random|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Attachment_Link_Should_Not_Have_NoFollow_Attribute() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"/Attachments/folder/myfile.jpg\">Some link text</a> <a href=\"/Attachments/folder2/myfile.jpg\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[~/folder/myfile.jpg|Some link text]] [[attachment:/folder2/myfile.jpg|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void links_starting_with_attachmentcolon_should_resolve_as_attachment_paths() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/Attachments/my/folder/image1.jpg\">hello world</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[attachment:/my/folder/image1.jpg|hello world]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void links_starting_with_https_or_hash_are_not_rewritten_as_internal() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"#myanchortag\">hello world</a> <a rel=\"nofollow\" href=\"https://www.google.com\" class=\"external-link\">google</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[#myanchortag|hello world]] [[https://www.google.com|google]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
/// <summary> /// Gets a particular version of a page. /// </summary> /// <param name="id">The Guid ID for the version.</param> /// <returns>A <see cref="PageViewModel"/> as the model, which contains the HTML diff /// output inside the <see cref="PageViewModel.Content"/> property.</returns> public ActionResult Version(Guid id) { MarkupConverter converter = _pageService.GetMarkupConverter(); IList <PageViewModel> bothVersions = _historyService.CompareVersions(id).ToList(); string diffHtml = ""; if (bothVersions[1] != null) { string oldVersion = converter.ToHtml(bothVersions[1].Content).Html; string newVersion = converter.ToHtml(bothVersions[0].Content).Html; HtmlDiff diff = new HtmlDiff(oldVersion, newVersion); diffHtml = diff.Build(); } else { diffHtml = converter.ToHtml(bothVersions[0].Content).Html; } PageViewModel model = bothVersions[0]; model.Content = diffHtml; return(View(model)); }
/// <summary> /// Converts the page summary to a lucene Document with the relevant searchable fields. /// </summary> internal string GetContentSummary(PageViewModel model) { // Turn the contents into HTML, then strip the tags for the mini summary. This needs some works string modelHtml = model.Content; modelHtml = _markupConverter.ToHtml(modelHtml); modelHtml = _removeTagsRegex.Replace(modelHtml, ""); if (modelHtml.Length > 150) { modelHtml = modelHtml.Substring(0, 149); } return(modelHtml); }
public void links_with_the_word_script_in_url_should_not_be_cleaned() { // Issue #159 // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.descriptionattribute.aspx\" class=\"external-link\">ComponentModel.Description</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://msdn.microsoft.com/en-us/library/system.componentmodel.descriptionattribute.aspx|ComponentModel.Description]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void links_with_angle_brackets_and_quotes_should_be_encoded() { // Issue #159 // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"http://www.google.com/2%3Ejavascript:alert('hello')\" class=\"external-link\">ComponentModel</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.google.com/\">javascript:alert('hello')|ComponentModel]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }