How to dispaly HTML page in Silverlight application?

How do I convert text to bare-bones HTML?

  • How do I convert basic text formatting (italics, bold, underline, superscript, etc.) into HTML formatting on a semi-automated basis? Many of my clients' websites are CMS-based, much like blogging software, allowing them to easily add new articles, update pages, etc. They don't need to know about paragraph tags, break tags or any of the document-level HTML tags. But they do need to insert character-formatting tags, like em, strong, and so on. A clever UI, with "bold" and "italic" buttons means that they don't need to know HTML in order to mark these up. When porting large amounts of information, such as a twenty-page Word document, pasting the text inside of a textarea loses the formatting, and so somebody must go through and laboriously mark up the text with HTML to match the formatting of the original document. This is impractical and error-prone. I've tried programs like http://wvware.sourceforge.net/ and I've tried saving the original content as HTML and then running it through http://tidy.sourceforge.net/, but I've had no luck. They create webpages. I just want the inline markup converted, with no block-level or page-level tags. I figure that this can either happen by parsing a RTF file or through some JavaScript or OS-level magic, based on the text in the clipboard. This must be a common need for anybody building a CMS, and yet I can't find any solutions to the problem. Is there any widget (Flash, Java, whatever) into which I can paste formatted text and it will retain that formatting and generate HTML? Some command-line application that will do the same? Or do I need to -- god help me -- write my own PHP-based RTF parser?

  • Answer:

    I thought FCK editor put out decent code. Tidy with the http://tidy.sourceforge.net/docs/quickref.html#show-body-only option should help.

waldo at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

This WYSIWYG-meets-Tidy-meets-http://us3.php.net/strip-tags option sounds pretty compelling. Hideous. But compelling. :)

waldo

Perhaps I have been unfair. I shall read the manual and re-evaluate.

IndigoRain

IndigoRain, you're using HTML Tidy wrong. It's a powerful tool, but not if you skip reading the manual. :) You want to use the --wrap 0 flag.

waldo

Heh, center tags are funny.

If I Had An Anus

Yeah, "not pretty" is just about the best way to describe any *nix-based solution like this, for one simple reason: it's all based on the "no jacknives" theory. A program should do one thing, and do it well, rather than trying to do everything (and inevitably doing them all poorly). So you have a program that converts Word documents to HTML documents. You feed that into a program that beautifies/simplifies the HTML. Then you feed that into a program that strips out any unwanted tags. Combine it with an upload script, and a script to put the final output into the blog, and you've got yourself a real utility there.

CrayDrygu

CrayDrygu, I'm starting to think that you're right. It's not pretty, and it will still require post-processing with strip_tags (or regex, as you point out), but it may well work. I'm playing with it now. It may be a good 90% solution, which is better than the 0% where I'm at now. :) This makes me want to learn to write Firefox plugins, just so I can solve this problem for good.

waldo

The http://www.atlantiswordprocessor.com is a very capable RTF editor which produces nice clean HTML when you choose "Save as web page".

yclipse

Now, I haven't actually tried it, but it seems like wvWare and HTMLTidy did exactly what you want, except that it produced a whole page instead of just a chunk of HTML. Why not take the output from that, and trim out the <body> tag and everything before it, and the </body> tag and everything after? I don't remember my regular expressions, but I'm sure it could be done with sed.

CrayDrygu

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.