Help us understand the problem. What is going on with this article?

Cocoaの機能を使ってHTML文字列をプレーンテキストに変換するAppleScriptハンドラ

More than 3 years have passed since last update.
  • do shell scriptと違って文字数制限がないので使いやすい
  • 文字化けする場合はdataUsingEncoding:メソッドの引数を変更
convertHTMLToPlainText.scpt
use scripting additions
use framework "AppKit"

tell application "Safari"
    my convertHTMLToPlainText(source of current tab of window 1)
end tell

on convertHTMLToPlainText(HTML)
    --require framework: Foundation
    set attributedString to my attributedStringOfHTMLText(HTML)
    return attributedString's |string| as text
end convertHTMLToPlainText

on attributedStringOfHTMLText(HTML as text)
    --require framework: AppKit, Foundation
    set HTMLString to current application's NSString's stringWithString:HTML
    set HTMLData to HTMLString's dataUsingEncoding:(current application's NSUnicodeStringEncoding)
    return current application's NSAttributedString's alloc()'s initWithHTML:HTMLData documentAttributes:(missing value)
end attributedStringOfHTMLText

更新履歴

  • 2016-01-27: CocoaのAppKitフレームワークにあるNSAttributedStringクラスを使って作成
  • 2016-02-01: attributedStringOfHTMLTextハンドラ作成
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away