Skip to content

Commit

Permalink
Merge pull request #425 from mojavelinux/issue-424
Browse files Browse the repository at this point in the history
resolves #424 don't set doctype by default in asciidoctorj cli
  • Loading branch information
robertpanzer committed Jan 11, 2016
2 parents 98ebf8b + 464abd4 commit 15642d1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class AsciidoctorCliOptions {
private String backend = "html5";

@Parameter(names = { DOCTYPE, "--doctype" }, description = "document type to use when rendering output: [article, book, inline] (default: article)")
private String doctype = "article";
private String doctype;

@Parameter(names = { OUTFILE, "--out-file" }, description = "output file (default: based on input file path); use - to output to STDOUT")
private String outFile;
Expand Down Expand Up @@ -139,6 +139,10 @@ public String getDoctype() {
return this.doctype;
}

public boolean isDoctypeOption() {
return this.doctype != null;
}

public String getOutFile() {
return this.outFile;
}
Expand Down Expand Up @@ -223,7 +227,11 @@ public Options parse() {
OptionsBuilder optionsBuilder = OptionsBuilder.options();
AttributesBuilder attributesBuilder = AttributesBuilder.attributes();

optionsBuilder.backend(this.backend).safe(this.safeMode).docType(this.doctype).eruby(this.eruby);
optionsBuilder.backend(this.backend).safe(this.safeMode).eruby(this.eruby);

if (isDoctypeOption()) {
optionsBuilder.docType(this.doctype);
}

if (isOutFileOption() && !isOutputStdout()) {
optionsBuilder.toFile(new File(this.outFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ public void with_no_options_file_should_be_rendered_in_place_and_in_html5_format
assertThat(expectedFile.exists(), is(true));
expectedFile.delete();
}

@Test
public void should_honor_doctype_defined_in_document_by_default() throws IOException {
File inputFile = classpath.getResource("sample-book.adoc");
String inputPath = inputFile.getPath().substring(pwd.length() + 1);

new AsciidoctorInvoker().invoke(inputPath);

File expectedFile = new File(inputPath.replaceFirst("\\.adoc$", ".html"));
assertThat(expectedFile.exists(), is(true));
Document doc = Jsoup.parse(expectedFile, "UTF-8");
Elements body = doc.select("body");
String attr = body.attr("class");
assertThat(attr, is("book"));
expectedFile.delete();
}

@Test
public void file_should_be_rendered_to_docbook_with_docbook_backend() {
Expand Down
8 changes: 8 additions & 0 deletions asciidoctorj-core/src/test/resources/sample-book.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
= Title
:doctype: book

= Part 1

== Chapter 1

It was a dark and stormy night.

0 comments on commit 15642d1

Please sign in to comment.