Formatting text in NSTextView - cocoa-touch

I have a case where i'm getting formatted text with <a href ...>, <em>, <br>, ", etc tags, and i'm showing it in a Text View. How can i apply these formats? If i can't, whats the most generic way to remove all these tags?
Thanks,
Mustafa
No, i just want to show the formatted text in non editable NSTextView. or maybe UIWebView, will it automatically handle tags like <em>?

If you want editable text you will have to parse it using a library like Tidy to get just an NSString and then pass that to UITextView's -setText: method
If you need to display HTML, use UIWebView.
If you want to edit HTML as formatted text you will have to roll your own or use private API's.

Related

Sitefinity Text line breaks

In my model I have text with tag where I would like to replace it with a html tag. I did search and show that using Html.Encode may work but that didnt work.
is there another way to do this in the cshtml file?
#Html.Encode(Model.Desceiption).Replace("<cr>", "<br>")
I think you want
#Html.Raw(...)

Toggle vue2-editor view content to html

I am using vue2-editor and i want to toggle the content view of the editor like ckeditor or mailchimp editor does
It is possible using vue2-editor or quill?
You can have a computed property that either returns the actual text or uses a library like hypertext to generate html, the return value of the html would be contingent on another computed property and returns the html you want.
I also have a simpler solution, which I used once but need to take a look at my code in a few hours which is not in front of me.

How do I wrap text in DDX

I have dynamic content i'm outputting in a Footer element in a PDF w/ DDX & Coldfusion. Some of the records have long text, and do not automatically wrap, I have placed tags, tried padding/margin, all to no avail.
Any ideas?
It should be easy with <cfdocument format="PDF">. Maybe have org.pdf converted into an image using the make thumbnail action, then use cfdocument and HTML to style the footer? Not most efficient, but easiest.

Objective-C: Formatting text in a string object within a plist

I am a new objective-c/iPhone developer and am wondering if there is any way to apply formatting to text within a string in a plist?
I have a plist that is an array of dictionaries. Each dictionary contains a few string objects, some of which I would like to contain lists and paragraphs of information. I am calling these strings and displaying them via labels in the UI.
Similar to using <li> and </li> or <b> and </b> in html, I would like to be able to specify parts of a string to be formatted when displayed as a bulleted list, bold, italic, etc.. How could this be accomplished?
With the help of some kind users on this site, I was able to embed the <li> and <b> tags within the xml plist file, however this just resulted in literally printing the tags on the screen.
Thanks in advance for your help!!
It doesn't sound like the fact that your strings are in a plist has much to do with the issue. You'll be storing them that way regardless. But if you want to render HTML-like formatting inside your UI, you have two choices:
Parse the data into an
NSAttributedString, which is
available starting in iOS 3.2. I
believe you'll have to figure out
how to get from the HTML
representation to the right
attributes in the string.
Use a UIWebView and render your HTML directly. This sounds heavyweight, esp for labels, and it probably would be, but you could try.
(Gist here is that there isn't a trivial answer to your question-- the Cocoa frameworks don't natively speak much HTML, and intra-string formatting isn't something that's necessarily easily done.)
For HTML markup to work, you'll need to display the text in a UIWebView, not a UILabel. Check out the UIWebView documentation here.
Update: In response to the other answer, I don't believe UILabel will correctly display an NSAttributedString even on iOS 4. Apple's recommended approach to doing styled text is to use a UIWebView (or draw the text yourself using Core Text, which is significantly more complicated).

Alter Rendered Page in Webbrowser Control

is there a way to alter the rendered HTML page in webbrowser control? What i need is to alter the rendered HTML Page in my webbrowser control to highlight selected text.
What i did is use a webclient and use the webclient.Downloadstring() to get the source code of the page, Highlight specific text then write it again in webbrowser. problm is, images along with that page does not appear since they are rendered as relative path.
Is there a way to solve this problem? Is there a way to detect images in a webbrowser control?
Not sure why you need to change the HTML to lighlight text, why not use IHighlightRenderingServices?
To specify a base url when loading HTML string you need to use the document's IPersistMoniker interface and specify a url in your IMoniker implementation.
I suggest you do it a different way, download and replace the text using the webbrowser control, this way your links will work. All you do is replace whatever is in the Search TextBox with the following, say the search term is "hello", then you replace all occurances of hello with the following:
<font color="yellow">hello</font>
Of course, this HTML can be replaced with the SPAN tag (which is an inline version of the DIV tag, so your lines wont break using SPAN, but will using DIV). But in either case, both these tags have a style attribute, where you can use CSS to change its color or a zillion other properties that are CSS compatible, like follows:
<SPAN style="background-color: yellow;">hello</SPAN>
Of course, there are a zillion other ways to change color using HTML, feel free to search the web for more if you want.
Now, you can use the .Replace() function in dotnet to do this (replace the searched text), it's very easy. So, you can Get the Whole document as a string using .DocumentText, and once all occurances are replaced (using .Replace()), you can set it back to .DocumentText (so, you're using .DocumentText to get the original string, and setting .DocumentText with the replaced string). Of course, you probably don't want to do this to items inside the actual HTML, so you can just loop through all the elements on the page by doing a For Each loop over all elements like below:
For Each someElement as HTMLElement in WebBrowser1.Document.All
And each element will have a .InnerText/.InnerHTML and .OuterText/.OuterHTML that you can Get (read from) and Set (overwrite with replaced text).
Of course, for your needs, you'd probably just want to be replacing and overwriting the .InnerText and/or the .OuterText.
If you need more help, let me know. In either case, i'd like to know how it worked out for you anyway, or if there is anything more any of us can do to add value to your problem. Cheers.