ronn 0.6.0 → 0.6.6

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/CHANGES CHANGED
@@ -1,8 +1,14 @@
1
1
  Ronn CHANGES
2
2
  ============
3
3
 
4
- Version 0.6 (not yet released)
5
- ------------------------------
4
+ Version 0.6.6 (2010 June 13)
5
+ ----------------------------
6
+
7
+ Small bug fix release fixes whitespace stripping between adjacent
8
+ inline elements in roff output (adamv, rtomayko)
9
+
10
+ Version 0.6 (2010 June 13)
11
+ --------------------------
6
12
 
7
13
  Features:
8
14
 
data/Rakefile CHANGED
@@ -82,6 +82,8 @@ task :rev do
82
82
  data = File.read('lib/ronn.rb')
83
83
  data.gsub!(/^( *)REV *=.*/, "\\1REV = '#{rev}'")
84
84
  File.open('lib/ronn.rb', 'wb') { |fd| fd.write(data) }
85
+ puts "revision: #{rev}"
86
+ puts "version: #{`ruby -Ilib -rronn -e 'puts Ronn::VERSION'`}"
85
87
  end
86
88
 
87
89
  require 'rubygems'
@@ -10,7 +10,7 @@ module Ronn
10
10
  end
11
11
 
12
12
  # bring REV up to date with: rake rev
13
- REV = '0.6.0'
13
+ REV = '0.6-6-gd7645f2'
14
14
  VERSION = REV[/(?:[\d.]+)(?:-\d+)?/].tr('-', '.')
15
15
 
16
16
  def self.release?
@@ -4,6 +4,7 @@ require 'hpricot'
4
4
  require 'rdiscount'
5
5
  require 'ronn/roff'
6
6
  require 'ronn/template'
7
+ require 'ronn/utils'
7
8
 
8
9
  module Ronn
9
10
  # The Document class can be used to load and inspect a ronn document
@@ -15,6 +16,8 @@ module Ronn
15
16
  # generated documentation unless overridden by the information
16
17
  # extracted from the document's name section.
17
18
  class Document
19
+ include Ronn::Utils
20
+
18
21
  attr_reader :path, :data
19
22
 
20
23
  # The man pages name: usually a single word name of
@@ -318,7 +321,7 @@ module Ronn
318
321
  contents = $1
319
322
  tag, attrs = contents.split(' ', 2)
320
323
  if attrs =~ /\/=/ ||
321
- HTML.include?(tag.sub(/^\//, '')) ||
324
+ html_element?(tag.sub(/^\//, '')) ||
322
325
  data.include?("</#{tag}>")
323
326
  match.to_s
324
327
  else
@@ -340,16 +343,6 @@ module Ronn
340
343
  end
341
344
  data
342
345
  end
343
-
344
- HTML = %w[
345
- a abbr acronym b bdo big br cite code dfn
346
- em i img input kbd label q samp select
347
- small span strong sub sup textarea tt var
348
- address blockquote div dl fieldset form
349
- h1 h2 h3 h4 h5 h6 hr noscript ol p pre
350
- table ul
351
- ].to_set
352
-
353
346
  private
354
347
  def parse_html(html)
355
348
  if html.respond_to?(:doc?) && html.doc?
@@ -1,13 +1,18 @@
1
1
  require 'hpricot'
2
+ require 'ronn/utils'
2
3
 
3
4
  module Ronn
4
5
  class RoffFilter
6
+ include Ronn::Utils
7
+
5
8
  # Convert Ronn HTML to roff.
6
9
  def initialize(html, name, section, tagline, manual=nil, version=nil, date=nil)
7
10
  @buf = []
8
11
  title_heading name, section, tagline, manual, version, date
9
- html = Hpricot(html)
10
- block_filter(normalize_whitespace(html))
12
+ doc = Hpricot(html)
13
+ remove_extraneous_elements! doc
14
+ normalize_whitespace! doc
15
+ block_filter doc
11
16
  write "\n"
12
17
  end
13
18
 
@@ -38,30 +43,50 @@ module Ronn
38
43
  def title_heading(name, section, tagline, manual, version, date)
39
44
  comment "generated with Ronn/v#{Ronn::VERSION}"
40
45
  comment "http://github.com/rtomayko/ronn/"
46
+ return if name.nil?
41
47
  macro "TH", %["#{escape(name.upcase)}" "#{section}" "#{date.strftime('%B %Y')}" "#{version}" "#{manual}"]
42
48
  end
43
49
 
44
- def normalize_whitespace(node)
45
- if node.kind_of?(Array) || node.kind_of?(Hpricot::Elements)
46
- node.each { |ch| normalize_whitespace(ch) }
47
- elsif node.doc? || (node.elem? && node.children)
48
- normalize_whitespace(node.children)
49
- elsif node.text? && !child_of?(node, 'pre')
50
- node.content = node.content.gsub(/[\n ]+/m, ' ')
51
- node_prev = previous(node)
52
- if (node.previous && node.previous.elem?) &&
53
- (node.next && node.next.elem?) &&
54
- (node.content.strip == '')
55
- node.content = ''
50
+ def remove_extraneous_elements!(doc)
51
+ doc.traverse_all_element do |node|
52
+ if node.comment? || node.procins? || node.doctype? || node.xmldecl?
53
+ warn 'removing: %p' % [node]
54
+ node.parent.children.delete(node)
55
+ end
56
+ end
57
+ end
58
+
59
+ def normalize_whitespace!(node)
60
+ case
61
+ when node.kind_of?(Array) || node.kind_of?(Hpricot::Elements)
62
+ node.to_a.dup.each { |ch| normalize_whitespace! ch }
63
+ when node.text?
64
+ preceding, following = node.previous, node.next
65
+ content = node.content.gsub(/[\n ]+/m, ' ')
66
+ if preceding.nil? || block_element?(preceding.name) ||
67
+ preceding.name == 'br'
68
+ content.lstrip!
69
+ end
70
+ if following.nil? || block_element?(following.name) ||
71
+ following.name == 'br'
72
+ content.rstrip!
73
+ end
74
+ if content.empty?
75
+ node.parent.children.delete(node)
56
76
  else
57
- node.content = node.content.lstrip if node_prev.nil?
58
- node.content = node.content.rstrip if node.next.nil?
77
+ node.content = content
59
78
  end
60
- elsif node.elem? || node.text?
79
+ when node.elem? && node.name == 'pre'
80
+ # stop traversing
81
+ when node.elem? && node.children
82
+ normalize_whitespace! node.children
83
+ when node.elem?
84
+ # element has no children
85
+ when node.doc?
86
+ normalize_whitespace! node.children
61
87
  else
62
- warn "unrecognized tag: %p", node.name
88
+ warn "unexpected node during whitespace normalization: %p", node.name
63
89
  end
64
- node
65
90
  end
66
91
 
67
92
  def block_filter(node)
@@ -72,7 +97,6 @@ module Ronn
72
97
  block_filter(node.children)
73
98
 
74
99
  elsif node.text?
75
- return if node.to_html =~ /^\s*$/m
76
100
  warn "unexpected text: %p", node
77
101
 
78
102
  elsif node.elem?
@@ -207,7 +231,6 @@ module Ronn
207
231
  gsub('&nbsp;', ' ').
208
232
  gsub('&lt;', '<').
209
233
  gsub('&gt;', '>').
210
- gsub('&gt;', '>').
211
234
  gsub(/&#x([0-9A-Fa-f]+);/) { $1.to_i(16).chr }.
212
235
  gsub(/&#(\d+);/) { $1.to_i.chr }.
213
236
  gsub('&amp;', '&').
@@ -0,0 +1,47 @@
1
+ require 'set'
2
+ require 'cgi'
3
+
4
+ module Ronn
5
+ module Utils
6
+
7
+ # All HTML 4 elements and some that are in common use.
8
+ HTML = %w[
9
+ a abbr acronym address applet area b base basefont bdo big blockquote body br
10
+ button caption center cite code col colgroup dd del dfn dir div dl dt em
11
+ fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img
12
+ input ins isindex kbd label legend li link map menu meta noframes noscript
13
+ object ol optgroup option p param pre q s samp script select small span strike
14
+ strong style sub sup table tbody td textarea tfoot th thead title tr tt u ul var
15
+ ].to_set
16
+
17
+ # Block elements.
18
+ HTML_BLOCK = %w[
19
+ blockquote body colgroup dd div dl dt fieldset form frame frameset
20
+ h1 h2 h3 h4 h5 h6 hr head html iframe li noframes noscript
21
+ object ol optgroup option p param pre script select
22
+ style table tbody td textarea tfoot th thead title tr tt ul
23
+ ].to_set
24
+
25
+ # Inline elements
26
+ HTML_INLINE = HTML - HTML_BLOCK
27
+
28
+ # Elements that don't have a closing tag.
29
+ HTML_EMPTY = %w[area base basefont br col hr input link meta].to_set
30
+
31
+ def block_element?(name)
32
+ HTML_BLOCK.include?(name)
33
+ end
34
+
35
+ def inline_element?(name)
36
+ HTML_INLINE.include?(name)
37
+ end
38
+
39
+ def empty_element?(name)
40
+ HTML_EMPTY.include?(name)
41
+ end
42
+
43
+ def html_element?(name)
44
+ HTML.include?(name)
45
+ end
46
+ end
47
+ end
data/man/ronn.1 CHANGED
@@ -1,7 +1,7 @@
1
- .\" generated with Ronn/v0.6.0
1
+ .\" generated with Ronn/v0.6.6
2
2
  .\" http://github.com/rtomayko/ronn/
3
3
  .
4
- .TH "RONN" "1" "June 2010" "0.6.0" "Ronn 0.6.0"
4
+ .TH "RONN" "1" "June 2010" "0.6-6-gd7645f2" "Ronn 0.6.6"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBronn\fR \- convert markdown files to manpages
@@ -10,16 +10,16 @@
10
10
  \fBronn\fR [\fIoptions\fR] \fIfile\fR\.\.\.
11
11
  .
12
12
  .br
13
- \fBronn\fR\fB\-m\fR|\fB\-\-man\fR\fIfile\fR\.\.\.
13
+ \fBronn\fR \fB\-m\fR|\fB\-\-man\fR \fIfile\fR\.\.\.
14
14
  .
15
15
  .br
16
- \fBronn\fR\fB\-S\fR|\fB\-\-server\fR\fIfile\fR\.\.\.
16
+ \fBronn\fR \fB\-S\fR|\fB\-\-server\fR \fIfile\fR\.\.\.
17
17
  .
18
18
  .br
19
- \fBronn\fR\fB\-\-pipe\fR\fIfile\fR
19
+ \fBronn\fR \fB\-\-pipe\fR \fIfile\fR
20
20
  .
21
21
  .br
22
- \fBronn\fR\fI<file\fR
22
+ \fBronn\fR < \fIfile\fR
23
23
  .
24
24
  .SH "DESCRIPTION"
25
25
  \fBRonn\fR converts Markdown input to standard roff\-formatted UNIX manpages or manpage styled HTML\. The ronn(5) source format is based on markdown(7) but includes additional rules and syntax geared toward authoring manuals\.
@@ -7,7 +7,7 @@ ronn(1) -- convert markdown files to manpages
7
7
  `ronn` `-m`|`--man` <file>...<br>
8
8
  `ronn` `-S`|`--server` <file>...<br>
9
9
  `ronn` `--pipe` <file><br>
10
- `ronn` < <file>
10
+ `ronn` &lt; <file>
11
11
 
12
12
  ## DESCRIPTION
13
13
 
data/man/ronn.5 CHANGED
@@ -1,7 +1,7 @@
1
- .\" generated with Ronn/v0.6.0
1
+ .\" generated with Ronn/v0.6.6
2
2
  .\" http://github.com/rtomayko/ronn/
3
3
  .
4
- .TH "RONN" "5" "June 2010" "0.6.0" "Ronn 0.6.0"
4
+ .TH "RONN" "5" "June 2010" "0.6-6-gd7645f2" "Ronn 0.6.6"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBronn\fR \- markdown\-based text format for authoring manpages
data/man/ronn.7 CHANGED
@@ -1,7 +1,7 @@
1
- .\" generated with Ronn/v0.6.0
1
+ .\" generated with Ronn/v0.6.6
2
2
  .\" http://github.com/rtomayko/ronn/
3
3
  .
4
- .TH "RONN" "7" "June 2010" "0.6.0" "Ronn 0.6.0"
4
+ .TH "RONN" "7" "June 2010" "0.6-6-gd7645f2" "Ronn 0.6.6"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBronn\fR \- the opposite of roff
@@ -162,7 +162,7 @@ Ronn aims to address many of the issues with manpage creation while preserving t
162
162
  Ronn is Copyright (C) 2009 Ryan Tomayko \fIhttp://tomayko\.com/about\fR
163
163
  .
164
164
  .br
165
- See the file COPYING for information of licensing and distribution\.
165
+ See the file COPYING for information of licensing and distribution\.
166
166
  .
167
167
  .SH "SEE ALSO"
168
168
  ronn(1) \fIhttp://rtomayko\.github\.com/ronn/ronn\.1\fR, ronn(5) \fIhttp://rtomayko\.github\.com/ronn/ronn\.5\fR, markdown(5)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ronn'
3
- s.version = '0.6.0'
3
+ s.version = '0.6.6'
4
4
  s.date = '2010-06-13'
5
5
 
6
6
  s.description = "The opposite of roff"
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  lib/ronn/template/print.css
32
32
  lib/ronn/template/screen.css
33
33
  lib/ronn/template/toc.css
34
+ lib/ronn/utils.rb
34
35
  man/ronn.1
35
36
  man/ronn.1.ronn
36
37
  man/ronn.5
@@ -58,12 +59,16 @@ Gem::Specification.new do |s|
58
59
  test/middle_paragraph.html
59
60
  test/middle_paragraph.roff
60
61
  test/middle_paragraph.ronn
62
+ test/missing_spaces.roff
63
+ test/missing_spaces.ronn
61
64
  test/ronn_test.rb
62
65
  test/section_reference_links.html
63
66
  test/section_reference_links.roff
64
67
  test/section_reference_links.ronn
65
68
  test/titleless_document.html
66
69
  test/titleless_document.ronn
70
+ test/underline_spacing_test.roff
71
+ test/underline_spacing_test.ronn
67
72
  ]
68
73
  # = MANIFEST =
69
74
 
@@ -98,7 +98,7 @@ This is another regular paragraph.
98
98
  HTML tags. E.g., you can't use Markdown-style <code>*emphasis*</code> inside an
99
99
  HTML block.</p>
100
100
 
101
- <p>Span-level HTML tags -- e.g. <code>&lt;span&gt;</code>, <code>&lt;cite&gt;</code>, or <code>&lt;del></code> -- can be
101
+ <p>Span-level HTML tags -- e.g. <code>&lt;span&gt;</code>, <code>&lt;cite&gt;</code>, or <code>&lt;del&gt;</code> -- can be
102
102
  used anywhere in a Markdown paragraph, list item, or header. If you
103
103
  want, you can even use HTML tags instead of Markdown formatting; e.g. if
104
104
  you'd prefer to use HTML <code>&lt;a&gt;</code> or <code>&lt;img&gt;</code> tags instead of Markdown's
@@ -0,0 +1,6 @@
1
+ .TH "MISSING_SPACES" "" "January 1979" "" ""
2
+ .
3
+ .TP
4
+ \fB\-S\fR \fItext\fR, \fBsearch\fR \fItext\fR
5
+ Performs a substring search of formula names for \fItext\fR\.
6
+
@@ -0,0 +1,2 @@
1
+ * `-S` <text>, `search` <text>:
2
+ Performs a substring search of formula names for <text>.
@@ -0,0 +1,16 @@
1
+ .TH "UNDERLINE_SPACING_TEST" "" "January 1979" "" ""
2
+ This input
3
+ .
4
+ .TP
5
+ \fB\-S\fR \fItext\fR, \fBsearch\fR \fItext\fR
6
+ Performs a substring search of formula names for \fItext\fR\.
7
+ .
8
+ .TP
9
+ \fB\-O\fR \fItext\fR, \fBother\fR \fItext\fR
10
+ Does something else\.
11
+ .
12
+ .P
13
+ Should space text properly\.
14
+ .
15
+ .P
16
+ \fI!\-\- this is a comment \-\-\fR
@@ -0,0 +1,11 @@
1
+ This input
2
+
3
+ * `-S` _text_, `search` _text_:
4
+ Performs a substring search of formula names for _text_.
5
+
6
+ * `-O` <text>, `other` <text>:
7
+ Does something else.
8
+
9
+ Should space text properly.
10
+
11
+ <!-- this is a comment -->
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 0
9
- version: 0.6.0
8
+ - 6
9
+ version: 0.6.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Tomayko
@@ -89,6 +89,7 @@ files:
89
89
  - lib/ronn/template/print.css
90
90
  - lib/ronn/template/screen.css
91
91
  - lib/ronn/template/toc.css
92
+ - lib/ronn/utils.rb
92
93
  - man/ronn.1
93
94
  - man/ronn.1.ronn
94
95
  - man/ronn.5
@@ -116,12 +117,16 @@ files:
116
117
  - test/middle_paragraph.html
117
118
  - test/middle_paragraph.roff
118
119
  - test/middle_paragraph.ronn
120
+ - test/missing_spaces.roff
121
+ - test/missing_spaces.ronn
119
122
  - test/ronn_test.rb
120
123
  - test/section_reference_links.html
121
124
  - test/section_reference_links.roff
122
125
  - test/section_reference_links.ronn
123
126
  - test/titleless_document.html
124
127
  - test/titleless_document.ronn
128
+ - test/underline_spacing_test.roff
129
+ - test/underline_spacing_test.ronn
125
130
  has_rdoc: true
126
131
  homepage: http://github.com/rtomayko/ronn/
127
132
  licenses: []