Class: CBETA::P5aParser
- Inherits:
-
Object
- Object
- CBETA::P5aParser
- Defined in:
- lib/cbeta/p5a_parser.rb
Instance Method Summary collapse
-
#handle_note(e, mode = 'html') ⇒ Hash
- :content [String] 要放在本文中的文字, 如果 mode=='html', 那麼本文文字會包含 footnote anchor * :footnote_text [String] 要放在 footnote 的文字 * :footnote_resp [String] * 'orig': 表示這個註解是底本的註 * 'CBETA': 表示這個註解是 CBETA 修訂過的註.
-
#initialize(xml_string, children_handler) ⇒ P5aParser
constructor
A new instance of P5aParser.
Constructor Details
#initialize(xml_string, children_handler) ⇒ P5aParser
Returns a new instance of P5aParser.
16 17 18 19 20 |
# File 'lib/cbeta/p5a_parser.rb', line 16 def initialize(xml_string, children_handler) @doc = Nokogiri::XML(s) @doc.remove_namespaces!() @children_handler = children_handler end |
Instance Method Details
#handle_note(e, mode = 'html') ⇒ Hash
Returns * :content [String] 要放在本文中的文字, 如果 mode=='html', 那麼本文文字會包含 footnote anchor
- :footnote_text [String] 要放在 footnote 的文字
- :footnote_resp [String]
- 'orig': 表示這個註解是底本的註
- 'CBETA': 表示這個註解是 CBETA 修訂過的註.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cbeta/p5a_parser.rb', line 30 def handle_note(e, mode='html') r = { content: '', footnote_resp: nil, footnote_text: nil } n = e['n'] if e.has_attribute?('type') t = e['type'] case t when 'equivalent' then return r when 'orig' then return handle_note_orig(e, mode) when 'orig_biao' then return handle_note_orig(e, mode, 'biao') when 'orig_ke' then return handle_note_orig(e, mode, 'ke') when 'mod' r[:footnote_resp] = 'CBETA' r[:footnote_content] = @children_handler.call(e) if mode == 'html' r[:content] = "<a class='noteAnchor' href='#n#{n}'></a>" end return r when 'rest' then return r else return r if t.start_with?('cf') end end if e.has_attribute?('resp') return r if e['resp'].start_with? 'CBETA' end s = @children_handler.call(e) r[:content] = s if e.has_attribute?('place') && e['place']=='inline' if mode == 'html' r[:content] = "<span class='doube-line-note'>#{s}</span>" end end r end |