LoginSignup
1
1

More than 5 years have passed since last update.

PDFからコピーしたテキストの濁音を置換する

Last updated at Posted at 2016-10-12

PDFからテキストをコピーしてきた時に、濁音や半濁音が2文字に分解されたり、半角スペースが混じって困ることがないでしょうか?
僕は今、困ってます・・・。

「グッドデザイン」をコピーして貼り付けると「スクリーンショット-2015-12-16-18.06.02.png」となってしまうようなやつです。
※ ブラウザ上で見てもわかりにくかったので画像にしました

ほんとはAlfredのworkflowとか作るのがいいのでしょうが、作ったことないので、手っ取り早くSublime PluginのRegReplaceでなんとかすることにしました。
半角スペース除去と、濁音・半濁音の置換をするだけです。

Sublime\ Text\ 3/Packages/User/reg_replace.sublime-settings
Sublime\ Text\ 3/Packages/User/reg_replace_rules.sublime-settings
(追記:RegRepalce 3.0.0からファイル名が変わっていました)

reg_replace.sublime-settings
{
  "replacements": {
    "半角スペース": {"find": " ", "replace": ""},
    "ゔ": {"find": "ゔ", "replace": "ゔ"},
    "が": {"find": "が", "replace": "が"},
    "ぎ": {"find": "ぎ", "replace": "ぎ"},
    "ぐ": {"find": "ぐ", "replace": "ぐ"},
    "げ": {"find": "げ", "replace": "げ"},
    "ご": {"find": "ご", "replace": "ご"},
    "ざ": {"find": "ざ", "replace": "ざ"},
    "じ": {"find": "じ", "replace": "じ"},
    "ず": {"find": "ず", "replace": "ず"},
    "ぜ": {"find": "ぜ", "replace": "ぜ"},
    "ぞ": {"find": "ぞ", "replace": "ぞ"},
    "だ": {"find": "だ", "replace": "だ"},
    "ぢ": {"find": "ぢ", "replace": "ぢ"},
    "づ": {"find": "づ", "replace": "づ"},
    "で": {"find": "で", "replace": "で"},
    "ど": {"find": "ど", "replace": "ど"},
    "ば": {"find": "ば", "replace": "ば"},
    "び": {"find": "び", "replace": "び"},
    "ぶ": {"find": "ぶ", "replace": "ぶ"},
    "べ": {"find": "べ", "replace": "べ"},
    "ぼ": {"find": "ぼ", "replace": "ぼ"},
    "ぱ": {"find": "ぱ", "replace": "ぱ"},
    "ぴ": {"find": "ぴ", "replace": "ぴ"},
    "ぷ": {"find": "ぷ", "replace": "ぷ"},
    "ぺ": {"find": "ぺ", "replace": "ぺ"},
    "ぽ": {"find": "ぽ", "replace": "ぽ"},
    "ヴ": {"find": "ヴ", "replace": "ヴ"},
    "ガ": {"find": "ガ", "replace": "ガ"},
    "ギ": {"find": "ギ", "replace": "ギ"},
    "グ": {"find": "グ", "replace": "グ"},
    "ゲ": {"find": "ゲ", "replace": "ゲ"},
    "ゴ": {"find": "ゴ", "replace": "ゴ"},
    "ザ": {"find": "ザ", "replace": "ザ"},
    "ジ": {"find": "ジ", "replace": "ジ"},
    "ズ": {"find": "ズ", "replace": "ズ"},
    "ゼ": {"find": "ゼ", "replace": "ゼ"},
    "ゾ": {"find": "ゾ", "replace": "ゾ"},
    "ダ": {"find": "ダ", "replace": "ダ"},
    "ヂ": {"find": "ヂ", "replace": "ヂ"},
    "ヅ": {"find": "ヅ", "replace": "ヅ"},
    "デ": {"find": "デ", "replace": "デ"},
    "ド": {"find": "ド", "replace": "ド"},
    "バ": {"find": "バ", "replace": "バ"},
    "ビ": {"find": "ビ", "replace": "ビ"},
    "ブ": {"find": "ブ", "replace": "ブ"},
    "ベ": {"find": "ベ", "replace": "ベ"},
    "ボ": {"find": "ボ", "replace": "ボ"},
    "パ": {"find": "パ", "replace": "パ"},
    "ピ": {"find": "ピ", "replace": "ピ"},
    "プ": {"find": "プ", "replace": "プ"},
    "ペ": {"find": "ペ", "replace": "ペ"},
    "ポ": {"find": "ポ", "replace": "ポ"},
    "Ⅱ": {"find": "II", "replace": "Ⅱ"}
  }
}

※ 表示フォントによって、findの値が一文字に見えるかもしれませんが、「か」+「”」みたいになってます。

Sublime\ Text\ 3/Packages/User/Default.sublime-commands

Default.sublime-commands
[
  {
    "caption": "Reg Replace: PDFからコピーしたテキストを復元",
    "command": "reg_replace",
    "args": {"replacements": ["半角スペース","ゔ","が","ぎ","ぐ","げ","ご","ざ","じ","ず","ぜ","ぞ","だ","ぢ","づ","で","ど","ば","び","ぶ","べ","ぼ","ぱ","ぴ","ぷ","ぺ","ぽ","ヴ","ガ","ギ","グ","ゲ","ゴ","ザ","ジ","ズ","ゼ","ゾ","ダ","ヂ","ヅ","デ","ド","バ","ビ","ブ","ベ","ボ","パ","ピ","プ","ペ","ポ","Ⅱ"]}
  }
]

これで、コマンドパレットから”Reg Replace: PDFからコピーしたテキストを復元”を実行すれば、一発で変換してくれます。
Sublime立ちあげなきゃいけなかったり、複数の検索置換に適したもっといいプラグインあるかもしれませんが(設定が冗長・・・)。


この記事は2015.12.16にこちらのURLで公開していた内容を移行しました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1