Class: VivlioStarter::CLI::Techbook::Processor
- Inherits:
-
Object
- Object
- VivlioStarter::CLI::Techbook::Processor
- Defined in:
- lib/vivlio_starter/cli/techbook/processor.rb
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(config) ⇒ Processor
constructor
A new instance of Processor.
-
#inject_css ⇒ String
Techbook 用 CSS(絵文字スタイル + 可変フォント静的インスタンス)を返す.
-
#post_process_html_files!(html_files = nil, inject_css: true) ⇒ Object
生成済み HTML に対して Techbook 後処理を適用する。 Step 5c と Step 9 後の両方から呼ばれるため、CSS 注入は既存ブロックを置換して冪等にする。.
-
#process(html) ⇒ String
HTML 中の絵文字を Twemoji SVG に差し替え、Type 3 フォント化する文字を置換する.
Constructor Details
#initialize(config) ⇒ Processor
Returns a new instance of Processor.
16 17 18 19 |
# File 'lib/vivlio_starter/cli/techbook/processor.rb', line 16 def initialize(config) @config = config @techbook = config.dig(:output, :pdf, :techbook) == true end |
Instance Method Details
#enabled? ⇒ Boolean
21 |
# File 'lib/vivlio_starter/cli/techbook/processor.rb', line 21 def enabled? = @techbook |
#inject_css ⇒ String
Techbook 用 CSS(絵文字スタイル + 可変フォント静的インスタンス)を返す
48 49 50 51 52 53 54 55 56 |
# File 'lib/vivlio_starter/cli/techbook/processor.rb', line 48 def inject_css return "" unless enabled? css_parts = [] css_parts << emoji_css font_css = VariableFontInjector.new(variable_font_configs).css css_parts << font_css unless font_css.empty? css_parts.join("\n") end |
#post_process_html_files!(html_files = nil, inject_css: true) ⇒ Object
生成済み HTML に対して Techbook 後処理を適用する。 Step 5c と Step 9 後の両方から呼ばれるため、CSS 注入は既存ブロックを置換して冪等にする。
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vivlio_starter/cli/techbook/processor.rb', line 62 def post_process_html_files!(html_files = nil, inject_css: true) return unless enabled? files = Array(html_files || Dir.glob(File.join(Common::BUILD_HTML_DIR, '*.html'))) .select { File.file?(it) }.sort return if files.empty? ensure_generated_assets! rewrite_svg_references!(files) normalize_heading_marker_spans!(files) normalize_circled_number_spans!(files) replace_emoji_and_type3_prone_chars!(files) inject_css_into_files!(files) if inject_css end |
#process(html) ⇒ String
HTML 中の絵文字を Twemoji SVG に差し替え、Type 3 フォント化する文字を置換する
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vivlio_starter/cli/techbook/processor.rb', line 26 def process(html) return html unless enabled? # --- Phase: 全角チルダ → 波ダッシュ正規化 --- # 同梱 Zen フォント(Old Mincho / Kaku Gothic New)は U+301C(波ダッシュ)を # 収録するが U+FF5E(全角チルダ)を収録しない。全角チルダはキーボードから # 入力しやすく原稿に混入するため、Zen が描画できる U+301C へ正規化する。 # (さもないと Chromium が OS フォントへフォールバックし、Chrome 149 が # それを Type 3 フォントとして埋め込む。字形は同一。) html = html.gsub("\uFF5E", "\u301C") # --- Phase: 囲み数字 → ラスタ画像化 --- # ①〜⑳ は環境によって Chromium が Type 3 フォント化しやすいため、 # 事前生成した WebP 画像に置換する。 html = replace_circled_numbers(html) # --- Phase: 絵文字 SVG 差し替え --- EmojiReplacer.new.process(html) end |