public override object parse(string s) { // parses a cell content as a map of headers. // syntax is name:value\n* IList <RestData.Header> expected = new List <RestData.Header>(); if (!"".Equals(s.Trim())) { string expStr = HtmlTools.fromHtml(s.Trim()); string[] nvpArray = expStr.Split(new char[] { '\n' }); foreach (string nvp in nvpArray) { try { string[] nvpEl = nvp.Split(new char[] { ':' }, 2); expected.Add(new RestData.Header(nvpEl[0].Trim(), nvpEl[1].Trim())); } catch (Exception) { throw new System.ArgumentException("Each entry in the must be separated by \\n and each entry must be expressed as a name:value"); } } } return(expected); }
private void WriteTableHeader(StreamWriter sw) { sw.WriteLine("<thead><tr>"); foreach (ColumnDescriptor descr in displayedColumns) { if ((descr.Flags & ColumnDescriptorFlags.FixedSize) == 0) { string[] props = descr.PropNames; string prop = (props[0][0] != '-') ? props[0] : props[0].Substring(1); string text; sw.Write("<th>"); if (prop == "DisplayName") { text = prop; } else { IPropType propType = Core.ResourceStore.PropTypes[prop]; text = !String.IsNullOrEmpty(propType.DisplayName) ? propType.DisplayName : propType.Name; } sw.Write(HtmlTools.SafeHtmlDecode(text)); sw.WriteLine("</th>"); } } sw.WriteLine("</tr></thead>"); }
public void wrong(ICellWrapper <String> expected, RestDataTypeAdapter ta) { string expectedContent = expected.body(); expected.body(Tools.HtmlTools.makeContentForWrongCell(expectedContent, ta, this, minLenForToggle)); expected.body("fail:" + HtmlTools.wrapInDiv(expected.body())); }
private static void ToHtmlPhrase(string body, StringBuilder htmlBuilder) { htmlBuilder.Append("<td width=100% valign=top>"); // convert all urls to active weblinks htmlBuilder.Append(HtmlTools.ConvertLinks(body.Replace("\n", "<br>"))); htmlBuilder.Append("</td>"); }
public string GetPreviewText(IResource res, int lines) { IPreviewTextProvider provider = (IPreviewTextProvider)_previewTextProviders [res.Type]; if (provider != null) { string previewText = provider.GetPreviewText(res, lines); if (previewText == null) { return(""); } return(previewText); } if (res.HasProp(Core.Props.LongBody)) { string longBody = res.GetPropText(Core.Props.LongBody).Trim(); if (res.HasProp(Core.Props.LongBodyIsHTML)) { if (longBody.Length > 1024) { longBody = longBody.Substring(0, 1024) + "..."; // we won't fit more text in 2 lines, anyway } longBody = HtmlTools.StripHTML(longBody); longBody = HtmlTools.SafeHtmlDecode(longBody).Trim(); } longBody = longBody.Replace('\t', ' '); return(CleanPreviewText(longBody, lines)); } return(""); }
public override void DoCells(Parse parse) { if (restFixture == null) { restFixture = new CommonRestFixture <Parse>(this.Symbols); restFixture.Config = Config.getConfig(ConfigNameFromArgs); string url = BaseUrlFromArgs; if (url != null) { restFixture.BaseUrl = new Url(HtmlTools.fromSimpleTag(url)); } restFixture.initialize(Runner.FIT); ((FitFormatter)restFixture.Formatter).ActionFixtureDelegate = this; } IRowWrapper <Parse> currentRow = new FitRow(parse); try { restFixture.Formatter.DisplayActual = restFixture.displayActualOnRight; restFixture.processRow(currentRow); } catch (Exception exception) { // TODO: Sort out CellWrapper vs CellWrapper<Parse>. ICellWrapper <Parse> firstCell = currentRow.getCell(0); LOG.Error(exception, "Exception when processing row {0}", firstCell.text()); ICellFormatter <Parse> cellFormatter = restFixture.Formatter; cellFormatter.exception(firstCell, exception); } }
/// <summary> /// Parses the expected body in the current test. /// <para> /// A body is a String containing XPaths one for each new line. Empty body /// would result in an empty {@code List<String>}. A body containing the /// value {@code no-body} is especially treated separately. /// /// </para> /// </summary> /// <param name="expectedListOfXpathsAsString"> expected list of xpaths as string </param> public override object parse(string expectedListOfXpathsAsString) { // expected values are parsed as a list of XPath expressions IList <string> expectedXPathAsList = new List <string>(); if (expectedListOfXpathsAsString == null) { return(expectedXPathAsList); } string expStr = expectedListOfXpathsAsString.Trim(); if ("no-body".Equals(expStr)) { return(expectedXPathAsList); } if ("".Equals(expStr)) { return(expectedXPathAsList); } expStr = HtmlTools.fromHtml(expStr); string[] nvpArray = expStr.Split(new string[] { "\r", "\n", "\r\n" }, StringSplitOptions.None); foreach (string nvp in nvpArray) { if (!string.IsNullOrWhiteSpace(nvp)) { expectedXPathAsList.Add(nvp.Trim()); } } return(expectedXPathAsList); }
/// <summary> /// configures the internal map of handled content types (See /// <seealso cref="RestFixtureConfig"/>). It reads two properties: /// <ul> /// <li>{@code restfixture.content.default.charset} to determine the default /// charset for that content type, in cases when the content type header of /// the request/response isn't specifying the charset. If this config /// parameter is not set, then the default value is /// <seealso cref="Charset#defaultCharset()"/>. /// <li>{@code restfixture.content.handlers.map} to override the default map. /// </ul> /// </summary> /// <param name="config"> /// the config </param> public static void config(Config config) { RestData.DEFAULT_ENCODING = config.get("restfixture.content.default.charset", Encoding.UTF8.HeaderName); string htmlConfig = config.get("restfixture.content.handlers.map", ""); string configStr = HtmlTools.fromHtml(htmlConfig); IDictionary <string, string> map = StringTools.convertStringToMap(configStr, "=", "\n", true); foreach (string key in map.Keys) { string value = map[key]; string enumName = value.ToUpper(); ContentType ct = ContentType.valueOf(enumName); if (null == ct) { IList <ContentType> values = ContentType.values(); StringBuilder sb = new StringBuilder(); sb.Append("["); foreach (ContentType cType in values) { sb.Append("'").Append(cType).Append("' "); } sb.Append("]"); throw new System.ArgumentException( "I don't know how to handle " + value + ". Use one of " + sb); } contentTypeToEnum[key] = ct; } }
bool IResourceTextProvider.ProcessResourceText(IResource resource, IResourceTextConsumer consumer) { try { StreamReader reader = Core.FileResourceManager.GetStreamReader(resource); if (reader != null) { using ( reader ) { // for weblinks, detect & set charset if it is not set IResource source = resource.GetLinkProp("Source"); if (source != null) { string charset = source.GetPropText(Core.FileResourceManager.PropCharset); if (charset.Length == 0) { charset = HtmlTools.DetectCharset(reader); new ResourceProxy(source).SetPropAsync(Core.FileResourceManager.PropCharset, charset); reader.BaseStream.Position = 0; } } ProcessResourceStream(resource, source, reader, consumer); } } } catch (ObjectDisposedException) { Core.TextIndexManager.QueryIndexing(resource.Id); } return(true); }
public void CleanHtmlExpression() { string strg1 = "efzefze"; string strg2 = "zefzefzefez"; string strg3 = "ATTENTION. LIVRE SANS LA CARTOUCHE<br />il n\'y a plus que l\'embout flexible dans la boite.<br />l\'embout rigide a été supprimé.<br />Attention de le noter car la photo du cata 2013 ne correspond plus"; string strg3result = "ATTENTION. LIVRE SANS LA CARTOUCHE" + Environment.NewLine + "il n\'y a plus que l\'embout flexible dans la boite." + Environment.NewLine + "l\'embout rigide a été supprimé." + Environment.NewLine + "Attention de le noter car la photo du cata 2013 ne correspond plus"; string exprWithBreak = strg1 + "<br>" + strg2; string exprWithoutBreak = strg1 + strg2; if (HtmlTools.CleanHtmlExpression(exprWithBreak, true) == exprWithBreak) { throw new Exception(); } if (HtmlTools.CleanHtmlExpression(exprWithBreak, false) != exprWithoutBreak) { throw new Exception(); } if (HtmlTools.CleanHtmlExpression(strg3, true) != strg3result) { throw new Exception(); } var string4 = "Catalogue Compétition 2015 Français / Espagnol / Anglais"; var string4Result = "Catalogue Compétition 2015 Français / Espagnol / Anglais"; if (HtmlTools.CleanHtmlExpression(string4, false) != string4Result) { throw new Exception(); } }
public void exception(ICellWrapper <String> cell, Exception exception) { //String m = Tools.toHtml(cell.getWrapped() + "\n-----\n") + Tools.toCode(Tools.toHtml(out.toString())); string m = HtmlTools.toHtml(cell.Wrapped + "\n-----\n") + HtmlTools.toCode(HtmlTools.toHtml(exception.ToString())); cell.body("error:" + HtmlTools.wrapInDiv(m)); //cell.body("error:" + m); }
private void BuildDirectories(string vPath) { ImageViewPanel.Visible = false; ImageBrowserPanel.Visible = true; string path = imageTools.GetPath(vPath); DirectoryWrapper data = new DirectoryWrapper(path, imageTools); // draw navigation HtmlTools.RendenderLinkPath(ImageBrowserPanel.Controls, path, this, imageTools.cfg); ImageBrowserPanel.Controls.Add(HtmlTools.HR); if (ModuleHasEditRights) { TextBox editblurb = new TextBox(); editblurb.ID = "editblurb"; editblurb.Text = data.Blurb; editblurb.Width = new Unit("100%"); editblurb.Height = new Unit("100px"); editblurb.TextMode = TextBoxMode.MultiLine; ImageBrowserPanel.Controls.Add(editblurb); HyperLink lnkSave = new HyperLink(); lnkSave.NavigateUrl = Page.GetPostBackClientHyperlink(this, "directorysave;" + vPath); lnkSave.Text = "Save"; ImageBrowserPanel.Controls.Add(lnkSave); ImageBrowserPanel.Controls.Add(HtmlTools.HR); } else { // pump out the blurb Label blurb = new Label(); blurb.Text = data.Blurb; ImageBrowserPanel.Controls.Add(blurb); // draw a line if appropriate if (blurb.Text.Length > 0 && (data.Directories.Count > 0 || data.Images.Count > 0)) { ImageBrowserPanel.Controls.Add(HtmlTools.HR); } } // draw subdirectories ImageBrowserPanel.Controls.Add(HtmlTools.RenderDirectoryTable(4, data, this)); // draw a line if appropriate if (data.Directories.Count > 0 && data.Images.Count > 0) { ImageBrowserPanel.Controls.Add(HtmlTools.HR); } // draw images ImageBrowserPanel.Controls.Add(HtmlTools.RenderImageTable(7, 0, data, this)); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is string) { return(HtmlTools.Strip(WebUtility.HtmlDecode(value.ToString()))); } return(string.Empty); }
private int CountNewLines() { int count = 0; foreach (SubLine line in _lines) { count += HtmlTools.RemoveHtmlTags(line.Context.Replace("</br>", "")).Length - 1; } return(count); }
public override object parse(string possibleJsContent) { if (possibleJsContent == null || !HasJavaScriptHeader(possibleJsContent.Trim())) { forceJsEvaluation = false; return(base.parse(possibleJsContent)); } forceJsEvaluation = true; return(HtmlTools.fromHtml(possibleJsContent.Trim())); }
private void SetBlogSummary(BlogArticleEntity entity) { string summary = HtmlTools.ReplaceHtmlTag(entity.Content); if (summary.Length > 200) { summary = summary.Substring(0, 200); summary += "..."; } entity.Summary = summary; }
public void Should_Enclose_Text_In_Code_Tags() { // Arrange. string textToEnclose = "x"; string expectedResult = "<code>x</code>"; // Act. string actualResult = HtmlTools.toCode(textToEnclose); // Assert. Assert.AreEqual(expectedResult, actualResult); }
public void Should_Extract_Text_From_Tag() { // Arrange. string textWithTags = "<bob data='1'>stuff</bob>"; string expectedResult = "stuff"; // Act. string actualResult = HtmlTools.fromSimpleTag(textWithTags); // Assert. Assert.AreEqual(expectedResult, actualResult); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is Post post) { return new HtmlWebViewSource { Html = HtmlTools.WrapContent(post) } } ; return(string.Empty); }
private static void DisplayHTML(IResource resource, AbstractWebBrowser browser, WordPtr[] wordsToHighlight) { try { StreamReader reader = Core.FileResourceManager.GetStreamReader(resource); if (reader != null) { string sourceUrl = ""; string htmlText = Utils.StreamReaderReadToEnd(reader); reader.BaseStream.Close(); IResource source = FileResourceManager.GetSource(resource); if (source != null) { string url = string.Empty; if (Core.ResourceStore.PropTypes.Exist("URL")) { url = source.GetPropText("URL"); } if (url.Length > 0) { sourceUrl = url; htmlText = HtmlTools.FixRelativeLinks(htmlText, url); } else { string directory = source.GetPropText("Directory"); if (directory.Length > 0) { if ((!directory.EndsWith("/")) && (!directory.EndsWith("\\"))) { directory += "/"; } htmlText = HtmlTools.FixRelativeLinks(htmlText, directory); } } } try { WebSecurityContext context = WebSecurityContext.Restricted; context.WorkOffline = false; browser.ShowHtml(htmlText, context, DocumentSection.RestrictResults(wordsToHighlight, DocumentSection.BodySection)); browser.CurrentUrl = sourceUrl; } catch (Exception e) { Trace.WriteLine(e.ToString(), "Html.Plugin"); } } } catch (ObjectDisposedException) {} }
public void Should_Include_Content_Wrapped_In_Div() { //Arrange. string title = "title text"; string content = "this is the content"; string expectedContentDiv = "<div>this is the content</div>"; // Act. string actualResult = HtmlTools.makeToggleCollapseable(title, content); // Assert. Assert.IsTrue(actualResult.Contains(expectedContentDiv)); }
public void Should_Enclose_Text_In_Anchor_Tags() { // Arrange. string textToEnclose = "x"; string linkUrl = "http://localhost:1234"; string expectedResult = "<a href='http://localhost:1234'>x</a>"; // Act. string actualResult = HtmlTools.toHtmlLink(linkUrl, textToEnclose); // Assert. Assert.AreEqual(expectedResult, actualResult); }
public void Should_Include_Title_In_Paragraph_with_Title_Class() { //Arrange. string title = "title text"; string content = "this is the content"; string expectedTitleElement = "<p class='title'>title text</p>"; // Act. string actualResult = HtmlTools.makeToggleCollapseable(title, content); // Assert. Assert.IsTrue(actualResult.Contains(expectedTitleElement)); }
[Test] public void TestConvertLinks() { Assert.AreEqual("WWW).", HtmlTools.ConvertLinks("WWW).")); Assert.AreEqual("WWW сервере", HtmlTools.ConvertLinks("WWW сервере")); Assert.AreEqual("RSDN@home", HtmlTools.ConvertLinks("RSDN@home")); Assert.AreEqual("<a href=\"news:[email protected]\">news:[email protected]</a>...", HtmlTools.ConvertLinks("news:[email protected]...")); Assert.AreEqual("<a href=\"http://jetbrains.com\">http://jetbrains.com</a>.", HtmlTools.ConvertLinks("http://jetbrains.com.")); Assert.AreEqual("<a href=\"http://www.jetbrains.com\">www.jetbrains.com</a>.", HtmlTools.ConvertLinks("www.jetbrains.com.")); Assert.AreEqual("<a href=\"http://www.jetbrains.com\">www.jetbrains.com</a>. ", HtmlTools.ConvertLinks("www.jetbrains.com. ")); Assert.AreEqual("<a href=\"http://www.jetbrains.com/\">www.jetbrains.com/</a>", HtmlTools.ConvertLinks("www.jetbrains.com/")); Assert.AreEqual("<a href=\"http://www.jetbrains.com/\">http://www.jetbrains.com/</a>", HtmlTools.ConvertLinks("http://www.jetbrains.com/")); Assert.AreEqual("<a href=\"http://www.jetbrains.com\">www.jetbrains.com</a> a", HtmlTools.ConvertLinks("www.jetbrains.com a")); Assert.AreEqual("<a href=\"news://news.intellij.net:119/[email protected]\">news://news.intellij.net:119/[email protected]</a>", HtmlTools.ConvertLinks("news://news.intellij.net:119/[email protected]")); }
protected void Page_Load(object sender, System.EventArgs e) { string path = ImageTools.GetPath(Request["path"]); DirectoryWrapper data = new DirectoryWrapper(path); // draw navigation HtmlTools.RendenderLinkPath(ImageBrowserPanel.Controls, path, Request.Path + "?page=" + "ImageBrowser.ascx&path="); ImageBrowserPanel.Controls.Add(HtmlTools.HR); // setup titles, headings etc. if (data.Name != null && data.Name.Length > 0) { ((Literal)this.Page.FindControl("title")).Text = System.Configuration.ConfigurationSettings.AppSettings["SiteTitle"] + " - " + data.Name; } else { ((Literal)this.Page.FindControl("title")).Text = System.Configuration.ConfigurationSettings.AppSettings["SiteTitle"] + " - My Pictures"; } // pump out the blurb Label blurb = new Label(); blurb.Text = data.Blurb; ImageBrowserPanel.Controls.Add(blurb); // draw a line if appropriate if (blurb.Text.Length > 0 && (data.Directories.Count > 0 || data.Images.Count > 0)) { ImageBrowserPanel.Controls.Add(HtmlTools.HR); } // draw subdirectories ImageBrowserPanel.Controls.Add(HtmlTools.RenderDirectoryTable(4, data, Request.Path + "?page=" + "ImageBrowser.ascx&path=")); // draw a line if appropriate if (data.Directories.Count > 0 && data.Images.Count > 0) { ImageBrowserPanel.Controls.Add(HtmlTools.HR); } // draw images ImageBrowserPanel.Controls.Add(HtmlTools.RenderImageTable(7, 0, data, Request.Path + "?page=" + "WebImage.ascx&path=")); }
public void asLink(ICellWrapper <Parse> cell, string resolvedUrl, string link, string text) { string actualText = text; string parsed = null; if (displayAbsoluteURLInFull) { parsed = HtmlTools.fromSimpleTag(resolvedUrl); if (parsed.Trim().StartsWith("http", StringComparison.Ordinal)) { actualText = parsed; } } cell.body(HtmlTools.toHtmlLink(link, actualText)); }
private IEnumerable <Post> PreparePosts(IEnumerable <Post> posts) { // Wrap the HTML content with headers, styles, scripts etc. int fontsize = _settings.GetSetting("fontsize", () => Config.DefaultFontSize, SettingLocality.Roamed); var settings = new HtmlSettings { FontSize = fontsize }; foreach (var post in posts) { post.Content.Rendered = HtmlTools.WrapContent(post, settings); } return(posts); }
public void Should_Return_Div_with_CollapsibleClosed_Class() { //Arrange. string title = "title text"; string content = "this is the content"; string expectedStartTag = "<div class='collapsible closed'>"; string expectedEndTag = "</div>"; // Act. string actualResult = HtmlTools.makeToggleCollapseable(title, content); // Assert. Assert.IsTrue(actualResult.StartsWith(expectedStartTag)); Assert.IsTrue(actualResult.EndsWith(expectedEndTag)); }
public async void Initialize() { _client = new WordPressClient(ApiCredentials.WordPressUri); var posts = await _client.ListPosts(true); if (posts != null) { foreach (var post in posts) { // Clean excerpt if (post?.Excerpt?.Rendered != null) { post.Excerpt.Raw = HtmlTools.Strip(post.Excerpt.Rendered); } } Posts = new ObservableCollection <Post>(posts); } }
/// <summary> /// Processes each row in the config fixture table and loads the key/value /// pairs. The fixture optional first argument is the config name. If not /// supplied the value is defaulted. See <seealso cref="Config#DEFAULT_CONFIG_NAME"/>. /// </summary> public override void DoRow(Parse p) { Parse cells = p.Parts; try { string key = cells.Text; string value = cells.More.Text; Config c = Config; c.add(key, value); string fValue = HtmlTools.toHtml(value); Parse valueParse = cells.More; valueParse.SetBody(fValue); Right(valueParse); } catch (Exception e) { Exception(p, e); } }