public void ConvertHtmlToXamlTest() { var markupConverter = new MarkupConverter(); const string html = @"<!DOCTYPE html> <html> <head> <title>Just testing...</title> </head> <body> <b>The world is ending.</b> <p>Yes, <strong>it is.</strong></p> <ul> <li>I'm</li> <li><em>a</em></li> <li>list!</li> </ul> </body> </html>"; var xaml = markupConverter.ConvertHtmlToXaml(html); Debug.WriteLine(xaml); }
public void should_not_render_toc_with_multiple_curlies() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); _markupConverter.UrlResolver = new UrlResolverMock(); string htmlFragment = "Give me a {{TOC}} and a {{{TOC}}} - the should not render a TOC"; string expected = @"<p>Give me a </p><div class=""floatnone""><div class=""image_frame""><img src=""/Attachments/TOC""></div></div> and a TOC - the should not render a TOC" + "\n<p></p>"; // Act string actualHtml = _markupConverter.ToHtml(htmlFragment); // Assert Assert.That(actualHtml, Is.EqualTo(expected), actualHtml); }
public void Parser_Should_Not_Be_Null_For_MarkupTypes() { // Arrange, act _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); // Assert Assert.NotNull(_markupConverter.Parser); _repository.SiteSettings.MarkupType = "Markdown"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); Assert.NotNull(_markupConverter.Parser); _repository.SiteSettings.MarkupType = "Mediawiki"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); Assert.NotNull(_markupConverter.Parser); }
public void Should_Not_Render_ToC_With_Multiple_Curlies() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); _markupConverter.UrlResolver = new UrlResolverMock(); string htmlFragment = "Give me a {{TOC}} and a {{{TOC}}} - the should not render a TOC"; string expected = @"<p>Give me a <div class=""floatnone""><div class=""image_frame""><img src=""/Attachments/TOC""></div></div> and a TOC - the should not render a TOC" + "\n</p>"; // Act string actualHtml = _markupConverter.ToHtml(htmlFragment); // Assert Assert.That(actualHtml, Is.EqualTo(expected)); }
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 void Should_Remove_Script_Link_Iframe_Frameset_Frame_Applet_Tags_From_Text() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string markdown = " some text <script type=\"text/html\">while(true)alert('lolz');</script>" + "<iframe src=\"google.com\"></iframe><frame>blah</frame> <applet code=\"MyApplet.class\" width=100 height=140></applet>" + "<frameset src='new.html'></frameset>"; string expectedHtml = "<p> some text blah \n</p>"; // Act string actualHtml = _markupConverter.ToHtml(markdown); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Html_Should_Not_Be_Sanitized_If_UseHtmlWhiteList_Setting_Is_False() { // Arrange _applicationSettings.UseHtmlWhiteList = false; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string htmlFragment = "<div onclick=\"javascript:alert('ouch');\">test</div>"; MarkupConverter converter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); // Act string actualHtml = converter.ToHtml(htmlFragment); // Assert string expectedHtml = "<p>" + htmlFragment + "\n</p>"; Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void External_Links_With_Anchor_Tag_Should_Retain_The_Anchor() { // Issue #172 // Arrange _repository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"http://www.google.com/?blah=xyz#myanchor\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.google.com/?blah=xyz#myanchor|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void html_should_not_be_sanitized_if_usehtmlwhitelist_setting_is_false() { // Arrange _applicationSettings.UseHtmlWhiteList = false; _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string htmlFragment = "<div onclick=\"javascript:alert('ouch');\">test</div>"; MarkupConverter converter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); // Act string actualHtml = converter.ToHtml(htmlFragment); // Assert string expectedHtml = "<p>" + htmlFragment + "\n</p>"; Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void internal_wiki_page_link_should_not_have_nofollow_attribute() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _pageRepository.AddNewPage(new Page() { Id = 1, Title = "foo-page" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/1/foo-page\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[foo-page|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Internal_Links_With_UrlEncoded_Anchor_Tag_Should_Retain_The_Anchor() { // Issue #172 // Arrange _repository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/1/foo%23myanchor\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[foo%23myanchor|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public PageService(ApplicationSettings settings, ISettingsRepository settingsRepository, IPageRepository pageRepository, SearchService searchService, PageHistoryService historyService, IUserContext context, ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache sitecache, IPluginFactory pluginFactory) { _searchService = searchService; _markupConverter = new MarkupConverter(settings, settingsRepository, pageRepository, pluginFactory); _historyService = historyService; _context = context; _listCache = listCache; _pageViewModelCache = pageViewModelCache; _siteCache = sitecache; _pluginFactory = pluginFactory; _markupLinkUpdater = new MarkupLinkUpdater(_markupConverter.Parser); ApplicationSettings = settings; SettingsRepository = settingsRepository; PageRepository = pageRepository; }
public void Internal_Wiki_Page_Link_Should_Not_Have_NoFollow_Attribute() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _repository.AddNewPage(new Page() { Id = 1, Title = "foo-page" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/1/foo-page\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[foo-page|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Internal_Links_With_Anchor_Tag_Should_Retain_The_Anchor_With_Markdown() { // Issue #172 // Arrange _repository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/1/foo#myanchor\">Some link text</a></p>\n"; // use /index/ as no routing exists // Act string actualHtml = _markupConverter.ToHtml("[Some link text](foo#myanchor)"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void internal_links_with_anchor_tag_should_retain_the_anchor_with_markdown() { // Issue #172 // Arrange _settingsRepository.SiteSettings.MarkupType = "Markdown"; _pageRepository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/1/foo#myanchor\">Some link text</a></p>\n"; // use /index/ as no routing exists // Act string actualHtml = _markupConverter.ToHtml("[Some link text](foo#myanchor)"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void external_links_with_anchor_tag_should_retain_the_anchor() { // Issue #172 // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _pageRepository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"http://www.google.com/?blah=xyz#myanchor\" class=\"external-link\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.google.com/?blah=xyz#myanchor|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
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"); } 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; 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>(); CustomWysiwygButtons = new List <WysiwygButtonViewModel>(); }
public PageService(ApplicationSettings settings, IRepository repository, SearchService searchService, PageHistoryService historyService, IUserContext context, ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache sitecache, IPluginFactory pluginFactory , Security.UserServiceBase UserService ) : base(settings, repository) { _searchService = searchService; _markupConverter = new MarkupConverter(settings, repository, pluginFactory); _historyService = historyService; _context = context; _listCache = listCache; _pageViewModelCache = pageViewModelCache; _siteCache = sitecache; _pluginFactory = pluginFactory; _markupLinkUpdater = new MarkupLinkUpdater(_markupConverter.Parser); _UserService = UserService; }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _repository = _container.Repository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _markupConverter = _container.MarkupConverter; _searchService = _container.SearchService; // Use a stub instead of the MocksAndStubsContainer's default _contextStub = new UserContextStub(); // Customise the page service so we can verify what was called _pageServiceMock = new Mock <IPageService>(); _pageServiceMock.Setup(x => x.GetMarkupConverter()).Returns(new MarkupConverter(_applicationSettings, _repository, _pluginFactory)); _pageServiceMock.Setup(x => x.GetById(It.IsAny <int>(), false)).Returns <int, bool>((int id, bool loadContent) => { Page page = _repository.GetPageById(id); return(new PageViewModel(page)); }); _pageServiceMock.Setup(x => x.GetById(It.IsAny <int>(), true)).Returns <int, bool>((int id, bool loadContent) => { PageContent content = _repository.GetLatestPageContent(id); if (content != null) { return(new PageViewModel(content, _markupConverter)); } else { return(null); } }); _pageServiceMock.Setup(x => x.FindByTag(It.IsAny <string>())); _pageService = _pageServiceMock.Object; _pagesController = new PagesController(_applicationSettings, _userService, _settingsService, _pageService, _searchService, _historyService, _contextStub); _mocksContainer = _pagesController.SetFakeControllerContext(); }
public void internal_links_with_urlencoded_anchor_tag_should_retain_the_anchor() { // Issue #172 // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _pageRepository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/1/foo%23myanchor\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[foo%23myanchor|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public PageView ToView(MarkupConverter converter = null, bool includeDetails = true) { return(new PageView { ApprovalStatus = ApprovalStatus, Id = PageId, CreatedBy = CreatedBy.DisplayName, CreatedOn = CreatedOn, EditingBy = EditingOn > DateTime.UtcNow.Subtract(Constants.EditingTimeout) ? (EditingBy?.DisplayName ?? string.Empty) : string.Empty, Files = new List <FileView>(), Html = includeDetails ? converter?.ToHtml(Text) ?? string.Empty : string.Empty, IsPublished = IsPublished, LastModified = DateTime.UtcNow.Subtract(CreatedOn).ToTimeAgo(), Pages = new List <PageReference>(), Tags = SplitTags(Tags), Text = includeDetails ? Text : string.Empty, Title = Title, TitleForLink = PageView.ConvertTitleForLink(Title) }); }
public void Single_Constructor_Argument_Should_Register_Default_Instances() { // Arrange DependencyManager container = new DependencyManager(new ApplicationSettings()); // Act container.Configure(); ApplicationSettings settings = ObjectFactory.TryGetInstance <ApplicationSettings>(); IRepository repository = ObjectFactory.GetInstance <IRepository>(); IUserContext context = ObjectFactory.GetInstance <IUserContext>(); IPageService pageService = ObjectFactory.GetInstance <IPageService>(); MarkupConverter markupConverter = ObjectFactory.GetInstance <MarkupConverter>(); CustomTokenParser tokenParser = ObjectFactory.GetInstance <CustomTokenParser>(); UserViewModel userModel = ObjectFactory.GetInstance <UserViewModel>(); SettingsViewModel settingsModel = ObjectFactory.GetInstance <SettingsViewModel>(); AttachmentRouteHandler routerHandler = ObjectFactory.GetInstance <AttachmentRouteHandler>(); UserServiceBase userManager = ObjectFactory.GetInstance <UserServiceBase>(); IPluginFactory pluginFactory = ObjectFactory.GetInstance <IPluginFactory>(); IWikiImporter wikiImporter = ObjectFactory.GetInstance <IWikiImporter>(); IAuthorizationProvider authProvider = ObjectFactory.GetInstance <IAuthorizationProvider>(); IActiveDirectoryProvider adProvider = ObjectFactory.GetInstance <IActiveDirectoryProvider>(); // Assert Assert.That(settings, Is.Not.Null); Assert.That(repository, Is.TypeOf <LightSpeedRepository>()); Assert.That(context, Is.TypeOf <UserContext>()); Assert.That(pageService, Is.TypeOf <PageService>()); Assert.That(markupConverter, Is.TypeOf <MarkupConverter>()); Assert.That(tokenParser, Is.TypeOf <CustomTokenParser>()); Assert.That(userModel, Is.TypeOf <UserViewModel>()); Assert.That(settingsModel, Is.TypeOf <SettingsViewModel>()); Assert.That(userManager, Is.TypeOf <FormsAuthUserService>()); Assert.That(pluginFactory, Is.TypeOf <PluginFactory>()); Assert.That(wikiImporter, Is.TypeOf <ScrewTurnImporter>()); Assert.That(authProvider, Is.TypeOf <AuthorizationProvider>()); #if !MONO Assert.That(adProvider, Is.TypeOf <ActiveDirectoryProvider>()); #endif }
public void Setup() { _pluginFactory = new PluginFactoryMock(); _pageRepository = new PageRepositoryMock(); _settingsRepository = new SettingsRepositoryMock(); _settingsRepository.SiteSettings = new SiteSettings(); _settingsRepository.SiteSettings.MarkupType = "Markdown"; _userContext = new UserContextStub(); _applicationSettings = new ApplicationSettings(); _applicationSettings.Installed = true; _cache = new CacheMock(); _siteCache = new SiteCache(_cache); _converter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); _menuParser = new MenuParser(_converter, _settingsRepository, _siteCache, _userContext); }
public void Should_Return_Different_Menu_Html_For_Admin_And_Editor_And_Guest_User() { // Arrange string menuMarkup = "My menu %newpage% %sitesettings%"; RepositoryMock repository = new RepositoryMock(); repository.SiteSettings = new SiteSettings(); repository.SiteSettings.MarkupType = "Markdown"; repository.SiteSettings.MenuMarkup = menuMarkup; UserContextStub userContext = new UserContextStub(); ApplicationSettings applicationSettings = new ApplicationSettings(); applicationSettings.Installed = true; CacheMock cache = new CacheMock(); SiteCache siteCache = new SiteCache(applicationSettings, cache); MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory); MenuParser parser = new MenuParser(converter, repository, siteCache, userContext); // Act userContext.IsLoggedIn = false; userContext.IsAdmin = false; string guestHtml = parser.GetMenu(); userContext.IsLoggedIn = true; userContext.IsAdmin = false; string editorHtml = parser.GetMenu(); userContext.IsLoggedIn = true; userContext.IsAdmin = true; string adminHtml = parser.GetMenu(); // Assert Assert.That(guestHtml, Is.EqualTo("My menu")); Assert.That(editorHtml, Is.EqualTo("My menu <a href=\"/pages/new\">New page</a>")); Assert.That(adminHtml, Is.EqualTo("My menu <a href=\"/pages/new\">New page</a> <a href=\"/settings\">Site settings</a>")); }
public void images_should_support_dimensions_and_titles() { // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; PageRepositoryMock pageRepositoryStub = new PageRepositoryMock(); pageRepositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); var settingsRepository = new SettingsRepositoryMock(); settingsRepository.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; MarkupConverter converter = new MarkupConverter(settings, settingsRepository, pageRepositoryStub, _pluginFactory); string markdownText = "Here is an image with a title:![Image](/Image1.png \"Image\") \n\n" + "And another with equal dimensions ![Square](/Image1.png \"Square\" =250x) \n\n" + "And this one is a rectangle ![Rectangle](/Image1.png \"Rectangle\" =250x350)"; string expectedHtml = "<p>Here is an image with a title:<img src=\"/Attachments/Image1.png\" class=\"img-responsive\" border=\"0\" alt=\"Image\" width=\"\" height=\"\" title=\"Image\" /> </p>\n\n" + "<p>And another with equal dimensions <img src=\"/Attachments/Image1.png\" class=\"img-responsive\" border=\"0\" alt=\"Square\" width=\"250px\" height=\"\" title=\"Square\" /> </p>\n\n" + "<p>And this one is a rectangle <img src=\"/Attachments/Image1.png\" class=\"img-responsive\" border=\"0\" alt=\"Rectangle\" width=\"250px\" height=\"350px\" title=\"Rectangle\" /></p>\n"; // Act string actualHtml = converter.ToHtml(markdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void code_blocks_should_allow_quotes() { // Issue #82 // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; PageRepositoryMock pageRepositoryStub = new PageRepositoryMock(); pageRepositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); var settingsRepository = new SettingsRepositoryMock(); settingsRepository.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; MarkupConverter converter = new MarkupConverter(settings, settingsRepository, pageRepositoryStub, _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 void ImageParsed_Should_Convert_To_Absolute_Path() { // Arrange UrlResolverMock resolver = new UrlResolverMock(); resolver.AbsolutePathSuffix = "123"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); _markupConverter.UrlResolver = resolver; // Act bool wasCalled = false; _markupConverter.Parser.ImageParsed += (object sender, ImageEventArgs e) => { wasCalled = (e.Src == "/Attachments/DSC001.jpg123"); }; _markupConverter.ToHtml("![Image title](/DSC001.jpg)"); // Assert Assert.True(wasCalled, "ImageParsed.ImageEventArgs.Src did not match."); }
public ScribeService(IScribeDatabase database, AccountService accountService, ISearchService searchService, User user) { _database = database; _accountService = accountService; _searchService = searchService; _siteSettings = SiteSettings.Load(database); _user = user; Converter = new MarkupConverter(); Converter.ImagedParsed += title => _database.Files.Where(x => x.Name == title).Select(x => new FileView { Id = x.Id, Name = x.Name }).FirstOrDefault(); Converter.LinkParsed += (title, title2) => { return(GetCurrentPagesQuery().Where(x => x.Title == title || x.Title == title2).Select(x => new PageView { Id = x.PageId, Title = x.Title }).FirstOrDefault() ?? GetCurrentPagesQuery().Where(x => "Page/" + x.PageId == title || x.PageId.ToString() == title).Select(x => new PageView { Id = x.PageId, Title = x.Title }).FirstOrDefault()); }; }
static void Main(string[] args) { string html = @"<h2>This is <em>my</em> title</h2> <p>Then I have <b>a paragraph</b></p> <p>Then I have <b>another para!</b></p> Some random <i>text</i>!! <p>Then I have <b>another para!</b></p> <ol> <li><b>list</b> item1</li> <li>list item2</li> <li>list item3</li> <li>list item4</li> <li> <ul> <li>sub item1</li> <li>sub item2</li> <li>sub item3</li> <li>sub item4</li> </ul></li> <li>list item5</li> </ol><ul> <li>list item1</li> <li>list item2</li> <li>list item3</li> <li>list item4</li> </ul> <table>" + " <tr><th colspan\"2\">title</th></tr>" + " <tr><td colspan\"omg\">cell</td><td colspan\"omg\">cell2</td></tr>" + " <tr><td>cell3</td><td>cell4</td></tr>" + " <tr><td>cell5</td><td>cell6</td></tr>" + "</table>" + "<img src='/contentimg.png' /> " + "<p>This is some <strong>sample text</strong>. You are using <a href=\"http://www.fckeditor.net/\">FCKeditor</a>. this is some text</p>" + "<p>yeah omg whoa <span style=\"background-color: rgb(255, 0, 0);\">and </span>some <span style=\"color: rgb(153, 204, 0);\">color</span>!!</p>"; System.Console.Write(MarkupConverter.HTML2Textile(html)); }
public void Should_Cache_Menu_Html_For_Admin_And_Editor_And_Guest_User() { // Arrange string menuMarkup = "My menu %newpage% %sitesettings%"; RepositoryMock repository = new RepositoryMock(); repository.SiteSettings = new SiteSettings(); repository.SiteSettings.MarkupType = "Markdown"; repository.SiteSettings.MenuMarkup = menuMarkup; UserContextStub userContext = new UserContextStub(); ApplicationSettings applicationSettings = new ApplicationSettings(); applicationSettings.Installed = true; CacheMock cache = new CacheMock(); SiteCache siteCache = new SiteCache(applicationSettings, cache); MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory); MenuParser parser = new MenuParser(converter, repository, siteCache, userContext); // Act userContext.IsLoggedIn = false; userContext.IsAdmin = false; parser.GetMenu(); userContext.IsLoggedIn = true; userContext.IsAdmin = false; parser.GetMenu(); userContext.IsLoggedIn = true; userContext.IsAdmin = true; parser.GetMenu(); // Assert Assert.That(cache.CacheItems.Count, Is.EqualTo(3)); }
/// <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)); }