mandown 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,7 +20,7 @@
20
20
  require 'yaml'
21
21
 
22
22
  # Define the text that is displayed when the user asks for documentation
23
- def documentation
23
+ def bibdown_documentation
24
24
  <<END
25
25
 
26
26
 
@@ -504,7 +504,7 @@ end
504
504
  def bibdown_main
505
505
  # Handle request for documentation.
506
506
  if ARGV.length > 0 && ARGV[0] == '--help'
507
- puts documentation
507
+ puts bobdown_documentation
508
508
  exit
509
509
  end
510
510
 
@@ -2,7 +2,7 @@ module Mandown #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 9
5
+ TINY = 10
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -18,13 +18,15 @@
18
18
  ################################################################################
19
19
 
20
20
  # Define the text that is displayed when the user asks for documentation
21
- def documentation
21
+ def secdown_documentation
22
22
  <<END
23
23
 
24
24
 
25
25
  secdown --- part of the Mandown set of tools.
26
26
 
27
- secdown processes standard input and inserts section numbers in titles.
27
+ secdown processes standard input and:
28
+ * inserts section numbers in titles;
29
+ * allows references to other sections to be made.
28
30
 
29
31
  Copyright © 2008 Chris Rose.
30
32
  Distributed according to the GNU General Public License.
@@ -77,6 +79,39 @@ def documentation
77
79
  style.
78
80
 
79
81
  secdown does not insert a heading number for '# Bibliography'.
82
+
83
+ secdown provides a way to reference other sections. To label a section (or
84
+ subsection, etc.), insert a line containing a label of the form
85
+ 'label:some-label' somehwere in the section you want to reference. To
86
+ reference the section, use the syntax 'sec:some-label'. secdown will remove
87
+ the label definitions and replace the section references with something like
88
+ 'section 1.2'.
89
+
90
+ ------------------------------- Example -------------------------------------
91
+
92
+ The following text
93
+
94
+ # This is a heading
95
+ label:first-section
96
+
97
+ This is a reference to the second section, sec:second-section.
98
+
99
+ # This is another heading
100
+ label:second-section
101
+
102
+ This is a reference to the first section, sec:first-section.
103
+
104
+ Would be turned into
105
+
106
+ # 1 This is a heading
107
+
108
+ This is a reference to the second section, section 2.
109
+
110
+ # 2 This is another heading
111
+
112
+ This is a reference to the first section, section 1.
113
+
114
+ ------------------------------- End of example ------------------------------
80
115
 
81
116
  See also:
82
117
  ---------
@@ -204,12 +239,63 @@ def insert_header_levels(lines, ignore_bibliography = true)
204
239
  ret_val
205
240
  end
206
241
 
242
+ # Take a header string that contains a leading section number and return that
243
+ # number.
244
+ def get_section_number_from_header(header)
245
+ tmp = header.scan(/(\d+((\.\d)+))/)
246
+ if tmp.empty?
247
+ header.scan(/(\d+)/)[0][0]
248
+ else
249
+ tmp[0][0]
250
+ end
251
+ end
252
+
253
+
254
+ # Take a manuscript, as an array of lines, that has been processed by
255
+ # insert_header_levels, and replace isnstances of 'sec:some-label' with the
256
+ # section number that the the label was defined in using 'label:some-label'.
257
+ # Remove lines that contain the label definition and return the result.
258
+ def replace_section_references(lines)
259
+ # First parse the lines to get a mapping between the label names and the
260
+ # section numbers they appear in.
261
+ current_section_number = nil
262
+ label_section_map = {} # Will map labels to section numbers.
263
+ ret_val = []
264
+ lines.each do |line|
265
+ # Get the label:some-label string, if it is on this line, as an array.
266
+ label_string_arr = line.scan(/^label:\w+[-_\.]*\w*/)
267
+
268
+ if atx_header?(line)
269
+ current_section_number = get_section_number_from_header(line)
270
+ elsif !label_string_arr.empty?
271
+ label = label_string_arr[0].split('label:')[1] # Get the label.
272
+ label_section_map[label] = current_section_number
273
+ line = nil # Kill off the label.
274
+ else
275
+ # Do nothing.
276
+ end
277
+ ret_val.push(line) unless line.nil?
278
+ end
279
+
280
+ # Now process ret_val to replace instances of 'sec:some-label' with 'section
281
+ # 3.2' or whatever.
282
+ ret_val.each_index do |i|
283
+ label_section_map.each_pair do |key, value|
284
+ ret_val[i].gsub!("sec:#{key}", "section #{value}")
285
+ end
286
+ p ret_val[i]
287
+ end
288
+
289
+ ret_val
290
+ end
291
+
292
+
207
293
 
208
294
  # Read the manuscript from standard input and insert appropriately nested level numbering (e.g. '2.1') and send the result to standard output.
209
295
  def secdown_main
210
296
  # Handle request for documentation.
211
297
  if ARGV.length > 0 && ARGV[0] == '--help'
212
- puts documentation
298
+ puts secdown_documentation
213
299
  exit
214
300
  end
215
301
 
@@ -142,8 +142,59 @@ class TestSecdown < Test::Unit::TestCase
142
142
  # Test that it ignores bibliography headings by default.
143
143
  bib_line = ["# Bibliography"]
144
144
  assert_equal(bib_line, insert_header_levels(bib_line))
145
+ end
146
+
147
+ def test_get_section_number_from_header
148
+ assert_equal('2', get_section_number_from_header('# 2 Some Header'))
149
+ assert_equal('2.1', get_section_number_from_header('## 2.1 Some Header'))
150
+ assert_equal('1.2.3', get_section_number_from_header('### 1.2.3 Header'))
151
+ end
152
+
153
+
154
+ def test_replace_section_references
155
+ source = [
156
+ '# 1 First Heading',
157
+ '',
158
+ 'This is a reference to the third heading label sec:lab3.',
159
+ '',
160
+ '# 2 Second Heading',
161
+ '',
162
+ 'label:lab2',
163
+ '',
164
+ 'This is a reference to sec:lab2.',
165
+ '',
166
+ '## 2.1 A subheading',
167
+ '',
168
+ 'label:lab2.1',
169
+ '',
170
+ 'This is a reference to the first label in sec:lab2.',
171
+ 'This is a reference the second label in sec:lab2, sec:lab2.1.',
172
+ '',
173
+ '# 3 Third heading',
174
+ '',
175
+ 'label:lab3']
176
+
177
+ expected = [
178
+ '# 1 First Heading',
179
+ '',
180
+ 'This is a reference to the third heading label section 3.',
181
+ '',
182
+ '# 2 Second Heading',
183
+ '',
184
+ '',
185
+ 'This is a reference to section 2.',
186
+ '',
187
+ '## 2.1 A subheading',
188
+ '',
189
+ '',
190
+ 'This is a reference to the first label in section 2.',
191
+ 'This is a reference the second label in section 2, section 2.1.',
192
+ '',
193
+ '# 3 Third heading',
194
+ '']
195
+ assert_equal(expected, replace_section_references(source))
145
196
 
146
197
  end
147
-
148
-
198
+
199
+
149
200
  end
@@ -33,7 +33,7 @@
33
33
  <h1>Academic writing extensions to Markdown</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/mandown"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/mandown" class="numbers">0.0.9</a>
36
+ <a href="http://rubyforge.org/projects/mandown" class="numbers">0.0.10</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;mandown&#8217;</h1>
39
39
 
@@ -50,16 +50,19 @@
50
50
  <p>&#8216;Mandown&#8217; is a portmanteau of &#8216;Markdown&#8217; and &#8216;manuscript&#8217; which I found appropriately amusing (&#8220;Man down!!&#8221;).</p>
51
51
 
52
52
 
53
+ <p>Mandown is at an early stage of development and is not quite ready for use on real work. However, it still might be useful to you and I&#8217;d appreciate early feedback. It is easy to install, upgrade and uninstall Mandown, so if you&#8217;re interested, please give it a try.</p>
54
+
55
+
53
56
  <h2>Why?</h2>
54
57
 
55
58
 
56
59
  <p>Academics typically write papers using either LaTeX or Microsoft Word. Word is often favoured by the less technically inclined (or those who are simply ignorant of the existence of alternatives). LaTeX is used for some combination of the following reasons: it&#8217;s free software; it can produce typographically excellent output; LaTeX documents are plain text files which can be edited using powerful text editors (vi, Emacs, TextMate etc.). Those who would otherwise choose LaTeX are often forced to use Word by their co-authors or the publishers of their work, and would like a way to maintain the benefits of their LaTeX environment while being able to produce Word documents. Mandown provides tools to allow this.</p>
57
60
 
58
61
 
59
- <p>Mandown is not attempting to be a document preparation system like LaTeX; if you can use LaTeX you probably should&#8212;-it&#8217;s far more powerful than Mandown. For example, Mandown will have no support for controlling page layout or inserting and controlling graphics (though it will support the concept of figures).</p>
62
+ <p>Mandown is not attempting to be a document preparation system like LaTeX; if you can use LaTeX you probably should&#8212;it&#8217;s far more powerful than Mandown. For example, Mandown will have no support for controlling page layout or inserting and controlling graphics (though it will support the concept of figures).</p>
60
63
 
61
64
 
62
- <p>Mandown is implemented as a set of command line tools that can be chained together into a pipeline. At this stage of development, only one component of Mandown has been implemented: bibdown allows one to maintain a bibliography in <span class="caps">YAML</span> format and cite papers from it; bibdown replaces citation keys with citation numbers and renders the bibliography using appropriate Markdown syntax. In future, further extensions to Markdown will be developed and implemented (e.g. figdown will support figures, another tool will support sectioning, labels and referring, etc.). Mandown is distributed as a gem for ease of installation (see the next section).</p>
65
+ <p>Mandown is implemented as a set of command line tools that can be chained together into a pipeline. In future, further extensions to Markdown will be developed and implemented (e.g. figdown will support figures, another tool will support sectioning, labels and referring, etc.). Mandown is distributed as a gem for ease of installation (see the next section).</p>
63
66
 
64
67
 
65
68
  <h2>Installing</h2>
@@ -70,13 +73,13 @@
70
73
 
71
74
  <pre>sudo gem install mandown</pre>
72
75
 
73
- <p>If you are confused already, read the <a href="http://rubygems.org/read/chapter/1#page1">Really Quick Start guide</a> from the RubyGems user guide and note that you may or may not need the <a href="http://en.wikipedia.org/wiki/Sudo">sudo</a> command (it&#8217;s necessary on Mac <span class="caps">OS X</span>); on some systems you might need to become the super user first by running the <code>su</code> command and entering the super user&#8217;s password, and then running <code>gem install mandown</code>.</p>
76
+ <p>(If you are confused already, read the <a href="http://rubygems.org/read/chapter/1#page1">Really Quick Start guide</a> from the RubyGems user guide and note that you may or may not need the <a href="http://en.wikipedia.org/wiki/Sudo">sudo</a> command: it&#8217;s necessary on Mac <span class="caps">OS X</span>, but on other systems you might need to become the super user first by running the <code>su</code> command and entering the super user&#8217;s password, and then running <code>gem install mandown</code>.)</p>
74
77
 
75
78
 
76
- <p>This will add the Mandown executables (executable Ruby scripts) to your $PATH, which include the following: bibdown.</p>
79
+ <p>This will add the Mandown programs (executable Ruby scripts).</p>
77
80
 
78
81
 
79
- <p>You will also need to install a suitable Markdown processor; I recommend <a href="http://johnmacfarlane.net/pandoc/">Pandoc</a> which can convert Markdown to multiple output formats, including <span class="caps">RTF</span> which can be opened using Microsoft Word.</p>
82
+ <p>You will also need to install a suitable Markdown processor. I recommend <a href="http://johnmacfarlane.net/pandoc/">Pandoc</a> which can convert Markdown to multiple output formats, including <span class="caps">RTF</span> which can be opened using Microsoft Word.</p>
80
83
 
81
84
 
82
85
  <h2>The tools</h2>
@@ -96,11 +99,10 @@
96
99
 
97
100
 
98
101
  <p>First you need to write a manuscript using a combination of the Markdown and
99
- Mandown syntaxes, but to get you started Mandown includes a sample Mandown document (see the example, below). Markdown and Mandown are very simple and all you need is a plain text editor.</p>
102
+ Mandown syntaxes, but to get you started Mandown includes a sample Mandown document (see the example, below). Markdown and Mandown are very simple and all you need is a plain text editor (don&#8217;t save your Mandown files as Word documents, they must be plain text files).</p>
100
103
 
101
104
 
102
- <p>To
103
- learn Markdown, see the <a href="http://daringfireball.net/projects/markdown/syntax">Markdown
105
+ <p>To learn Markdown, see the <a href="http://daringfireball.net/projects/markdown/syntax">Markdown
104
106
  documentation</a> (note that
105
107
  <a href="http://johnmacfarlane.net/pandoc/">Pandoc</a> is the recommended Markdown processor
106
108
  for academic applications).</p>
@@ -131,7 +133,7 @@ for academic applications).</p>
131
133
  <p>The <code>mandown-sample</code> program simply outputs the sample manuscript.</p>
132
134
 
133
135
 
134
- <p>(Note how papers are cited using the <code>cite:</code> command and have a quick look at the <span class="caps">YAML</span>-format bibliography towards the end of the file.)</p>
136
+ <p>(Note how papers are cited using the <code>cite:</code> command. Also scroll to the bottom and have a quick look at the <span class="caps">YAML</span>-format bibliography.)</p>
135
137
 
136
138
 
137
139
  <p>We want to process this document using Mandown (and then Pandoc), so first save the sample to a file:</p>
@@ -160,6 +162,30 @@ for academic applications).</p>
160
162
  <pre>cat my-manu.txt | bibdown | secdown &gt; my-manu-out.txt</pre>
161
163
  <pre>pandoc ...</pre>
162
164
 
165
+ <h2>Upgrading</h2>
166
+
167
+
168
+ <p>Mandown is undergoing steady development and currently has a 0.0.x release number. I&#8217;m hoping to get first versions of the most important tools finished soon. At this point Mandown will be given the 0.1.0 version number, to indicate that it is suitable for people to start using it (even if just in an experimental context).</p>
169
+
170
+
171
+ <p>If you use the early versions of Mandown and want to keep up-to-date, simply run</p>
172
+
173
+
174
+ <pre>sudo gem update mandown</pre>
175
+
176
+ <p>You may also optionally remove previous versions using:</p>
177
+
178
+
179
+ <pre>sudo gem uninstall mandown --version x.y.z</pre>
180
+
181
+ <p>or</p>
182
+
183
+
184
+ <pre>sudo gem uninstall mandown</pre>
185
+
186
+ <p>and then install Mandown as usual.</p>
187
+
188
+
163
189
  <h2>Help, gotchas and <span class="caps">FAQ</span></h2>
164
190
 
165
191
 
@@ -10,14 +10,16 @@ Writing a paper using Mandown is simple: write your paper using standard Markdow
10
10
 
11
11
  'Mandown' is a portmanteau of 'Markdown' and 'manuscript' which I found appropriately amusing ("Man down!!").
12
12
 
13
+ Mandown is at an early stage of development and is not quite ready for use on real work. However, it still might be useful to you and I'd appreciate early feedback. It is easy to install, upgrade and uninstall Mandown, so if you're interested, please give it a try.
14
+
13
15
 
14
16
  h2. Why?
15
17
 
16
18
  Academics typically write papers using either LaTeX or Microsoft Word. Word is often favoured by the less technically inclined (or those who are simply ignorant of the existence of alternatives). LaTeX is used for some combination of the following reasons: it's free software; it can produce typographically excellent output; LaTeX documents are plain text files which can be edited using powerful text editors (vi, Emacs, TextMate etc.). Those who would otherwise choose LaTeX are often forced to use Word by their co-authors or the publishers of their work, and would like a way to maintain the benefits of their LaTeX environment while being able to produce Word documents. Mandown provides tools to allow this.
17
19
 
18
- Mandown is not attempting to be a document preparation system like LaTeX; if you can use LaTeX you probably should---it's far more powerful than Mandown. For example, Mandown will have no support for controlling page layout or inserting and controlling graphics (though it will support the concept of figures).
20
+ Mandown is not attempting to be a document preparation system like LaTeX; if you can use LaTeX you probably should--it's far more powerful than Mandown. For example, Mandown will have no support for controlling page layout or inserting and controlling graphics (though it will support the concept of figures).
19
21
 
20
- Mandown is implemented as a set of command line tools that can be chained together into a pipeline. At this stage of development, only one component of Mandown has been implemented: bibdown allows one to maintain a bibliography in YAML format and cite papers from it; bibdown replaces citation keys with citation numbers and renders the bibliography using appropriate Markdown syntax. In future, further extensions to Markdown will be developed and implemented (e.g. figdown will support figures, another tool will support sectioning, labels and referring, etc.). Mandown is distributed as a gem for ease of installation (see the next section).
22
+ Mandown is implemented as a set of command line tools that can be chained together into a pipeline. In future, further extensions to Markdown will be developed and implemented (e.g. figdown will support figures, another tool will support sectioning, labels and referring, etc.). Mandown is distributed as a gem for ease of installation (see the next section).
21
23
 
22
24
 
23
25
  h2. Installing
@@ -26,11 +28,12 @@ Mandown is distributed as a Ruby gem (so you'll need Ruby and RubyGems installed
26
28
 
27
29
  <pre>sudo gem install mandown</pre>
28
30
 
29
- If you are confused already, read the "Really Quick Start guide":http://rubygems.org/read/chapter/1#page1 from the RubyGems user guide and note that you may or may not need the "sudo":http://en.wikipedia.org/wiki/Sudo command (it's necessary on Mac OS X); on some systems you might need to become the super user first by running the <code>su</code> command and entering the super user's password, and then running <code>gem install mandown</code>.
31
+ (If you are confused already, read the "Really Quick Start guide":http://rubygems.org/read/chapter/1#page1 from the RubyGems user guide and note that you may or may not need the "sudo":http://en.wikipedia.org/wiki/Sudo command: it's necessary on Mac OS X, but on other systems you might need to become the super user first by running the <code>su</code> command and entering the super user's password, and then running <code>gem install mandown</code>.)
32
+
33
+ This will add the Mandown programs (executable Ruby scripts).
30
34
 
31
- This will add the Mandown executables (executable Ruby scripts) to your $PATH, which include the following: bibdown.
35
+ You will also need to install a suitable Markdown processor. I recommend "Pandoc":http://johnmacfarlane.net/pandoc/ which can convert Markdown to multiple output formats, including RTF which can be opened using Microsoft Word.
32
36
 
33
- You will also need to install a suitable Markdown processor; I recommend "Pandoc":http://johnmacfarlane.net/pandoc/ which can convert Markdown to multiple output formats, including RTF which can be opened using Microsoft Word.
34
37
 
35
38
  h2. The tools
36
39
 
@@ -44,10 +47,9 @@ The following Mandown tools are provided in the latest release:
44
47
  h2. Usage
45
48
 
46
49
  First you need to write a manuscript using a combination of the Markdown and
47
- Mandown syntaxes, but to get you started Mandown includes a sample Mandown document (see the example, below). Markdown and Mandown are very simple and all you need is a plain text editor.
50
+ Mandown syntaxes, but to get you started Mandown includes a sample Mandown document (see the example, below). Markdown and Mandown are very simple and all you need is a plain text editor (don't save your Mandown files as Word documents, they must be plain text files).
48
51
 
49
- To
50
- learn Markdown, see the "Markdown
52
+ To learn Markdown, see the "Markdown
51
53
  documentation":http://daringfireball.net/projects/markdown/syntax (note that
52
54
  "Pandoc":http://johnmacfarlane.net/pandoc/ is the recommended Markdown processor
53
55
  for academic applications).
@@ -70,7 +72,7 @@ Let's read an example Mandown manuscript using the <code>less</code> pager:
70
72
 
71
73
  The <code>mandown-sample</code> program simply outputs the sample manuscript.
72
74
 
73
- (Note how papers are cited using the <code>cite:</code> command and have a quick look at the YAML-format bibliography towards the end of the file.)
75
+ (Note how papers are cited using the <code>cite:</code> command. Also scroll to the bottom and have a quick look at the YAML-format bibliography.)
74
76
 
75
77
  We want to process this document using Mandown (and then Pandoc), so first save the sample to a file:
76
78
 
@@ -94,6 +96,24 @@ The Mandown tools are designed to be chained together into a pipeline, so for ex
94
96
  <pre>pandoc ...</pre>
95
97
 
96
98
 
99
+ h2. Upgrading
100
+
101
+ Mandown is undergoing steady development and currently has a 0.0.x release number. I'm hoping to get first versions of the most important tools finished soon. At this point Mandown will be given the 0.1.0 version number, to indicate that it is suitable for people to start using it (even if just in an experimental context).
102
+
103
+ If you use the early versions of Mandown and want to keep up-to-date, simply run
104
+
105
+ <pre>sudo gem update mandown</pre>
106
+
107
+ You may also optionally remove previous versions using:
108
+
109
+ <pre>sudo gem uninstall mandown --version x.y.z</pre>
110
+
111
+ or
112
+
113
+ <pre>sudo gem uninstall mandown</pre>
114
+
115
+ and then install Mandown as usual.
116
+
97
117
 
98
118
  h2. Help, gotchas and FAQ
99
119
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: mandown
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.9
7
- date: 2008-01-18 00:00:00 +00:00
6
+ version: 0.0.10
7
+ date: 2008-01-24 00:00:00 +00:00
8
8
  summary: Provides simple extensions to Markdown that are useful for academic writing
9
9
  require_paths:
10
10
  - lib