Module: BitClust::DocConverter
- Defined in:
- lib/bitclust/doc_converter.rb
Overview
refm/doc(散文ページ)の Markdown 変換。
doc ページにはクロスファイル情報(library 所属等)が無いため、 オーケストレータは不要で、reduce(正規化)+ 単一ファイル変換のみ。 タイトルは H1 が担い、front matter は使わない。
reduce は意味を変えない表記ゆれを md→rd の再生成形に合わせる正規化と、 クロスツリー include(api 断片の transclude)の manual レイアウトへの 書き換えを行う。md→rd 変換は reduce の結果を復元する(検証の期待値)。
Class Method Summary collapse
- .convert(rrd) ⇒ Object
-
.files(doc_root) ⇒ Object
変換対象ファイルの一覧(doc ルート相対)。 旧パイプライン(copy_doc)は **/*.rd だけをページとして読むため、 .rd 以外は doc 内 include から参照される断片のみを対象にし、 参照されない死にファイル(news/1.8.0.rd-2 等)は凍結側に残す.
- .reduce(rrd) ⇒ Object
Class Method Details
.convert(rrd) ⇒ Object
41 42 43 |
# File 'lib/bitclust/doc_converter.rb', line 41 def convert(rrd) RRDToMarkdown.convert(reduce(rrd)) end |
.files(doc_root) ⇒ Object
変換対象ファイルの一覧(doc ルート相対)。 旧パイプライン(copy_doc)は **/*.rd だけをページとして読むため、 .rd 以外は doc 内 include から参照される断片のみを対象にし、 参照されない死にファイル(news/1.8.0.rd-2 等)は凍結側に残す
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bitclust/doc_converter.rb', line 49 def files(doc_root) all = Dir.glob('**/*', base: doc_root) .select { |f| File.file?(File.join(doc_root, f)) }.sort pages = all.select { |f| f.end_with?('.rd') } referenced = pages.flat_map { |f| base = File.dirname(f) File.read(File.join(doc_root, f)) .scan(/^\#@include\((?!(?:\.\.\/)+api\/)(.*?)\)/) .map { |t| File.(base == '.' ? (t[0] || raise) : File.join(base, t[0] || raise), '/') .delete_prefix('/') } } (pages + (all & referenced)).sort end |
.reduce(rrd) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bitclust/doc_converter.rb', line 18 def reduce(rrd) RRDToMarkdown.normalize_dlist_colon_spacing(rrd.lines.map { |line| case line when /\A\#@samplecode[ \t]+\n\z/ "\#@samplecode\n" # ラベル無しの末尾スペース when %r{\A//\}[ \t]+\n\z} "//}\n" when /\A:\s{2,}(.*)/m ": #{$1}" # 定義リスト term の余分なスペース when /\A(={1,4}\[a:[^\]]+\])\s{2,}(.*)/m "#{$1} #{$2}" # アンカー見出しの余分なスペース when /\A\t+/ line.sub(/\A\t+/) { ' ' * ($& || raise).length } # 行頭タブ(doc の散文1行のみ) when /\A\#@include\((?:\.\.\/)+api\/src\// # 旧レイアウト ../api/src/X → 新レイアウト ../api/X # (manual/ 配下では src 階層が無い。ブリッジが逆変換する) line.sub(%r{((?:\.\./)+)api/src/}, '\1api/') else line end }.join) end |