Class: VivlioStarter::CLI::PreProcessCommands::MarkdownPreprocessor

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio_starter/cli/pre_process/markdown_preprocessor.rb

Overview

Markdown 前処理を段階的に実行するクラス

Constant Summary collapse

TABLE_CONTAINER_CLASSES =

テーブルコンテナのクラス名(long-table との語順統一で rotate-table を採用)。

%w[long-table rotate-table].freeze
INVALID_PAGEBREAK_PATTERN =

マッチしないため、放置すると生テキストのまま紙面に出る(§2.2 の否定先読みの裏面)。

/@pagebreak:(?!(?:recto|verso)\b)([\w-]*)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(md_file, entry) ⇒ MarkdownPreprocessor

Returns a new instance of MarkdownPreprocessor.

Parameters:

  • md_file (String)

    Markdown ファイルパス

  • entry (TokenResolver::Entry)

    章情報を持つ Entry オブジェクト



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/vivlio_starter/cli/pre_process/markdown_preprocessor.rb', line 72

def initialize(md_file, entry)
  filename = File.basename(md_file)
  @context = PreProcessContext.new(
    source_path: md_file,
    # 中間 .md はルートではなくワークスペースの html/ へ書く(P4 §3.4-1)
    output_path: File.join(Common::BUILD_HTML_DIR, filename),
    filename: filename,
    file_type: entry.kind.to_s,
    chapter_number: entry.number,
    content: File.read(md_file, encoding: 'utf-8')
  )
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



61
62
63
# File 'lib/vivlio_starter/cli/pre_process/markdown_preprocessor.rb', line 61

def context
  @context
end

Instance Method Details

#runObject

指定Markdownの前処理パイプラインを順次実行する



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/vivlio_starter/cli/pre_process/markdown_preprocessor.rb', line 86

def run
  Common.log_info("#{context.source_path}#{context.output_path}")
  validate_directives!
  validate_links!
  apply_frontmatter!
  strip_html_comments!
  transform_terminal_blocks!
  process_data_streams!
  normalize_image_paths!
  transform_qr_codes!
  validate_images!
  transform_showcases!
  transform_mermaid!
  transform_talk!
  process_code_includes!
  detect_plain_math!
  transform_math!
  normalize_html_block_boundaries!
  escape_inline_code_html!
  transform_text_right_inlines!
  transform_spacing_markers!
  transform_text_align_containers!
  transform_book_cards!
  transform_tables!
  normalize_container_fences!
  transform_fancy_lists!
  transform_definition_lists!
  transform_links!
  expose_container_footnotes!
  strip_index_markup!
  write_output!
end