Removing HTML Markup from Text
When parsing HTML content, it’s often necessary to remove markup entirely. The handler in Listing 34-1 removes all HTML tags from the text provided, returning only the remaining text—the contents of the tags.
APPLESCRIPT
on removeMarkupFromText(theText)set tagDetected to falseset theCleanText to ""repeat with a from 1 to length of theTextset theCurrentCharacter to character a of theTextif theCurrentCharacter is "<" thenset tagDetected to trueelse if theCurrentCharacter is ">" thenset tagDetected to falseelse if tagDetected is false thenset theCleanText to theCleanText & theCurrentCharacter as stringend ifend repeatreturn theCleanTextend removeMarkupFromText
Listing 34-2 shows how to call the handler in Listing 34-1.
APPLESCRIPT
set theText to "<a href=\"http://www.apple.com/mac\">This is a <B>great</B> time to own a Mac!</a>"removeMarkupFromText(theText)--> Result: "This is a great time to own a Mac!"
Copyright © 2018 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-06-13
