| 1 | |
|---|
| 2 | #= block article |
|---|
| 3 | #? article.4meのデフォルトルート要素 |
|---|
| 4 | # |
|---|
| 5 | #:Author: FURUHASHI Sadayuki |
|---|
| 6 | # |
|---|
| 7 | #== 対応フォーマット |
|---|
| 8 | # すべてのフォーマット |
|---|
| 9 | # |
|---|
| 10 | #== 書式 |
|---|
| 11 | # 書式無し |
|---|
| 12 | # |
|---|
| 13 | # 子要素を展開する。 |
|---|
| 14 | # |
|---|
| 15 | |
|---|
| 16 | # ブロック要素の:article要素を作る |
|---|
| 17 | f = Format.block :article |
|---|
| 18 | |
|---|
| 19 | # :article要素は:body要素、:body要素と、:@blankグループに |
|---|
| 20 | # 属する要素を子要素にすることができる |
|---|
| 21 | # グループ名は@から始まる |
|---|
| 22 | f.contain :head, :body, :@blank |
|---|
| 23 | |
|---|
| 24 | # デフォルトの変換メソッド |
|---|
| 25 | f.process_default {|text, children| |
|---|
| 26 | # childrenは、子要素を展開したもの |
|---|
| 27 | # :articleは:head要素、:block要素、:@blankグループに |
|---|
| 28 | # 属する要素を含むことができる |
|---|
| 29 | children |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | # HTMLに変換する変換メソッド |
|---|
| 33 | f.process_html {|text, children| |
|---|
| 34 | # XML[]は、正確なタグを作成する(<や>などの文字を<や>に変換する処理も自動的に行う) |
|---|
| 35 | # XML[:タグ名, {属性名 => 属性値, 属性名 => 属性値, ...}, 子要素, 子要素, 子要素, ...] |
|---|
| 36 | # 属性が一つもなければ、{}は省略可能 |
|---|
| 37 | # 子要素には文字列の他に、 [:タグ名, {属性名 => 属性値, ...}, 子要素, ...] を含めることができ、 |
|---|
| 38 | # そうすると入れ子になったタグになる |
|---|
| 39 | # 例: ↓ |
|---|
| 40 | %[<?xml version="1.0" encoding="UTF-8" ?>] + |
|---|
| 41 | %[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">] + |
|---|
| 42 | XML[:html, {:xmlns => 'http://www.w3.org/1999/xhtml'}, children] |
|---|
| 43 | # <html xmlns="http://www.w3.org/1999/xhtml">ここに:article要素の子要素が入る</html> |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | # SmartDocに変換する変換メソッド |
|---|
| 47 | f.process_smartdoc {|text, children| |
|---|
| 48 | %[<?xml version="1.0" encoding="UTF-8" ?>] + |
|---|
| 49 | XML[:doc, children] |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | # DocBookに変換する変換メソッド |
|---|
| 53 | f.process_docbook {|text, children| |
|---|
| 54 | %[<?xml version="1.0" encoding="UTF-8" ?>] + |
|---|
| 55 | XML[:article, |
|---|
| 56 | {:xmlns => 'http://docbook.org/ns/docbook', 'xmlns:xlink' => 'http://www.w3.org/1999/xlink', :version => '5.0'}, |
|---|
| 57 | children] |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | # InDesign用XMLに変換する変換メソッド |
|---|
| 61 | f.process_inddxml {|text, children| |
|---|
| 62 | %[<?xml version="1.0" encoding="UTF-8" ?>] + |
|---|
| 63 | XML[:article, |
|---|
| 64 | { 'xmlns:aid' => 'http://ns.adobe.com/AdobeInDesign/4.0/', |
|---|
| 65 | 'xmlns:aid3' => 'http://ns.adobe.com/AdobeInDesign/3.0/', |
|---|
| 66 | 'xmlns:aid5' => 'http://ns.adobe.com/AdobeInDesign/5.0/'}, |
|---|
| 67 | children] |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | # それ以外のフォーマットに変換するデフォルト変換メソッド |
|---|
| 71 | f.process_default {|text, children| |
|---|
| 72 | children |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | #= block head |
|---|
| 78 | #? ヘッダのコンテナ |
|---|
| 79 | # |
|---|
| 80 | #:Author: FURUHASHI Sadayuki |
|---|
| 81 | # |
|---|
| 82 | #== 対応フォーマット |
|---|
| 83 | #| *HTML OK |
|---|
| 84 | #| *SmartDoc OK |
|---|
| 85 | #| *DocBook OK |
|---|
| 86 | #| *はてな記法 OK 子要素を展開するだけ |
|---|
| 87 | # |
|---|
| 88 | #== 書式 |
|---|
| 89 | # 書式無し |
|---|
| 90 | # |
|---|
| 91 | # 子要素を展開する。 |
|---|
| 92 | # |
|---|
| 93 | |
|---|
| 94 | # :head要素 |
|---|
| 95 | f = Format.block :head |
|---|
| 96 | # :@headersグループに属する要素と、:@blankグループに属する要素を |
|---|
| 97 | # 子要素にすることができる |
|---|
| 98 | f.contain :@headers, :@blank |
|---|
| 99 | |
|---|
| 100 | # 変換メソッド |
|---|
| 101 | f.process_html {|text, children| |
|---|
| 102 | XML[:head, |
|---|
| 103 | [:meta, {'http-equiv' => 'content-type', 'content' => 'application/xhtml+xml; charset=UTF-8'}], |
|---|
| 104 | [:meta, {'http-equiv' => 'content-style-type', 'content' => 'text/css'}], |
|---|
| 105 | [:meta, {'http-equiv' => 'content-script-type', 'content' => 'text/javascript'}], |
|---|
| 106 | children |
|---|
| 107 | ] |
|---|
| 108 | } |
|---|
| 109 | f.process_smartdoc {|text, children| |
|---|
| 110 | XML[:head, children] |
|---|
| 111 | } |
|---|
| 112 | f.process_docbook {|text, children| |
|---|
| 113 | XML[:info, children] |
|---|
| 114 | } |
|---|
| 115 | f.process_default {|text, children| |
|---|
| 116 | children |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | #= block body |
|---|
| 122 | #? 本文のコンテナ |
|---|
| 123 | # |
|---|
| 124 | #:Author: FURUHASHI Sadayuki |
|---|
| 125 | # |
|---|
| 126 | #== 対応フォーマット |
|---|
| 127 | #| *HTML OK |
|---|
| 128 | #| *SmartDoc OK |
|---|
| 129 | #| *DocBook OK |
|---|
| 130 | #| *InDesign XML OK |
|---|
| 131 | #| *はてな記法 OK 子要素を展開するだけ |
|---|
| 132 | # |
|---|
| 133 | #== 書式 |
|---|
| 134 | # 書式無し |
|---|
| 135 | # |
|---|
| 136 | # 子要素を展開する。 |
|---|
| 137 | # |
|---|
| 138 | |
|---|
| 139 | # :body要素 |
|---|
| 140 | f = Format.block :body |
|---|
| 141 | # :@contentsグループに属する要素と、:@blankグループに属する |
|---|
| 142 | # 要素と、:chapter要素、:part要素を含むことができる |
|---|
| 143 | f.contain :@contents, :@pagers, :@blank, :chapter, :part |
|---|
| 144 | |
|---|
| 145 | # 変換メソッド |
|---|
| 146 | f.process_html {|text, children| |
|---|
| 147 | XML[:body, children] |
|---|
| 148 | } |
|---|
| 149 | f.process_smartdoc {|text, children| |
|---|
| 150 | XML[:body, children] |
|---|
| 151 | } |
|---|
| 152 | f.process_docbook {|text, children| |
|---|
| 153 | children |
|---|
| 154 | } |
|---|
| 155 | f.process_inddxml {|text, children| |
|---|
| 156 | children |
|---|
| 157 | } |
|---|
| 158 | f.process_default {|text, children| |
|---|
| 159 | children |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|