• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: styled text to html
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: styled text to html


  • Subject: Re: styled text to html
  • From: Jeremy Dronfield <email@hidden>
  • Date: Fri, 20 Feb 2004 22:19:49 +0000

I've found it, and it was right under my nose all the time - a ready-cooked method of turning RTF into HTML. It's in NSAttributedString-OAExtensions in OmniAppKit (even by Omni framework standards, this file is very thin on documentation). The method -htmlString parses RTF as Ryan suggested and returns a string of HTML code. Just do:

NSString *html = [[myTextView textStorage] htmlString];
BOOL saveSuccess = html ? [html writeToFile:filename atomically:YES] : NO;

And bingo - you've got HTML output. There are two drawbacks. It can't handle RTFD, and the representation of font sizes is slightly wonky, but it saves me a huge amount of very tedious coding. I'm going to see what I can do to extend it's capabilities.
-Jeremy.


On 20 Feb 2004, at 11:10 am, Jeremy Dronfield wrote:

You'd also want to maintain a template to hold it all in. This business of converting rich text to HTML is a task I've been looking into over the past couple of days. Does anybody know of any sample code which would help with parsing the text (and graphics)? I also wondered about the possibility of using NSPrintInfo (which I'm currently using to output text documents as PDF) - getting the style and layout data out of that and parsing it to HTML. I can't see a way to do it, though.

-Jeremy


On 20 Feb 2004, at 1:41 am, Ryan Bates wrote:

You can loop through every character in the text view's text storage and compare the attributes with the previous character's attributes. You can then insert the appropriate HTML tags depending upon what attributes changed.

Ryan

On Feb 19, 2004, at 1:53 PM, Sascha Kuehn wrote:

hi,

is it possible to convert the contents of a text view (different fonts, sizes and colors) into html code?
if yes, how can i do this?

sascha
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: styled text to html (mixin' it up)
      • From: Chilton Webb <email@hidden>
References: 
 >styled text to html (From: Sascha Kuehn <email@hidden>)
 >Re: styled text to html (From: Ryan Bates <email@hidden>)
 >Re: styled text to html (From: Jeremy Dronfield <email@hidden>)

  • Prev by Date: Re: [Slightly OT] Shareware donation collection
  • Next by Date: Re: SFAuthorizationView
  • Previous by thread: Re: styled text to html
  • Next by thread: Re: styled text to html (mixin' it up)
  • Index(es):
    • Date
    • Thread