kramdown-man 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.md CHANGED
@@ -1,3 +1,13 @@
1
+ ### 0.1.5 / 2013-05-19
2
+
3
+ * Translate unicode symbols into roff glyphs.
4
+ * Convert typographic symbols and smart quotes into glyphs.
5
+ * Simplify `\fB\fC` as `\fC` (Colin Watson).
6
+ * Use `\fB` for codespans (Colin Watson).
7
+ * Escape `--` as `\-\-` (Colin Watson).
8
+ * Escape `\` as `\e` (Colin Watson).
9
+ * Emit `.TP` or `.HP` if the paragraph begins with a strong element.
10
+
1
11
  ### 0.1.4 / 2013-05-05
2
12
 
3
13
  * Improve detection of tagged paragraphs.
@@ -13,28 +13,394 @@ module Kramdown
13
13
  # Comment header
14
14
  HEADER = [
15
15
  ".\\\" Generated by kramdown-man #{::Kramdown::Man::VERSION}",
16
- ".\\\" https://github.com/postmodern/kramdown-roff#readme"
16
+ ".\\\" https://github.com/postmodern/kramdown-man#readme"
17
17
  ].join("\n")
18
18
 
19
19
  # Typographic Symbols and their UTF8 chars
20
20
  TYPOGRAPHIC_SYMS = {
21
- :ndash => "--",
22
- :mdash => "—",
23
- :hellip => "…",
24
- :laquo => "«",
25
- :raquo => "»",
26
- :laquo_space => "«",
27
- :raquo_space => "»"
21
+ :ndash => '\-\-',
22
+ :mdash => '\[em]',
23
+ :hellip => '...',
24
+ :laquo => '\[Fo]',
25
+ :raquo => '\[Fc]',
26
+ :laquo_space => '\[Fo]',
27
+ :raquo_space => '\[Fc]'
28
28
  }
29
29
 
30
30
  # Smart Quotes and their UTF8 chars
31
31
  SMART_QUOTES = {
32
- :lsquo => "‘",
33
- :rsquo => "’",
34
- :ldquo => "“",
35
- :rdquo => "”"
32
+ :lsquo => '\[oq]',
33
+ :rsquo => '\[cq]',
34
+ :ldquo => '\[lq]',
35
+ :rdquo => '\[rq]'
36
36
  }
37
37
 
38
+ GLYPHS = {
39
+ 'Ð' => '\[-D]',
40
+ 'ð' => '\[Sd]',
41
+ 'Þ' => '\[TP]',
42
+ 'þ' => '\[Tp]',
43
+ 'ß' => '\[ss]',
44
+ # Ligatures and Other Latin Glyphs
45
+ 'ff' => '\[ff]',
46
+ 'fi' => '\[fi]',
47
+ 'fl' => '\[fl]',
48
+ 'ffi' => '\[Fi]',
49
+ 'ffl' => '\[Fl]',
50
+ 'Ł' => '\[/L]',
51
+ 'ł' => '\[/l]',
52
+ 'Ø' => '\[/O]',
53
+ 'ø' => '\[/o]',
54
+ 'Æ' => '\[AE]',
55
+ 'æ' => '\[ae]',
56
+ 'Œ' => '\[OE]',
57
+ 'œ' => '\[oe]',
58
+ 'IJ' => '\[IJ]',
59
+ 'ij' => '\[ij]',
60
+ 'ı' => '\[.i]',
61
+ 'ȷ' => '\[.j]',
62
+ # Accented Characters
63
+ 'Á' => '\[\'A]',
64
+ 'Ć' => '\[\'C]',
65
+ 'É' => '\[\'E]',
66
+ 'Í' => '\[\'I]',
67
+ 'Ó' => '\[\'O]',
68
+ 'Ú' => '\[\'U]',
69
+ 'Ý' => '\[\'Y]',
70
+ 'á' => '\[\'a]',
71
+ 'ć' => '\[\'c]',
72
+ 'é' => '\[\'e]',
73
+ 'í' => '\[\'i]',
74
+ 'ó' => '\[\'o]',
75
+ 'ú' => '\[\'u]',
76
+ 'ý' => '\[\'y]',
77
+ 'Ä' => '\[:A]',
78
+ 'Ë' => '\[:E]',
79
+ 'Ï' => '\[:I]',
80
+ 'Ö' => '\[:O]',
81
+ 'Ü' => '\[:U]',
82
+ 'Ÿ' => '\[:Y]',
83
+ 'ä' => '\[:a]',
84
+ 'ë' => '\[:e]',
85
+ 'ï' => '\[:i]',
86
+ 'ö' => '\[:o]',
87
+ 'ü' => '\[:u]',
88
+ 'ÿ' => '\[:y]',
89
+ 'Â' => '\[^A]',
90
+ 'Ê' => '\[^E]',
91
+ 'Î' => '\[^I]',
92
+ 'Ô' => '\[^O]',
93
+ 'Û' => '\[^U]',
94
+ 'â' => '\[^a]',
95
+ 'ê' => '\[^e]',
96
+ 'î' => '\[^i]',
97
+ 'ô' => '\[^o]',
98
+ 'û' => '\[^u]',
99
+ 'À' => '\[`A]',
100
+ 'È' => '\[`E]',
101
+ 'Ì' => '\[`I]',
102
+ 'Ò' => '\[`O]',
103
+ 'Ù' => '\[`U]',
104
+ 'à' => '\[`a]',
105
+ 'è' => '\[`e]',
106
+ 'ì' => '\[`i]',
107
+ 'ò' => '\[`o]',
108
+ 'ù' => '\[`u]',
109
+ 'Ã' => '\[~A]',
110
+ 'Ñ' => '\[~N]',
111
+ 'Õ' => '\[~O]',
112
+ 'ã' => '\[~a]',
113
+ 'ñ' => '\[~n]',
114
+ 'õ' => '\[~o]',
115
+ 'Š' => '\[vS]',
116
+ 'š' => '\[vs]',
117
+ 'Ž' => '\[vZ]',
118
+ 'ž' => '\[vz]',
119
+ 'Ç' => '\[,C]',
120
+ 'ç' => '\[,c]',
121
+ 'Å' => '\[oA]',
122
+ 'å' => '\[oa]',
123
+ # Accents
124
+ '˝' => '\[a"]',
125
+ '¯' => '\[a-]',
126
+ '˙' => '\[a.]',
127
+ '^' => '\[a^]',
128
+ '´' => "\\´",
129
+ '`' => '\`',
130
+ '˘' => '\[ab]',
131
+ '¸' => '\[ac]',
132
+ '¨' => '\[ad]',
133
+ 'ˇ' => '\[ah]',
134
+ '˚' => '\[ao]',
135
+ '~' => '\(ti',
136
+ '˛' => '\[ho]',
137
+ '^' => '\(ha',
138
+ '~' => '\[ti]',
139
+ # Quotes
140
+ '„' => '\[Bq]',
141
+ '‚' => '\[bq]',
142
+ '“' => '\[lq]',
143
+ '”' => '\[rq]',
144
+ '‘' => '\[oq]',
145
+ '’' => '\[cq]',
146
+ "'" => '\(aq',
147
+ '"' => '\[dq]',
148
+ '«' => '\[Fo]',
149
+ '»' => '\[Fc]',
150
+ '‹' => '\[fo]',
151
+ '›' => '\[fc]',
152
+ # Punctuation
153
+ '.' => '\.',
154
+ '¡' => '\[r!]',
155
+ '¿' => '\[r?]',
156
+ '—' => '\[em]',
157
+ '–' => '\[en]',
158
+ '‐' => '\[hy]',
159
+ # Brackets
160
+ '[' => '\[lB]',
161
+ ']' => '\[rB]',
162
+ '{' => '\[lC]',
163
+ '}' => '\[rC]',
164
+ '⟨' => '\[la]',
165
+ '⟩' => '\[ra]',
166
+ '⎪' => '\[bv]',
167
+ '⎪' => '\[braceex]',
168
+ '⎡' => '\[bracketlefttp]',
169
+ '⎣' => '\[bracketleftbt]',
170
+ '⎢' => '\[bracketleftex]',
171
+ '⎤' => '\[bracketrighttp]',
172
+ '⎦' => '\[bracketrightbt]',
173
+ '⎥' => '\[bracketrightex]',
174
+ '╭' => '\[lt]',
175
+ '⎧' => '\[bracelefttp]',
176
+ '┥' => '\[lk]',
177
+ '⎨' => '\[braceleftmid]',
178
+ '╰' => '\[lb]',
179
+ '⎩' => '\[braceleftbt]',
180
+ '⎪' => '\[braceleftex]',
181
+ '╮' => '\[rt]',
182
+ '⎫' => '\[bracerighttp]',
183
+ '┝' => '\[rk]',
184
+ '⎬' => '\[bracerightmid]',
185
+ '╯' => '\[rb]',
186
+ '⎭' => '\[bracerightbt]',
187
+ '⎪' => '\[bracerightex]',
188
+ '⎛' => '\[parenlefttp]',
189
+ '⎝' => '\[parenleftbt]',
190
+ '⎜' => '\[parenleftex]',
191
+ '⎞' => '\[parenrighttp]',
192
+ '⎠' => '\[parenrightbt]',
193
+ '⎟' => '\[parenrightex]',
194
+ # Arrows
195
+ '←' => '\[<-]',
196
+ '→' => '\[->]',
197
+ '↔' => '\[<>]',
198
+ '↓' => '\[da]',
199
+ '↑' => '\[ua]',
200
+ '↕' => '\[va]',
201
+ '⇐' => '\[lA]',
202
+ '⇒' => '\[rA]',
203
+ '⇔' => '\[hA]',
204
+ '⇓' => '\[dA]',
205
+ '⇑' => '\[uA]',
206
+ '⇕' => '\[vA]',
207
+ '⎯' => '\[an]',
208
+ # Lines
209
+ '|' => '\[ba]',
210
+ '│' => '\[br]',
211
+ '_' => '\[ul]',
212
+ '‾' => '\[rn]',
213
+ '_' => '\[ru]',
214
+ '¦' => '\[bb]',
215
+ '/' => '\[sl]',
216
+ '\\' => '\e',
217
+ # Text markers
218
+ '○' => '\[ci]',
219
+ '·' => '\[bu]',
220
+ '‡' => '\[dd]',
221
+ '†' => '\[dg]',
222
+ '◊' => '\[lz]',
223
+ '□' => '\[sq]',
224
+ '¶' => '\[ps]',
225
+ '§' => '\[sc]',
226
+ '☜' => '\[lh]',
227
+ '☞' => '\[rh]',
228
+ '@' => '\[at]',
229
+ '#' => '\[sh]',
230
+ '↵' => '\[CR]',
231
+ '✓' => '\[OK]',
232
+ # Legal Symbols
233
+ '©' => '\[co]',
234
+ '®' => '\[rg]',
235
+ '™' => '\[tm]',
236
+ # Currency symbols
237
+ '$' => '\[Do]',
238
+ '¢' => '\[ct]',
239
+ '€' => '\[eu]',
240
+ '€' => '\[Eu]',
241
+ '¥' => '\[Ye]',
242
+ '£' => '\[Po]',
243
+ '¤' => '\[Cs]',
244
+ 'ƒ' => '\[Fn]',
245
+ # Units
246
+ '°' => '\[de]',
247
+ '‰' => '\[%0]',
248
+ '′' => '\[fm]',
249
+ '″' => '\[sd]',
250
+ 'µ' => '\[mc]',
251
+ 'ª' => '\[Of]',
252
+ 'º' => '\[Om]',
253
+ # Logical Symbols
254
+ '∧' => '\[AN]',
255
+ '∨' => '\[OR]',
256
+ '¬' => '\[no]',
257
+ '¬' => '\[tno]',
258
+ '∃' => '\[te]',
259
+ '∀' => '\[fa]',
260
+ '∋' => '\[st]',
261
+ '∴' => '\[3d]',
262
+ '∴' => '\[tf]',
263
+ '|' => '\[or]',
264
+ # Mathematical Symbols
265
+ '½' => '\[12]',
266
+ '¼' => '\[14]',
267
+ '¾' => '\[34]',
268
+ '⅛' => '\[18]',
269
+ '⅜' => '\[38]',
270
+ '⅝' => '\[58]',
271
+ '⅞' => '\[78]',
272
+ '¹' => '\[S1]',
273
+ '²' => '\[S2]',
274
+ '³' => '\[S3]',
275
+ '+' => '\[pl]',
276
+ '-' => '\-',
277
+ '−' => '\[mi]',
278
+ '∓' => '\[-+]',
279
+ '±' => '\[+-]',
280
+ '±' => '\[t+-]',
281
+ '·' => '\[pc]',
282
+ '⋅' => '\[md]',
283
+ '×' => '\[mu]',
284
+ '×' => '\[tmu]',
285
+ '⊗' => '\[c*]',
286
+ '⊕' => '\[c+]',
287
+ '÷' => '\[di]',
288
+ '÷' => '\[tdi]',
289
+ '⁄' => '\[f/]',
290
+ '∗' => '\[**]',
291
+ '≤' => '\[<=]',
292
+ '≥' => '\[>=]',
293
+ '≪' => '\[<<]',
294
+ '≫' => '\[>>]',
295
+ '=' => '\[eq]',
296
+ '≠' => '\[!=]',
297
+ '≡' => '\[==]',
298
+ '≢' => '\[ne]',
299
+ '≅' => '\[=~]',
300
+ '≃' => '\[|=]',
301
+ '∼' => '\[ap]',
302
+ '≈' => '\[~~]',
303
+ '≈' => '\[~=]',
304
+ '∝' => '\[pt]',
305
+ '∅' => '\[es]',
306
+ '∈' => '\[mo]',
307
+ '∉' => '\[nm]',
308
+ '⊂' => '\[sb]',
309
+ '⊄' => '\[nb]',
310
+ '⊃' => '\[sp]',
311
+ '⊅' => '\[nc]',
312
+ '⊆' => '\[ib]',
313
+ '⊇' => '\[ip]',
314
+ '∩' => '\[ca]',
315
+ '∪' => '\[cu]',
316
+ '∠' => '\[/_]',
317
+ '⊥' => '\[pp]',
318
+ '∫' => '\[is]',
319
+ '∫' => '\[integral]',
320
+ '∑' => '\[sum]',
321
+ '∏' => '\[product]',
322
+ '∐' => '\[coproduct]',
323
+ '∇' => '\[gr]',
324
+ '√' => '\[sr]',
325
+ '√' => '\[sqrt]',
326
+ '⌈' => '\[lc]',
327
+ '⌉' => '\[rc]',
328
+ '⌊' => '\[lf]',
329
+ '⌋' => '\[rf]',
330
+ '∞' => '\[if]',
331
+ 'ℵ' => '\[Ah]',
332
+ 'ℑ' => '\[Im]',
333
+ 'ℜ' => '\[Re]',
334
+ '℘' => '\[wp]',
335
+ '∂' => '\[pd]',
336
+ 'ℏ' => '\[-h]',
337
+ 'ℏ' => '\[hbar]',
338
+ # Greek glyphs
339
+ 'Α' => '\[*A]',
340
+ 'Β' => '\[*B]',
341
+ 'Γ' => '\[*G]',
342
+ 'Δ' => '\[*D]',
343
+ 'Ε' => '\[*E]',
344
+ 'Ζ' => '\[*Z]',
345
+ 'Η' => '\[*Y]',
346
+ 'Θ' => '\[*H]',
347
+ 'Ι' => '\[*I]',
348
+ 'Κ' => '\[*K]',
349
+ 'Λ' => '\[*L]',
350
+ 'Μ' => '\[*M]',
351
+ 'Ν' => '\[*N]',
352
+ 'Ξ' => '\[*C]',
353
+ 'Ο' => '\[*O]',
354
+ 'Π' => '\[*P]',
355
+ 'Ρ' => '\[*R]',
356
+ 'Σ' => '\[*S]',
357
+ 'Τ' => '\[*T]',
358
+ 'Υ' => '\[*U]',
359
+ 'Φ' => '\[*F]',
360
+ 'Χ' => '\[*X]',
361
+ 'Ψ' => '\[*Q]',
362
+ 'Ω' => '\[*W]',
363
+ 'α' => '\[*a]',
364
+ 'β' => '\[*b]',
365
+ 'γ' => '\[*g]',
366
+ 'δ' => '\[*d]',
367
+ 'ε' => '\[*e]',
368
+ 'ζ' => '\[*z]',
369
+ 'η' => '\[*y]',
370
+ 'θ' => '\[*h]',
371
+ 'ι' => '\[*i]',
372
+ 'κ' => '\[*k]',
373
+ 'λ' => '\[*l]',
374
+ 'μ' => '\[*m]',
375
+ 'ν' => '\[*n]',
376
+ 'ξ' => '\[*c]',
377
+ 'ο' => '\[*o]',
378
+ 'π' => '\[*p]',
379
+ 'ρ' => '\[*r]',
380
+ 'ς' => '\[ts]',
381
+ 'σ' => '\[*s]',
382
+ 'τ' => '\[*t]',
383
+ 'υ' => '\[*u]',
384
+ 'ϕ' => '\[*f]',
385
+ 'χ' => '\[*x]',
386
+ 'ψ' => '\[*q]',
387
+ 'ω' => '\[*w]',
388
+ 'ϑ' => '\[+h]',
389
+ 'φ' => '\[+f]',
390
+ 'ϖ' => '\[+p]',
391
+ 'ϵ' => '\[+e]',
392
+ # Card symbols
393
+ '♣' => '\[CL]',
394
+ '♠' => '\[SP]',
395
+ '♥' => '\[HE]',
396
+ '♡' => '\[u2661]',
397
+ '♦' => '\[DI]',
398
+ '♢' => '\[u2662]'
399
+ }
400
+
401
+ # Regular expression to convert unicode characters into glyphs
402
+ GLYPH_REGEXP = Regexp.union(GLYPHS.keys)
403
+
38
404
  #
39
405
  # Initializes the converter.
40
406
  #
@@ -324,8 +690,9 @@ module Kramdown
324
690
  def convert_p(p)
325
691
  children = p.children
326
692
 
327
- if (children.length >= 2) &&
328
- (children.first.type == :em || children.first.type == :codespan)
693
+ if ((children.length >= 2) && (children.first.type == :codespan ||
694
+ children.first.type == :em ||
695
+ children.first.type == :strong))
329
696
  newline = children.find_index { |el|
330
697
  el.type == :text && el.value.start_with?("\n")
331
698
  }
@@ -379,7 +746,7 @@ module Kramdown
379
746
  # The roff output.
380
747
  #
381
748
  def convert_codespan(codespan)
382
- "\\fB\\fC#{codespan.value}\\fR"
749
+ "\\fB#{codespan.value}\\fR"
383
750
  end
384
751
 
385
752
  #
@@ -392,7 +759,7 @@ module Kramdown
392
759
  # The roff output.
393
760
  #
394
761
  def convert_a(a)
395
- href = a.attr['href']
762
+ href = escape(a.attr['href'])
396
763
  text = convert_children(a.children)
397
764
 
398
765
  case href
@@ -436,7 +803,7 @@ module Kramdown
436
803
  # The escaped text.
437
804
  #
438
805
  def escape(text)
439
- text.gsub('\\','\&\&').gsub('-','\\-')
806
+ text.gsub(GLYPH_REGEXP) { |char| GLYPHS[char] }
440
807
  end
441
808
 
442
809
  end
@@ -1,6 +1,6 @@
1
1
  module Kramdown
2
2
  module Man
3
3
  # kramdown-man version
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
6
6
  end
data/man/kramdown-man.1 CHANGED
@@ -1,23 +1,23 @@
1
1
  .\" Generated by kramdown-man 0.1.4
2
- .\" https://github.com/postmodern/kramdown-roff#readme
2
+ .\" https://github.com/postmodern/kramdown-man#readme
3
3
  .TH kramdown-man.1 "April 2013" kramdown-man "User Manuals"
4
4
  .LP
5
5
  .SH DESCRIPTION
6
6
  .LP
7
7
  .PP
8
8
  A Kramdown
9
- .UR http://kramdown.rubyforge.org/
10
- .UE convert for converting Markdown files into man pages.
9
+ .UR http:\[sl]\[sl]kramdown\.rubyforge\.org\[sl]
10
+ .UE plugin for converting Markdown files into man pages\.
11
11
  .LP
12
12
  .SH EXAMPLE
13
13
  .LP
14
14
  .nf
15
- require 'kramdown'
16
- require 'kramdown/man'
15
+ require \(aqkramdown\(aq
16
+ require \(aqkramdown\[sl]man\(aq
17
17
 
18
- doc = Kramdown::Document.new(File.read('man/kramdown\-man.1.md'))
19
- File.write('man/kramdown\-man.1',doc.to_man)
20
- system 'man', 'man/kramdown\-man.1'
18
+ doc \[eq] Kramdown::Document\.new(File\.read(\(aqman\[sl]kramdown\-man\.1\.md\(aq))
19
+ File\.write(\(aqman\[sl]kramdown\-man\.1\(aq,doc\.to\[ru]man)
20
+ system \(aqman\(aq, \(aqman\[sl]kramdown\-man\.1\(aq
21
21
  .fi
22
22
  .LP
23
23
  .SH SYNTAX
@@ -25,11 +25,11 @@ system 'man', 'man/kramdown\-man.1'
25
25
  .SS FORMATTING
26
26
  .LP
27
27
  .nf
28
- `code`
28
+ \`code\`
29
29
  .fi
30
30
  .LP
31
31
  .PP
32
- \fB\fCcode\fR
32
+ \fBcode\fR
33
33
  .LP
34
34
  .nf
35
35
  *emphasis*
@@ -48,53 +48,53 @@ system 'man', 'man/kramdown\-man.1'
48
48
  .SS PARAGRAPHS
49
49
  .LP
50
50
  .nf
51
- Normal paragraph.
51
+ Normal paragraph\.
52
52
  .fi
53
53
  .LP
54
54
  .PP
55
- Normal paragraph.
55
+ Normal paragraph\.
56
56
  .LP
57
57
  .nf
58
- `command` [`\-\-foo`] *FILE*
58
+ \`command\` \[lB]\`\-\-foo\`\[rB] *FILE*
59
59
  .fi
60
60
  .LP
61
61
  .HP
62
- \fB\fCcommand\fR [\fB\fC--foo\fR] \fIFILE\fP
62
+ \fBcommand\fR \[lB]\fB--foo\fR\[rB] \fIFILE\fP
63
63
  .LP
64
64
  .nf
65
- `\-\-tagged`
66
- Text here.
65
+ \`\-\-tagged\`
66
+ Text here\.
67
67
  .fi
68
68
  .LP
69
69
  .TP
70
- \fB\fC--tagged\fR
71
- Text here.
70
+ \fB--tagged\fR
71
+ Text here\.
72
72
  .LP
73
73
  .SS LINKS
74
74
  .LP
75
75
  .nf
76
- [website](http://example.com/)
76
+ \[lB]website\[rB](http:\[sl]\[sl]example\.com\[sl])
77
77
  .fi
78
78
  .LP
79
79
  .PP
80
80
  website
81
- .UR http://example.com/
81
+ .UR http:\[sl]\[sl]example\.com\[sl]
82
82
  .UE
83
83
  .LP
84
84
  .nf
85
- [bash](man:bash(1))
85
+ \[lB]bash\[rB](man:bash(1))
86
86
  .fi
87
87
  .LP
88
88
  .PP
89
89
  .BR bash (1)
90
90
  .LP
91
91
  .nf
92
- Email <bob@example.com>
92
+ Email <bob\[at]example\.com>
93
93
  .fi
94
94
  .LP
95
95
  .PP
96
96
  Email
97
- .MT bob@example.com
97
+ .MT bob\[at]example\.com
98
98
  .ME
99
99
  .LP
100
100
  .SS LISTS
@@ -142,42 +142,42 @@ extra paragraph
142
142
  .SS BLOCKQUOTES
143
143
  .LP
144
144
  .nf
145
- > Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
145
+ > Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away\.
146
146
  >
147
- > \-\-Antoine de Saint\-Exupéry
147
+ > \-\-Antoine de Saint\-Exup\['e]ry
148
148
  .fi
149
149
  .LP
150
150
  .PP
151
151
  .RS
152
- Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
152
+ Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away\.
153
153
  .LP
154
- --Antoine de Saint\-Exupéry
154
+ \-\-Antoine de Saint\-Exup\['e]ry
155
155
  .RE
156
156
  .LP
157
157
  .SS CODE BLOCKS
158
158
  .LP
159
159
  .nf
160
- #include <stdio.h>
160
+ \[sh]include <stdio\.h>
161
161
 
162
162
  int main()
163
- {
164
- printf("hello world\\n");
163
+ \[lC]
164
+ printf(\[dq]hello world\en\[dq]);
165
165
  return 0;
166
- }
166
+ \[rC]
167
167
 
168
- #include <stdio.h>
168
+ \[sh]include <stdio\.h>
169
169
 
170
170
  int main()
171
- {
172
- printf("hello world\\n");
171
+ \[lC]
172
+ printf(\[dq]hello world\en\[dq]);
173
173
  return 0;
174
- }
174
+ \[rC]
175
175
  .fi
176
176
  .LP
177
177
  .SH AUTHOR
178
178
  .LP
179
179
  .PP
180
180
  Postmodern
181
- .MT postmodern.mod3@gmail.com
181
+ .MT postmodern\.mod3\[at]gmail\.com
182
182
  .ME
183
183
  .LP
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## DESCRIPTION
4
4
 
5
- A [Kramdown][kramdown] convert for converting Markdown files into man pages.
5
+ A [Kramdown][kramdown] plugin for converting Markdown files into man pages.
6
6
 
7
7
  ## EXAMPLE
8
8
 
@@ -25,7 +25,7 @@ Hello world.
25
25
  ".TH Header",
26
26
  ".LP",
27
27
  ".PP",
28
- "Hello world."
28
+ 'Hello world\.'
29
29
  ].join("\n")
30
30
  end
31
31
  end
@@ -46,7 +46,7 @@ Hello world.
46
46
  ".TH Header",
47
47
  ".LP",
48
48
  ".PP",
49
- "Hello world."
49
+ 'Hello world\.'
50
50
  ].join("\n")
51
51
  end
52
52
  end
@@ -100,8 +100,8 @@ Hello world.
100
100
  let(:doc) { Kramdown::Document.new("-- foo") }
101
101
  let(:sym) { doc.root.children[0].children[0] }
102
102
 
103
- it "should convert ndash symbols back into '--'" do
104
- subject.convert_typographic_sym(sym).should == '--'
103
+ it "should convert ndash symbols back into '\-\-'" do
104
+ subject.convert_typographic_sym(sym).should == "\\-\\-"
105
105
  end
106
106
  end
107
107
 
@@ -109,8 +109,8 @@ Hello world.
109
109
  let(:doc) { Kramdown::Document.new("--- foo") }
110
110
  let(:sym) { doc.root.children[0].children[0] }
111
111
 
112
- it "should convert mdash symbols into ''" do
113
- subject.convert_typographic_sym(sym).should == ''
112
+ it "should convert mdash symbols into '\[em]'" do
113
+ subject.convert_typographic_sym(sym).should == '\[em]'
114
114
  end
115
115
  end
116
116
 
@@ -118,8 +118,8 @@ Hello world.
118
118
  let(:doc) { Kramdown::Document.new("... foo") }
119
119
  let(:sym) { doc.root.children[0].children[0] }
120
120
 
121
- it "should convert mdash symbols into ''" do
122
- subject.convert_typographic_sym(sym).should == ''
121
+ it "should convert mdash symbols into '...'" do
122
+ subject.convert_typographic_sym(sym).should == '...'
123
123
  end
124
124
  end
125
125
 
@@ -127,8 +127,8 @@ Hello world.
127
127
  let(:doc) { Kramdown::Document.new("<< foo") }
128
128
  let(:sym) { doc.root.children[0].children[0] }
129
129
 
130
- it "should convert mdash symbols into '«'" do
131
- subject.convert_typographic_sym(sym).should == '«'
130
+ it "should convert mdash symbols into '\[Fo]'" do
131
+ subject.convert_typographic_sym(sym).should == '\[Fo]'
132
132
  end
133
133
  end
134
134
 
@@ -136,8 +136,8 @@ Hello world.
136
136
  let(:doc) { Kramdown::Document.new("foo >> bar") }
137
137
  let(:sym) { doc.root.children[0].children[1] }
138
138
 
139
- it "should convert mdash symbols into '»'" do
140
- subject.convert_typographic_sym(sym).should == '»'
139
+ it "should convert mdash symbols into '\[Fc]'" do
140
+ subject.convert_typographic_sym(sym).should == '\[Fc]'
141
141
  end
142
142
  end
143
143
 
@@ -145,8 +145,8 @@ Hello world.
145
145
  let(:doc) { Kramdown::Document.new(" << foo") }
146
146
  let(:sym) { doc.root.children[0].children[0] }
147
147
 
148
- it "should convert mdash symbols into '«'" do
149
- subject.convert_typographic_sym(sym).should == '«'
148
+ it "should convert mdash symbols into '\[Fo]'" do
149
+ subject.convert_typographic_sym(sym).should == '\[Fo]'
150
150
  end
151
151
  end
152
152
 
@@ -154,8 +154,8 @@ Hello world.
154
154
  let(:doc) { Kramdown::Document.new("foo >> bar") }
155
155
  let(:sym) { doc.root.children[0].children[1] }
156
156
 
157
- it "should convert mdash symbols into '»'" do
158
- subject.convert_typographic_sym(sym).should == '»'
157
+ it "should convert mdash symbols into '\[Fc]'" do
158
+ subject.convert_typographic_sym(sym).should == '\[Fc]'
159
159
  end
160
160
  end
161
161
  end
@@ -165,8 +165,8 @@ Hello world.
165
165
  let(:doc) { Kramdown::Document.new("'hello world'") }
166
166
  let(:quote) { doc.root.children[0].children.first }
167
167
 
168
- it "should convert lsquo quotes into ''" do
169
- subject.convert_smart_quote(quote).should == ''
168
+ it "should convert lsquo quotes into '\[oq]'" do
169
+ subject.convert_smart_quote(quote).should == '\[oq]'
170
170
  end
171
171
  end
172
172
 
@@ -174,8 +174,8 @@ Hello world.
174
174
  let(:doc) { Kramdown::Document.new("'hello world'") }
175
175
  let(:quote) { doc.root.children[0].children.last }
176
176
 
177
- it "should convert rsquo quotes into ''" do
178
- subject.convert_smart_quote(quote).should == ''
177
+ it "should convert rsquo quotes into '\[cq]'" do
178
+ subject.convert_smart_quote(quote).should == '\[cq]'
179
179
  end
180
180
  end
181
181
 
@@ -183,8 +183,8 @@ Hello world.
183
183
  let(:doc) { Kramdown::Document.new('"hello world"') }
184
184
  let(:quote) { doc.root.children[0].children.first }
185
185
 
186
- it "should convert lsquo quotes into ''" do
187
- subject.convert_smart_quote(quote).should == ''
186
+ it "should convert lsquo quotes into '\[lq]'" do
187
+ subject.convert_smart_quote(quote).should == '\[lq]'
188
188
  end
189
189
  end
190
190
 
@@ -192,8 +192,8 @@ Hello world.
192
192
  let(:doc) { Kramdown::Document.new('"hello world"') }
193
193
  let(:quote) { doc.root.children[0].children.last }
194
194
 
195
- it "should convert lsquo quotes into ''" do
196
- subject.convert_smart_quote(quote).should == ''
195
+ it "should convert lsquo quotes into '\[rq]'" do
196
+ subject.convert_smart_quote(quote).should == '\[rq]'
197
197
  end
198
198
  end
199
199
  end
@@ -322,8 +322,6 @@ Hello world.
322
322
  let(:doc) { Kramdown::Document.new("1. #{text1}\n\n #{text2}") }
323
323
 
324
324
  it "should convert the other p elements to '.IP \\\\n\\n...'" do
325
- p li
326
-
327
325
  subject.convert_ol_li(li).should == [
328
326
  ".IP \\n+[step0]",
329
327
  text1,
@@ -346,22 +344,24 @@ Hello world.
346
344
  end
347
345
 
348
346
  describe "#convert_blockquote" do
349
- let(:text) { "Some quote." }
350
- let(:doc) { Kramdown::Document.new("> #{text}") }
351
- let(:blockquote) { doc.root.children[0] }
347
+ let(:text) { "Some quote." }
348
+ let(:escaped_text) { 'Some quote\.' }
349
+ let(:doc) { Kramdown::Document.new("> #{text}") }
350
+ let(:blockquote) { doc.root.children[0] }
352
351
 
353
352
  it "should convert blockquote elements into '.PP\\n.RS\\ntext...\\n.RE'" do
354
- subject.convert_blockquote(blockquote).should == ".PP\n.RS\n#{text}\n.RE"
353
+ subject.convert_blockquote(blockquote).should == ".PP\n.RS\n#{escaped_text}\n.RE"
355
354
  end
356
355
  end
357
356
 
358
357
  describe "#convert_codeblock" do
359
- let(:code) { "puts 'hello world'" }
360
- let(:doc) { Kramdown::Document.new(" #{code}\n") }
361
- let(:codeblock) { doc.root.children[0] }
358
+ let(:code) { "puts 'hello world'" }
359
+ let(:escaped_code) { 'puts \(aqhello world\(aq' }
360
+ let(:doc) { Kramdown::Document.new(" #{code}\n") }
361
+ let(:codeblock) { doc.root.children[0] }
362
362
 
363
363
  it "should convert codeblock elements into '.nf\\ntext...\\n.fi'" do
364
- subject.convert_codeblock(codeblock).should == ".nf\n#{code}\n.fi"
364
+ subject.convert_codeblock(codeblock).should == ".nf\n#{escaped_code}\n.fi"
365
365
  end
366
366
  end
367
367
 
@@ -376,12 +376,13 @@ Hello world.
376
376
  end
377
377
 
378
378
  describe "#convert_p" do
379
- let(:text) { "Hello world." }
380
- let(:doc) { Kramdown::Document.new(text) }
381
- let(:p) { doc.root.children[0] }
379
+ let(:text) { "Hello world." }
380
+ let(:escaped_text) { 'Hello world\.' }
381
+ let(:doc) { Kramdown::Document.new(text) }
382
+ let(:p) { doc.root.children[0] }
382
383
 
383
384
  it "should convert p elements into '.PP\\ntext'" do
384
- subject.convert_p(p).should == ".PP\n#{text}"
385
+ subject.convert_p(p).should == ".PP\n#{escaped_text}"
385
386
  end
386
387
 
387
388
  context "when the paragraph starts with a codespan element" do
@@ -389,16 +390,16 @@ Hello world.
389
390
  let(:text) { 'Foo bar baz' }
390
391
  let(:doc) { Kramdown::Document.new("`#{option}`\n\t#{text}") }
391
392
 
392
- it "should convert p elements into '.TP\\n\\fB\\fC--option\\fR\\ntext...'" do
393
- subject.convert_p(p).should == ".TP\n\\fB\\fC#{option}\\fR\n#{text}"
393
+ it "should convert p elements into '.TP\\n\\fB--option\\fR\\ntext...'" do
394
+ subject.convert_p(p).should == ".TP\n\\fB#{option}\\fR\n#{text}"
394
395
  end
395
396
 
396
397
  context "when there is only one codespan element" do
397
398
  let(:code) { 'code' }
398
399
  let(:doc) { Kramdown::Document.new("`#{code}`") }
399
400
 
400
- it "should convert p elements into '.PP\\n\\fB\\fC...\\fR'" do
401
- subject.convert_p(p).should == ".PP\n\\fB\\fC#{code}\\fR"
401
+ it "should convert p elements into '.PP\\n\\fB...\\fR'" do
402
+ subject.convert_p(p).should == ".PP\n\\fB#{code}\\fR"
402
403
  end
403
404
  end
404
405
 
@@ -408,53 +409,60 @@ Hello world.
408
409
  let(:text) { 'Foo bar baz' }
409
410
  let(:doc) { Kramdown::Document.new("`#{flag}`, `#{option}`\n\t#{text}") }
410
411
 
411
- it "should convert p elements into '.TP\\n\\fB\\fC-o\\fR, \\fB\\fC--option\\fR\\ntext...'" do
412
- subject.convert_p(p).should == ".TP\n\\fB\\fC#{flag}\\fR, \\fB\\fC#{option}\\fR\n#{text}"
412
+ it "should convert p elements into '.TP\\n\\fB-o\\fR, \\fB--option\\fR\\ntext...'" do
413
+ subject.convert_p(p).should == ".TP\n\\fB#{flag}\\fR, \\fB#{option}\\fR\n#{text}"
413
414
  end
414
415
 
415
416
  context "when there is no newline" do
416
417
  let(:doc) { Kramdown::Document.new("`#{flag}` `#{option}`") }
417
418
 
418
419
  it "should convert the p element into a '.HP\\n...'" do
419
- subject.convert_p(p).should == ".HP\n\\fB\\fC#{flag}\\fR \\fB\\fC#{option}\\fR"
420
+ subject.convert_p(p).should == ".HP\n\\fB#{flag}\\fR \\fB#{option}\\fR"
420
421
  end
421
422
  end
422
423
  end
423
424
  end
424
425
 
425
426
  context "when the paragraph starts with a em element" do
426
- let(:option) { '--foo' }
427
- let(:text) { 'Foo bar baz' }
428
- let(:doc) { Kramdown::Document.new("*#{option}*\n\t#{text}") }
427
+ let(:option) { '--foo' }
428
+ let(:escaped_option) { "\\-\\-foo" }
429
+ let(:text) { 'Foo bar baz' }
430
+
431
+ let(:doc) do
432
+ Kramdown::Document.new("*#{option}*\n\t#{text}")
433
+ end
429
434
 
430
- it "should convert p elements into '.TP\\n\\fB\\fC--option\\fR\\ntext...'" do
431
- subject.convert_p(p).should == ".TP\n\\fI#{option}\\fP\n#{text}"
435
+ it "should convert p elements into '.TP\\n\\fI--option\\fP\\ntext...'" do
436
+ subject.convert_p(p).should == ".TP\n\\fI#{escaped_option}\\fP\n#{text}"
432
437
  end
433
438
 
434
439
  context "when there is only one em element" do
435
440
  let(:text) { 'foo' }
436
441
  let(:doc) { Kramdown::Document.new("*#{text}*") }
437
442
 
438
- it "should convert p elements into '.PP\\n\\fB\\fC...\\fR'" do
443
+ it "should convert p elements into '.PP\\n\\fI...\\fP'" do
439
444
  subject.convert_p(p).should == ".PP\n\\fI#{text}\\fP"
440
445
  end
441
446
  end
442
447
 
443
448
  context "when there are more than one em element" do
444
- let(:flag) { '-f' }
445
- let(:option) { '--foo' }
446
- let(:text) { 'Foo bar baz' }
447
- let(:doc) { Kramdown::Document.new("*#{flag}*, *#{option}*\n\t#{text}") }
449
+ let(:flag) { '-f' }
450
+ let(:escaped_flag) { "\\-f" }
451
+ let(:text) { 'Foo bar baz' }
448
452
 
449
- it "should convert p elements into '.TP\\n\\fI-o\\fP, \\fI--option\\fP\\ntext...'" do
450
- subject.convert_p(p).should == ".TP\n\\fI\\#{flag}\\fP, \\fI#{option}\\fP\n#{text}"
453
+ let(:doc) do
454
+ Kramdown::Document.new("*#{flag}*, *#{option}*\n\t#{text}")
455
+ end
456
+
457
+ it "should convert p elements into '.TP\\n\\fI-o\\fP, \\fI\\-\\-option\\fP\\ntext...'" do
458
+ subject.convert_p(p).should == ".TP\n\\fI#{escaped_flag}\\fP, \\fI#{escaped_option}\\fP\n#{text}"
451
459
  end
452
460
 
453
461
  context "when there is no newline" do
454
462
  let(:doc) { Kramdown::Document.new("*#{flag}* *#{option}*") }
455
463
 
456
464
  it "should convert the p element into a '.HP\\n...'" do
457
- subject.convert_p(p).should == ".HP\n\\fI\\#{flag}\\fP \\fI#{option}\\fP"
465
+ subject.convert_p(p).should == ".HP\n\\fI#{escaped_flag}\\fP \\fI#{escaped_option}\\fP"
458
466
  end
459
467
  end
460
468
  end
@@ -486,36 +494,37 @@ Hello world.
486
494
  let(:doc) { Kramdown::Document.new("`#{code}`") }
487
495
  let(:codespan) { doc.root.children[0].children[0] }
488
496
 
489
- it "should convert codespan elements into '\\fB\\fCcode\\fR'" do
490
- subject.convert_codespan(codespan).should == "\\fB\\fC#{code}\\fR"
497
+ it "should convert codespan elements into '\\fBcode\\fR'" do
498
+ subject.convert_codespan(codespan).should == "\\fB#{code}\\fR"
491
499
  end
492
500
  end
493
501
 
494
502
  describe "#convert_a" do
495
- let(:text) { 'example' }
496
- let(:href) { 'http://example.com/' }
497
- let(:doc) { Kramdown::Document.new("[#{text}](#{href})") }
498
- let(:link) { doc.root.children[0].children[0] }
503
+ let(:text) { 'example' }
504
+ let(:href) { 'http://example.com/' }
505
+ let(:escaped_href) { 'http:\[sl]\[sl]example\.com\[sl]' }
506
+ let(:doc) { Kramdown::Document.new("[#{text}](#{href})") }
507
+ let(:link) { doc.root.children[0].children[0] }
499
508
 
500
509
  it "should convert a link elements into 'text\\n.UR href\\n.UE'" do
501
- subject.convert_a(link).should == "#{text}\n.UR #{href}\n.UE"
510
+ subject.convert_a(link).should == "#{text}\n.UR #{escaped_href}\n.UE"
502
511
  end
503
512
 
504
513
  context "when the href begins with mailto:" do
505
- let(:text) { 'Bob' }
506
- let(:email) { 'bob@example.com' }
507
- let(:doc) { Kramdown::Document.new("[#{text}](mailto:#{email})") }
514
+ let(:text) { 'Bob' }
515
+ let(:email) { 'bob@example.com' }
516
+ let(:escaped_email) { 'bob\[at]example\.com' }
517
+ let(:doc) { Kramdown::Document.new("[#{text}](mailto:#{email})") }
508
518
 
509
519
  it "should convert the link elements into '.MT email\\n.ME'" do
510
- subject.convert_a(link).should == "#{text}\n.MT #{email}\n.ME"
520
+ subject.convert_a(link).should == "#{text}\n.MT #{escaped_email}\n.ME"
511
521
  end
512
522
 
513
523
  context "when link is <email>" do
514
- let(:email) { 'bob@example.com' }
515
- let(:doc) { Kramdown::Document.new("<#{email}>") }
524
+ let(:doc) { Kramdown::Document.new("<#{email}>") }
516
525
 
517
526
  it "should convert the link elements into '.MT email\\n.ME'" do
518
- subject.convert_a(link).should == "\n.MT #{email}\n.ME"
527
+ subject.convert_a(link).should == "\n.MT #{escaped_email}\n.ME"
519
528
  end
520
529
  end
521
530
  end
@@ -540,12 +549,12 @@ Hello world.
540
549
  end
541
550
 
542
551
  describe "#escape" do
543
- it "should escape '\\' as '\\\\'" do
544
- subject.escape("hello\\ world").should == "hello\\\\ world"
545
- end
552
+ let(:text) { "hello\nworld" }
546
553
 
547
- it "should escape '-' as '\\-'" do
548
- subject.escape("foo-bar").should == "foo\\-bar"
554
+ described_class::GLYPHS.each do |char,glyph|
555
+ it "should convert #{char.dump} into #{glyph.dump}" do
556
+ subject.escape("#{text} #{char}").should == "#{text} #{glyph}"
557
+ end
549
558
  end
550
559
  end
551
560
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2013-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: kramdown