notroff 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/notroff/docbook_renderer.rb +13 -1
- data/lib/notroff/html_renderer.rb +10 -0
- data/lib/notroff/odt_renderer.rb +4 -0
- data/lib/notroff/tokenize.rb +8 -2
- metadata +1 -1
@@ -16,7 +16,8 @@ class DocbookRenderer < Processor
|
|
16
16
|
format( paragraph )
|
17
17
|
end
|
18
18
|
@book = Element.new('book')
|
19
|
-
@book.add_namespace('http://docbook.org/ns/docbook')
|
19
|
+
@book.add_namespace( 'http://docbook.org/ns/docbook')
|
20
|
+
@book.add_namespace('xl', 'http://www.w3.org/1999/xlink')
|
20
21
|
@book.add_attribute('version', '5.0')
|
21
22
|
@book.add_element element_for('title', @title)
|
22
23
|
@book.add_element element_for('author', @author)
|
@@ -135,11 +136,22 @@ class DocbookRenderer < Processor
|
|
135
136
|
element.add_text( token.string )
|
136
137
|
when :footnote
|
137
138
|
element.add(footnote_for(token.string))
|
139
|
+
when :link
|
140
|
+
element.add(link_element_for(token.string))
|
138
141
|
else
|
139
142
|
raise "Dont know what to do with #{token}"
|
140
143
|
end
|
141
144
|
end
|
142
145
|
|
146
|
+
def link_element_for(link_token)
|
147
|
+
text, url = parse_link(link_token)
|
148
|
+
link = Element.new('link')
|
149
|
+
add_body_text(link, text)
|
150
|
+
link.add_attribute('xl:href', url)
|
151
|
+
link
|
152
|
+
end
|
153
|
+
|
154
|
+
|
143
155
|
def footnote_for( text )
|
144
156
|
fn = Element.new('footnote')
|
145
157
|
fn.add_element(element_for('para', text))
|
@@ -71,11 +71,21 @@ class HtmlRenderer < Processor
|
|
71
71
|
element.add_text(token.string)
|
72
72
|
when :footnote
|
73
73
|
add_body_text(" [#{token.string}] ", element)
|
74
|
+
when :link
|
75
|
+
element.add(anchor_element_for(token))
|
74
76
|
else
|
75
77
|
raise "Dont know what to do with type #{token[:type]} - #{token}"
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
81
|
+
def anchor_element_for(link_token)
|
82
|
+
text, url = parse_link(link_token)
|
83
|
+
anchor = Element.new('a')
|
84
|
+
add_body_text(text, anchor)
|
85
|
+
anchor.add_attribute('href', url)
|
86
|
+
anchor
|
87
|
+
end
|
88
|
+
|
79
89
|
def code_element(type, text)
|
80
90
|
element = Element.new('code')
|
81
91
|
pre_element = Element.new('pre')
|
data/lib/notroff/odt_renderer.rb
CHANGED
@@ -99,6 +99,10 @@ class OdtRenderer < Processor
|
|
99
99
|
element.add_text( token.string )
|
100
100
|
when :footnote
|
101
101
|
element.add( footnote_for( token.string ) )
|
102
|
+
when :link
|
103
|
+
text, url = parse_link(token)
|
104
|
+
add_body_text(text, element)
|
105
|
+
element.add_text( " (#{url}) " )
|
102
106
|
else
|
103
107
|
raise "Dont know what to do with #{token}"
|
104
108
|
end
|
data/lib/notroff/tokenize.rb
CHANGED
@@ -3,7 +3,7 @@ require 'rexml/document'
|
|
3
3
|
module Tokenize
|
4
4
|
def tokenize_body_text( text )
|
5
5
|
text = text.dup
|
6
|
-
re = /\~\~.*?\~\~|\@\@.*?\@\@+|\{\{.*?\}\}
|
6
|
+
re = /\~\~.*?\~\~|\@\@.*?\@\@+|\{\{.*?\}\}|!!.*?!!|\^\^.+\^\^/
|
7
7
|
results = []
|
8
8
|
until text.empty?
|
9
9
|
match = re.match( text )
|
@@ -32,7 +32,13 @@ module Tokenize
|
|
32
32
|
:footnote
|
33
33
|
when /^!/
|
34
34
|
:bold
|
35
|
-
|
35
|
+
when /^\^/
|
36
|
+
:link
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse_link(link_token)
|
41
|
+
link_token.split('->').map {|s| s.strip}
|
36
42
|
end
|
37
43
|
|
38
44
|
def token_text( token )
|