Class: Vivlio::Starter::Commands::PdfReadCommand
- Inherits:
-
Object
- Object
- Vivlio::Starter::Commands::PdfReadCommand
- Defined in:
- lib/vivlio/starter/cli/pdf/pdf_read_command.rb
Overview
PDF を Markdown に変換するコマンド
Standard Mode(テキストのみ)と Enhanced Mode(HexaPDF + 画像 + OCR)の2 段階で機能を提供する。vivlio-starter-pdf gem がインストール済みなら自動的に Enhanced Mode へ切り替わる。
Defined Under Namespace
Classes: Error, InvalidInputError, MissingPdfError
Constant Summary collapse
- NUMERIC_PILLAR_PREFIX_REGEX =
「1.2 見出しテキスト」形式の柱(ランニングヘッド)を検出する正規表現
/\A[0-90-9]+(?:[.-][0-90-9]+)*\.?\s+.+\z/- DASHED_PAGE_NUMBER_REGEX =
「— 42 —」形式のダッシュ付きページ番号を検出する正規表現
/\A[-–—]\s*[0-90-9ivxlcdmIVXLCDM]+\s*[-–—]\z/- SOURCES_DIR =
PDF 格納ディレクトリの既定名
'sources'- MAX_AUTO_CHAPTER =
自動割り当て章番号の上限(01〜98)
98
Instance Method Summary collapse
-
#call ⇒ Hash
PDF → Markdown 変換を実行する 入力を解決し、モードに応じて Standard / Enhanced の変換パイプラインを呼び出す.
-
#initialize(input, options = {}) ⇒ PdfReadCommand
constructor
A new instance of PdfReadCommand.
Constructor Details
#initialize(input, options = {}) ⇒ PdfReadCommand
Returns a new instance of PdfReadCommand.
43 44 45 46 47 48 49 50 |
# File 'lib/vivlio/starter/cli/pdf/pdf_read_command.rb', line 43 def initialize(input, = {}) @input = input.to_s.strip @options = || {} @resolver = CLI::TokenResolver::Resolver.new @catalog_entries = nil @plugin_checked = false @plugin_available = false end |
Instance Method Details
#call ⇒ Hash
PDF → Markdown 変換を実行する入力を解決し、モードに応じて Standard / Enhanced の変換パイプラインを呼び出す
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vivlio/starter/cli/pdf/pdf_read_command.rb', line 55 def call raise InvalidInputError, 'PDF を指定してください' if input.empty? entry, pdf_path = resolve_entry_and_pdf entry = ensure_unique_output_entry(entry) mode = resolved_mode log_enhanced_install_hint if mode == :standard ensure_entry_has_slug!(entry) add_catalog_entry_if_needed(entry) CLI::Common.log_action("[pdf:read] PDF からテキストを抽出します (#{entry.basename}, mode=#{mode})") result = mode == :enhanced ? convert_enhanced(pdf_path, entry) : convert_standard(pdf_path, entry) CLI::Common.log_success("[pdf:read] 変換が完了しました -> #{result[:markdown_path]}") { mode:, entry:, markdown_path: result[:markdown_path], source_pdf_path: pdf_path, pages: result[:pages] } end |