Browse files

Fixes for blank line whitespace separation (blank_lines test), separa…

…te para after leading h1, and always have '\n' at end of output.
  • Loading branch information...
1 parent 0f35539 commit 1a742ce3b9fab0fca219b2bb524793fc2b1bd238 @trentm committed Mar 8, 2011
Showing with 111 additions and 15 deletions.
  1. +3 −3 bin/ronn.js
  2. +20 −9 lib/ronn.js
  3. +1 −1 test/cases/basic_document.roff
  4. +56 −0 test/cases/blank_lines.roff
  5. +30 −0 test/cases/blank_lines.ronn
  6. +1 −2 test/test.js
View
6 bin/ronn.js
@@ -96,8 +96,8 @@ if (opts.get("man") && !opts.get("build")) {
if (fHtml) fs.writeFileSync(fBase + ".html", fHtml, 'utf8');
if (fFrag) fs.writeFileSync(fBase + ".fragment", fFrag, 'utf8');
} else {
- if (fRoff) sys.puts(fRoff);
- if (fHtml) sys.puts(fHtml);
- if (fFrag) sys.puts(fFrag);
+ if (fRoff) process.stdout.write(fRoff);
+ if (fHtml) process.stdout.write(fHtml);
+ if (fFrag) process.stdout.write(fFrag);
}
}
View
29 lib/ronn.js
@@ -23,17 +23,18 @@ exports.Ronn = function(text, version, manual, date) {
var gMD = md.parse(text);
prepareTree(gMD);
var gHtml = md.toHTMLTree(gMD);
+ //console.log(JSON.stringify(gHtml));
this.roff = function() {
- return blockFilter("", gHtml, {parent:null, previous:null, position:null});
+ return blockFilter("", gHtml, {parent:null, previous:null, position:null}) + "\n";
};
this.html = function() {
- return toHTML(gHtml);
+ return toHTML(gHtml) + "\n";
};
this.fragment = function() {
- return toHTMLfragment(gHtml);
+ return toHTMLfragment(gHtml) + "\n";
};
function blockFilter(out, node, context) {
@@ -102,16 +103,20 @@ exports.Ronn = function(text, version, manual, date) {
out = macro(out, "HR");
break;
case "p":
- if (fPrevious && fParent && (fParent == "dd" || fParent == "li"))
+ if (fPrevious && fParent && (fParent == "dd" || fParent == "li")) {
out = macro(out, "IP");
- else if (fPrevious == "h4")
+ } else if (fPrevious == "h4") {
out = out + "\n.";
- else if (fPrevious && !(fPrevious == "h1" || fPrevious == "h2" || fPrevious == "h3"))
+ // Ronn also has 'h1' here, but its preprocessing removes the
+ // first 'h1' on a page -- different than the 'h1' preprocessing
+ // in ronnjs -- so the same exclusion doesn't apply here.
+ } else if (fPrevious && !(fPrevious == "h2" || fPrevious == "h3")) {
out = macro(out, "P");
+ }
out = callInlineChildren(out, node, context);
break;
case "pre":
- var indent = (fPrevious == null || !(fPrevious == "h1" || fPrevious == "h2" || fPrevious == "h3"));
+ var indent = (fPrevious == null || !(fPrevious == "h2" || fPrevious == "h3"));
if (indent) out = macro(out, "IP", [quote(""), 4]);
out = macro(out, "nf");
out = callInlineChildren(out, node, context);
@@ -202,9 +207,15 @@ exports.Ronn = function(text, version, manual, date) {
if (context.parent == "pre") {
// do nothing
} else if (context.previous == null && !context.hasNext) {
- node = node.replace(/\n+$/gm, '');
+ // Not sure of the intention here, but this removes desired
+ // whitespace separation in man pages,
+ // e.g. 'test/cases/blank_lines.ronn'.
+ //node = node.replace(/\n+$/gm, '');
} else {
- node = node.replace(/\n+$/gm, ' ');
+ // Not sure of the intention here, but this removes desired
+ // whitespace separation in man pages,
+ // e.g. 'test/cases/blank_lines.ronn'.
+ //node = node.replace(/\n+$/gm, ' ');
}
out += esc(node);
return out;
View
2 test/cases/basic_document.roff
@@ -1,7 +1,7 @@
.\" Generated with Ronnjs/v0.1
.\" http://github.com/kapouer/ronnjs/
.
-.TH "SIMPLE" "7" "December 2010" "1.0" "basic_document"
+.TH "SIMPLE" "7" "December 2010" "" ""
.
.SH "NAME"
\fBsimple\fR \-\- a simple ron example
View
56 test/cases/blank_lines.roff
@@ -0,0 +1,56 @@
+.\" Generated with Ronnjs/v0.1
+.\" http://github.com/kapouer/ronnjs/
+.
+.TH "FOO" "1" "December 2010" "" ""
+.
+.SH "NAME"
+\fBfoo\fR \-\- do some foo
+.
+.SH "SYNOPSIS"
+.
+.nf
+foo [\-v] [\-h]
+.
+.fi
+.
+.SH "DESCRIPTION"
+Do some foo!
+.
+.SH "OPTIONS"
+The following options are supported:
+.
+.P
+\-v
+.
+.IP "" 4
+.
+.nf
+Verbose\.
+
+Or should this be a version option?
+.
+.fi
+.
+.IP "" 0
+.
+.P
+\-h
+.
+.IP "" 4
+.
+.nf
+Help output\.
+
+Perhaps I should add \'\-\-help\' too\.
+.
+.fi
+.
+.IP "" 0
+.
+.SH "SEE ALSO"
+.
+.nf
+bar(1)
+.
+.fi
+
View
30 test/cases/blank_lines.ronn
@@ -0,0 +1,30 @@
+foo(1) -- do some foo
+=====================
+
+## SYNOPSIS
+ foo [-v] [-h]
+
+## DESCRIPTION
+
+Do some foo!
+
+## OPTIONS
+
+The following options are supported:
+
+-v
+
+ Verbose.
+
+ Or should this be a version option?
+
+
+-h
+
+ Help output.
+
+ Perhaps I should add '--help' too.
+
+## SEE ALSO
+
+ bar(1)
View
3 test/test.js
@@ -79,8 +79,7 @@ for (var i=0; i < names.length; ++i) {
} catch(e) {}
test.expect(numTests);
- var base = path.basename(ronnPath).slice(0, -".ronn".length);
- var ronn = new Ronn(fs.readFileSync(ronnPath, 'utf-8'), "1.0", base, "2010-12-25");
+ var ronn = new Ronn(fs.readFileSync(ronnPath, 'utf-8'), "", "", "2010-12-25");
if (expectedRoff !== null) {
var actual = ronn.roff();
test.equal(expectedRoff, actual,

0 comments on commit 1a742ce

Please sign in to comment.