Coder Social home page Coder Social logo

markupconverter's Introduction

MarkupConverter

This sample shows how to convert from HTML to RTF, RTF to HTML, XAML to HTML and HTML to XAML.

For a full detailed write up on how this works see Converting between RTF and HTML on the Code Gallery.

markupconverter's People

Contributors

mmanela avatar sachin4dotnet avatar tlentine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

markupconverter's Issues

Html "BACKGROUND-COLOR=windows" results in Background black

The HtmlToXamlConveter miss handles the following html fragment

#-- Html Fragment ---

<P style="TEXT-ALIGN: left"><SPAN style="COLOR: black"><SPAN 
style="BACKGROUND-COLOR: window"><SPAN 
style="FONT-SIZE: 9pt; FONT-FAMILY: Segoe UI">The </SPAN><SPAN 
style="COLOR: red">gospel </SPAN><SPAN style="COLOR: black">was </SPAN><SPAN 
style="COLOR: blue">heard </SPAN><SPAN style="COLOR: black">by the </SPAN><SPAN 
style="COLOR: seagreen">saints</SPAN></SPAN></SPAN></P>

--- end Html fragment ---

Note: the <SPAN style="BACKGROUND-COLOR: window"> This is miss handled to the following.

XamlText = HtmlToXamlConverter.ConvertHtmlToXaml(htmlFragment, false); 

#--- XamlText result ---

<Section xml:space="preserve" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph TextAlignment="left"><Span Foreground="black"><Span Background="black"><Run FontSize="9pt" FontFamily="segoe ui">The </Run><Run Foreground="red">gospel </Run><Run Foreground="black">was </Run><Run Foreground="blue">heard </Run><Run Foreground="black">by the </Run><Run Foreground="seagreen">saints</Run></Span></Span></Paragraph></Section>

Note the <Span Foreground="black">

Found work around by removing the following the result has no background color:

style="BACKGROUND-COLOR: window"

Image support

This currently doesnt support images, any plan to add image support?

No License Attached

Hi,
Just wanted to check that the code here is Apache Licensed ok? The link to msdn says so, but don't want to presume.

Many thanks,
Chris

overflow exception in method ReadLookAheadCharacter from the HtmlLexicalAnalyzer class

I have an WPF application in which i am using the classes (htmlLexicalAnalyzer.cs, HtmlToXAMLConverter, etc.) from the sample application HtmlToXAMLDemo (the main repo).

I have changed the namespace of that classes for mine only.

Then in my physical pc is working correctly (no errors nor exceptions).

Then I create an MSI and deploy my WPF application to a new clean and fresh pc (a virtual machine). After installation I execute it and I get the below exception:

System.OverflowException: Arithmetic operation resulted in an overflow.
at myApp.Converters.HtmlConverter.HtmlLexicalAnalyzer.ReadLookAheadCharacter()
at myApp.Converters.HtmlConverter.HtmlLexicalAnalyzer.GetNextCharacter()
at myApp.Converters.HtmlConverter.HtmlLexicalAnalyzer.GetNextTagToken()
at myApp.Converters.HtmlConverter.HtmlParser.ParseHtmlContent()
at myApp.Converters.HtmlConverter.HtmlToXamlConverter.ConvertHtmlToXaml(String htmlString, Boolean asFlowDocument)
at myApp.UI.HtmlRichTextBoxBehavior.OnValueChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)

It looks like there is something wrong in ReadLookAheadCharacter that is causing this exception in some particular scenario like mine.

Please, could you have a look at it and fix it? Thanks in advance.

RGB color is not supported

Hello,

This project is very good & very useful to me for my WPF application.
Perhaps, if I am using a "

" tag with "style='color: rgb(255,90,40);' then it is not getting color and set black or gray color.
I have debugged into it and found the issue in "MarkupConverter/htmlcssparser.cs ". There is a function of ParseWhiteSpace in which color is converting but I can't understand why there is :

else if (styleValue.Substring(nextIndex, 3).ToLower() == "rbg")
                {
                    //  Implement real rgb() color parsing
                    while (nextIndex < styleValue.Length && styleValue[nextIndex] != ')')
                    {
                        nextIndex++;
                    }
                    if (nextIndex < styleValue.Length)
                    {
                        nextIndex++; // to skip ')'
                    }
                    color = "gray"; // return bogus color
                }

In this "rbg" is by mistake or some other reason (it should be rgb on rbg) - I don't know.

Anyway, I have resolved it by adding following code:

                //Added by Sachin for converting rgb color to hex and return
                else if (styleValue.Substring(nextIndex, 3).ToLower() == "rgb")
                {
                    //  Implement real rgb() color parsing
                    startIndex = 4;
                    string temp_color = styleValue.Substring(startIndex, styleValue.Length - 1 - startIndex);
                    string[] rgb = temp_color.Split(',');
                    color = "#" + (byte.Parse(rgb[0])).ToString("X2") + (byte.Parse(rgb[1])).ToString("X2") + (byte.Parse(rgb[2])).ToString("X2");
                }

Thanks,

Sachin

Whenever i enter a bulleted list it crashes

Whenever i enter a bulleted list in rtf it crashes.

Unrecognized structure in data format 'Rich Text Format'.
Parameter name: stream

Function: ConvertRtfToXaml
Code line: textRange.Load(rtfMemoryStream, DataFormats.Rtf)

ParseXamlColor issue

The ParseXamlColor routine assumes the input string is in the format #AARRGGBB. In an operational scenario, this has been demonstrated to not always be true, and when the value is a 6-digit string (#000000) this converts the value to #0000 which is not valid.

private static string ParseXamlColor(string color) { if (color.StartsWith("#")) { // Remove transparancy value color = "#" + color.Substring(3); } return color; }

HTML - Table width

Hello,

I know this projct is not really up-to-date, but I've just started looking for a HTML to RTF converter, and found yours. Awesome job! Almost as good as Sautin's dll, but there's a significant problem. I can't set column widths in tables, or width of tables.
Example HTML:

<!DOCTYPE html>
<html>
<head>
  <title>Table example</title>
  <meta http-equiv=Content-Type content="text/html; charset=unicode">
  <style>
    body {
      font-family: "Bookman Old Style", serif;
      font-weight: 200;
      font-size: 16px;
      margin: 0px;

    table {
      width: 100%;
    }
  </style>
</head>

<body>

  <table style="width:100%">
   <!-- <colgroup>
      <col width="50%" />
      <col width="50%" />
    </colgroup>-->
    <tr>
      <td style="width:50%">First cell</td>
      <td style="width:50%">Second cell, a bit longer</td>
    </tr>

  </table>

</body>
</html>

At colgroup it crashes, and style="width:50%" is ignored.

This is the only thing I miss, otherwise it would be a perfect alternative of Sautin's one. I hope anyone is still caring about this cool project.

Any help would be appreciated.
Thanks,

dobragab

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.