private bool MatchSelectorLevel(string selectorLevel, XmlElement xmlElement) { if (selectorLevel.Length == 0) { return(false); } int indexOfDot = selectorLevel.IndexOf('.'); int indexOfPound = selectorLevel.IndexOf('#'); string selectorClass = null; string selectorId = null; string selectorTag = null; if (indexOfDot >= 0) { if (indexOfDot > 0) { selectorTag = selectorLevel.Substring(0, indexOfDot); } selectorClass = selectorLevel.Substring(indexOfDot + 1); } else if (indexOfPound >= 0) { if (indexOfPound > 0) { selectorTag = selectorLevel.Substring(0, indexOfPound); } selectorId = selectorLevel.Substring(indexOfPound + 1); } else { selectorTag = selectorLevel; } if (selectorTag != null && selectorTag != xmlElement.LocalName) { return(false); } if (selectorId != null && HtmlToXamlConverter.GetAttribute(xmlElement, "id") != selectorId) { return(false); } if (selectorClass != null && HtmlToXamlConverter.GetAttribute(xmlElement, "class") != selectorClass) { return(false); } return(true); }
internal void ShowKnowledge() { if (ProjectMgr.Instance.App.Knowledge.Content == null) { return; } #if _SAVE_CONTENT_AS_XAML_ this.knowledgeDocument.Document = HtmlToXamlConverter.DeserializeFlowDocument(ProjectMgr.Instance.App.Knowledge.Content.Content); #else this.knowledgeDocument.Document = HtmlToXamlConverter.ConvertHtmlToXaml(ProjectMgr.Instance.App.Knowledge.Content.Content); #endif }
public static FlowDocument CreateXamlFromHtml(string html) { var flowDocument = new FlowDocument(); var xaml = HtmlToXamlConverter.ConvertHtmlToXaml(html, true); return(XamlReader.Load(new XmlTextReader(new StringReader(xaml))) as FlowDocument); //using (var msDocument = new MemoryStream((new ASCIIEncoding()).GetBytes(xaml))) //{ // var textRange = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd); // textRange.Load(msDocument, DataFormats.Xaml); //} //return flowDocument; }
/// <summary> /// Gets the bound document. /// </summary> /// <param name="dp">The dp.</param> /// <returns></returns> public static string GetBoundDocument(DependencyObject dp) { var html = dp.GetValue(BoundDocument) as string; var xaml = string.Empty; //if (!string.IsNullOrEmpty(html)) if (html != null) { xaml = HtmlToXamlConverter.ConvertHtmlToXaml(html, false); } return(xaml); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var xaml = HtmlToXamlConverter.ConvertHtmlToXaml((string)value, true); var flowDocument = XamlReader.Parse(xaml); var document = flowDocument as FlowDocument; if (document != null) { SubscribeToAllHyperlinks(document); document.PagePadding = new Thickness(0d); } return(flowDocument); }
public void RefreshLog() { // Formateamos la salida de HTML a XAML FlowDocument document = txtLogger.Document; String text = HtmlToXamlConverter.ConvertHtmlToXaml(App.Registry, false); TextRange tr = new TextRange(document.ContentStart, document.ContentEnd); using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text))) { tr.Load(ms, DataFormats.Xaml); } }
internal void RenderContent() { NewsFeedItem item = DataContext as NewsFeedItem; if (item == null) { return; } _scroller.ScrollToTop(); VisualStateManager.GoToState(this, Success.Name, true); try { // Build XAML using HtmlToXamlConverter, from here: http://windowsclient.net/downloads/folders/controlgallery/entry2313.aspx // Note that this has been modified quite a bit to add image support and disable some features. Search for "DISABLE" in // HtmlToXamlConverter.cs to see what's been turned off. string xaml = HtmlToXamlConverter.ConvertHtmlToXaml(item.Body, true); // Remove dumb images xaml = Regex.Replace(xaml, "<(Inline|Block)UIContainer><Image Source=\"[^\"]*(feeds\\.wordpress|feedburner|doubleclick).*?\" /></(Inline|Block)UIContainer>", string.Empty); // Try to repair images that use relative paths beginning with /. if (item.Uri != null) { xaml = Regex.Replace(xaml, "Source=\"(/.*?)\"", "Source=\"http://" + item.Uri.Host + "$1\""); } // Remove empty paragraphs. xaml = Regex.Replace(xaml, "<Paragraph />", string.Empty); xaml = Regex.Replace(xaml, "<Paragraph>\\s*?</Paragraph>", string.Empty); xaml = Regex.Replace(xaml, "<Paragraph><LineBreak />", "<Paragraph>"); xaml = Regex.Replace(xaml, "<LineBreak /></Paragraph>", "</Paragraph>"); xaml = Regex.Replace(xaml, "<Paragraph>(<(Run|LineBreak) />\\s)*?</Paragraph>", string.Empty); xaml = Regex.Replace(xaml, "<Paragraph><Run> </Run></Paragraph>", string.Empty); // Build FlowDocument. byte[] byteArray = Encoding.UTF8.GetBytes(xaml); using (MemoryStream stream = new MemoryStream(byteArray)) { FlowDocument document = XamlReader.Load(stream) as FlowDocument; _richTextBox.Document = document; _richTextBox.UpdateLayout(); SizeImages(); } } catch { VisualStateManager.GoToState(this, Fail.Name, true); } }
public string ConvertHtmlToRtf(string htmlText) { if (htmlText != null) { string xamlText = HtmlToXamlConverter.ConvertHtmlToXaml ( htmlText, false); return(ConvertXamlToRtf(xamlText)); } return(null); }
public void LoadRandomBibleChapter() { string content = BibleHelpers.GetRandomBibleChapterHtml(); if (!string.IsNullOrWhiteSpace(content)) { MainDocument = HtmlToXamlConverter.ConvertHtmlToXaml(content); MainDocument.ContentStart.InsertLineBreak(); MainDocument.ContentStart.InsertLineBreak(); MainDocument.ContentStart.InsertLineBreak(); SetDocumentConfig(); } }
private List <RssItem> RefreshNewsAsych(string strUrl) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strUrl); req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)"; WebResponse resp = req.GetResponse(); Stream strIn = resp.GetResponseStream(); StreamReader read = new StreamReader(strIn); string re = read.ReadToEnd(); List <RssItem> lstRss = new List <RssItem>(); //load the feed try { XElement theRoot = XElement.Parse(re); if (theRoot != null) { //get the channel XElement theChannel = theRoot.Element("channel"); if (theChannel != null) { //get the item elements var theItems = from ele in theChannel.Elements("item") select new RssItem { Title = ele.Element("title").Value, Description = HtmlToXamlConverter.ConvertHtmlToXaml(ele.Element("description").Value, true), Link = ele.Element("link").Value, Published = DateTime.Parse(ele.Element("pubDate").Value) }; lstRss = theItems.ToList(); } } } catch (Exception ex) { this.Dispatcher.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate() { txtStatus.Text = myVariables.RSSError + " " + ex.Message; }), System.Windows.Threading.DispatcherPriority.Normal); } return(lstRss); }
void UpdateText(string text) { try { string xaml = HtmlToXamlConverter.ConvertHtmlToXaml(text, false); TextRange tr = new TextRange(Document.ContentStart, Document.ContentEnd); using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(xaml))) { tr.Load(ms, DataFormats.Xaml); } } catch { } }
public void SetText(FlowDocument document, string text) { document.Blocks.Clear(); if (!string.IsNullOrEmpty(text)) { var xaml = HtmlToXamlConverter.ConvertHtmlToXaml(text, false); TextRange tr = new TextRange(document.ContentStart, document.ContentEnd); using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(xaml))) { tr.Load(ms, DataFormats.Xaml); } } }
public override void DoPrint(string[] lines) { var q = PrinterInfo.GetPrinter(Printer.ShareName); var formattedLines = ConvertTagsToHtml(lines); var text = formattedLines.Aggregate("", (current, s) => current + s + "\r\n"); if (!text.ToLower().Contains("<style>")) { text = LocalSettings.DefaultHtmlReportHeader + text; } var xaml = HtmlToXamlConverter.ConvertHtmlToXaml(text, false); PrintFlowDocument(q, PrinterTools.XamlToFlowDocument(xaml)); }
private void showNote() { StickyNote note = new StickyNote() { DataContext = this }; note.txt_noteContent.Document = XamlReader.Parse( HtmlToXamlConverter.ConvertHtmlToXaml(this.pageContent, true) ) as FlowDocument; note.ShowInTaskbar = false; note.Show(); }
public static void ParseSystems(List <ToolTips> ttList, string str) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(str); var tds = doc.DocumentNode.SelectNodes("//td[@class='ColE']"); foreach (HtmlNode node in tds) { string html = node.InnerHtml; string[] arr = html.Split('>'); string command = arr[0].Replace("<a name=\"", "").Replace("\"", ""); StringBuilder sb = new StringBuilder(); for (int i = 1; i < arr.Length; i++) { sb.Append(arr[i]); sb.Append(">"); } string h = sb.ToString(); string desc = h.Replace("</a>", "") .Replace("<p>", "\n\n") //.Replace("</p>", "\n\n") .Replace("<br>", "\n") .Replace("<ul>", "\n") .Replace("<li>", "\n") .Replace("</li>", "") .Replace("</ul>", "") .Replace("</ul", "") .Replace("</p", "") .Replace("<b>", "") .Replace("</b>", "") .TrimEnd('>'); string test = HtmlToXamlConverter.ConvertHtmlToXaml(h, false); //string desc = node.InnerText.Replace("<p>", "
"); ToolTips t = new ToolTips(); t.Command = command; t.Description = desc; ttList.Add(t); } }
private void HtmlToXaml_Click(object sender, RoutedEventArgs e) { OutputBox.Text = string.Empty; string output = string.Empty; try { output = HtmlToXamlConverter.ConvertHtmlToXaml(HtmlBox.Text, true); XamlBox.Text = output; //PreviewRichTextBox.Document = XamlReader.Load(new XmlTextReader(new StringReader(output))) as FlowDocument; } catch (Exception ex) { OutputBox.Text = ex.ToString(); } }
private static void OnValueChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { try { var richTextBox = (RichTextBox)dependencyObject; var text = (e.NewValue ?? string.Empty).ToString(); var xaml = HtmlToXamlConverter.ConvertHtmlToXaml(text, true); var flowDocument = XamlReader.Parse(xaml) as FlowDocument; HyperlinksSubscriptions(flowDocument); richTextBox.Document = flowDocument; } catch (Exception ex) { SysLog.Error("Message[{0}], StackTrace[{1}]", ex.Message, ex.StackTrace); } }
public static string GetBoundDocument(DependencyObject dp) { #if _SAVE_CONTENT_AS_XAML_ return(dp.GetValue(BoundDocument) as string); #else var html = dp.GetValue(BoundDocument) as string; var xaml = string.Empty; if (!string.IsNullOrEmpty(html)) { xaml = HtmlToXamlConverter.ConvertHtmlToXaml(html, true); } return(xaml); #endif }
public void SetText(System.Windows.Documents.FlowDocument document, string text) { text = HtmlToXamlConverter.ConvertHtmlToXaml(text, false); try { TextRange tr = new TextRange(document.ContentStart, document.ContentEnd); using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text))) { tr.Load(ms, DataFormats.Xaml); } } catch { //throw new InvalidDataException("data provided is not in the correct Html format."); } }
private void SetDocument(string html) { var xaml = HtmlToXamlConverter.ConvertHtmlToXaml(html, true); var stringReader = new StringReader(xaml); var xmlReader = XmlReader.Create(stringReader); var xamlReader = new XamlReader(); var flowDocument = xamlReader.LoadAsync(xmlReader); var doc = flowDocument as FlowDocument; if (doc != null) { SubscribeToAllHyperlinks(doc); doc.PagePadding = new Thickness(0d); } Document = doc; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var text = value as string; if (String.IsNullOrEmpty(text)) { return(null); } text = _markdown.Transform(text); text = HtmlToXamlConverter.ConvertHtmlToXaml(text, true); var flowDocument = (FlowDocument)XamlReader.Parse(text); SubscribeToAllHyperlinks(flowDocument); return(flowDocument); }
public void SetBookmark(BookmarkPrims bookmarkPrims) { var pipeline = new Markdig.MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); Viewbox viewbox = new Viewbox(); RichTextBoxs.Clear(); foreach (var it in bookmarkPrims) { int lineNo = it.Key - 1; bool redraw = false; CommentRichTextBox TextBox = null; if (!RichTextBoxs.ContainsKey(lineNo)) { TextBox = new CommentRichTextBox(it.Value); RichTextBoxs.TryAdd(lineNo, TextBox); redraw = true; } else if (RichTextBoxs[lineNo].m_comment != it.Value.m_comment) { TextBox = RichTextBoxs[lineNo]; redraw = true; } if (TextBox != null) { var html = Markdig.Markdown.ToHtml(it.Value.m_comment, pipeline); var xaml = HtmlToXamlConverter.ConvertHtmlToXaml(html, true); CommentRichTextBox rtb = new CommentRichTextBox(); rtb.Document = XamlReader.Parse(xaml) as FlowDocument; SetLineHeight(rtb); double Height = GethDocumentHeight(viewbox, rtb); TextBox.Document = XamlReader.Parse(xaml) as FlowDocument; TextBox.Document.Background = Brushes.LightGray; SetLineHeight(TextBox); TextBox.Height = Height; TextBox.Visibility = Visibility.Visible; } if (redraw) { RequestRedrawLine(lineNo); } } }
private static string ParseCssSize(string styleValue, ref int nextIndex, bool mustBeNonNegative) { ParseWhiteSpace(styleValue, ref nextIndex); int startIndex = nextIndex; // Parse optional minus sign if (nextIndex < styleValue.Length && styleValue[nextIndex] == '-') { nextIndex++; } if (nextIndex < styleValue.Length && Char.IsDigit(styleValue[nextIndex])) { while (nextIndex < styleValue.Length && (Char.IsDigit(styleValue[nextIndex]) || styleValue[nextIndex] == '.')) { nextIndex++; } string number = styleValue.Substring(startIndex, nextIndex - startIndex); string unit = ParseWordEnumeration(_fontSizeUnits, styleValue, ref nextIndex); if (unit == null) { unit = "px"; // Assuming pixels by default } if (mustBeNonNegative && styleValue[startIndex] == '-') { return "0"; } else { double val; if (HtmlToXamlConverter.TryGetLengthValue(number + unit, out val)) { return val.ToString(); } else { return "0"; } } } return null; }
private void GenerateQRCodeAndLink(dynamic state) { var qrcode = new QRCodeWriter(); var price = (decimal)state.price / DNotesToSatoshi; var address = (string)state.address; var qrValue = string.Format("dnotes:{0}?amount={1}&invoice={2}", address, price, state.invoice); var priceUSD = (decimal)state.priceUSD; var invoice = (string)state.invoice; var payText = string.Format("<strong>Please send exactly:</strong> {0:0.00000000} NOTE <a href='" + CopyAmtUrl + "'>copy</a><br/>" + "<strong>To:</strong> {1}+{2} <a href='" + CopyAddrUrl + "'>copy</a>", price, address, invoice); usdLabel.Content = string.Format("USD: ${0:0.00}", priceUSD); var xaml = HtmlToXamlConverter.ConvertHtmlToXaml(payText, true); dynamic flowDocument = XamlReader.Parse(xaml); HyperlinkEvents(flowDocument); payLabel.Document = flowDocument; var barcodeWriter = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new EncodingOptions { Height = 300, Width = 300, Margin = 1 } }; using (var bitmap = barcodeWriter.Write(qrValue)) using (var stream = new MemoryStream()) { bitmap.Save(stream, ImageFormat.Png); BitmapImage bi = new BitmapImage(); bi.BeginInit(); stream.Seek(0, SeekOrigin.Begin); bi.StreamSource = stream; bi.CacheOption = BitmapCacheOption.OnLoad; bi.EndInit(); qrCodeImage.Source = bi; } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { if (!string.IsNullOrEmpty(value?.ToString())) { var bytes = Encoding.Default.GetBytes(value.ToString()); return(HtmlToXamlConverter.ConvertHtmlToXaml(Encoding.UTF8.GetString(bytes), false)); } } catch { // ignored } return(null); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null) { FlowDocument flowDocument = new(); string xaml = HtmlToXamlConverter.ConvertHtmlToXaml(value.ToString(), false); using (MemoryStream stream = new(new ASCIIEncoding().GetBytes(xaml))) { TextRange text = new(flowDocument.ContentStart, flowDocument.ContentEnd); text.Load(stream, DataFormats.Xaml); } return(flowDocument); } return(value); }
internal override System.Windows.Documents.FlowDocument GetKnowledgeDefinition() { if (this.assessmentApp.Knowledge.Content == null) { return(new System.Windows.Documents.FlowDocument()); } if (this.assessmentApp.Knowledge.Content.ContentType == Assessment.Data.ContentType.Html) { return(HtmlToXamlConverter.ConvertHtmlToXaml(this.assessmentApp.Knowledge.Content.Content)); } else if (this.assessmentApp.Knowledge.Content.ContentType == Assessment.Data.ContentType.FlowDocument) { FlowDocument doc = HtmlToXamlConverter.DeserializeFlowDocument(this.assessmentApp.Knowledge.Content.Content); CommonControlCreator.replaceTextBoxWithRichTextBox(doc, this.assessmentApp.Knowledge.Content, null); return(doc); } throw new NotSupportedException("Knowledge must be HTML or FlowDocument format!"); }
public void accentText(string text, TextDataFormat format) { if (format == TextDataFormat.Html) { text = text.Substring(text.IndexOf('<')); StringBuilder sb = new StringBuilder(); sb.Append(HtmlToXamlConverter.ConvertHtmlToXaml(text, true)); richTextBox.Document = (FlowDocument)XamlReader.Parse(sb.ToString()); } if (format == TextDataFormat.Rtf) { MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(text)); TextRange range = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd); range.Load(stream, DataFormats.Rtf); } if (format == TextDataFormat.Text) { richTextBox.AppendText(text); } }
private FlowDocument ConvertHtmlToFlowDocument(string html) { var xaml = HtmlToXamlConverter.ConvertHtmlToXaml(html, false); var flowDocument = new FlowDocument(); using (var stream = new MemoryStream((new UTF8Encoding()).GetBytes(xaml))) { var text = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd); text.Load(stream, DataFormats.Xaml); } SubscribeToAllHyperlinks(flowDocument); flowDocument.FontSize = SystemFonts.IconFontSize; flowDocument.FontWeight = SystemFonts.MessageFontWeight; flowDocument.FontFamily = SystemFonts.CaptionFontFamily; return(flowDocument); }
private static void OnHtmlTextChanged( DependencyObject depObj, DependencyPropertyChangedEventArgs e) { // Go ahead and return out if we set the property on something other than a textblock, or set a value that is not a string. var txtBox = depObj as TextBlock; if (txtBox == null) { return; } if (!(e.NewValue is string)) { return; } var html = e.NewValue as string; string xaml; InlineCollection xamLines; try { xaml = HtmlToXamlConverter.ConvertHtmlToXaml(html, false); xamLines = ((Paragraph)((Section)System.Windows.Markup.XamlReader.Parse(xaml)).Blocks.FirstBlock).Inlines; } catch { // There was a problem parsing the html, return out. return; } // Create a copy of the Inlines and add them to the TextBlock. Inline[] newLines = new Inline[xamLines.Count]; xamLines.CopyTo(newLines, 0); txtBox.Inlines.Clear(); foreach (var l in newLines) { txtBox.Inlines.Add(l); } }