From 464abd4b9dde46adf30f2885fc6d21d0bc3525ac Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Sun, 10 Jan 2016 01:26:33 -0700 Subject: [PATCH] resolves #424 don't set doctype by default in asciidoctorj cli --- .../asciidoctor/cli/AsciidoctorCliOptions.java | 12 ++++++++++-- .../cli/WhenAsciidoctorIsCalledUsingCli.java | 16 ++++++++++++++++ .../src/test/resources/sample-book.adoc | 8 ++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 asciidoctorj-core/src/test/resources/sample-book.adoc diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/cli/AsciidoctorCliOptions.java b/asciidoctorj-core/src/main/java/org/asciidoctor/cli/AsciidoctorCliOptions.java index a893ff0a..1fdfb0e5 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/cli/AsciidoctorCliOptions.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/cli/AsciidoctorCliOptions.java @@ -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; @@ -139,6 +139,10 @@ public String getDoctype() { return this.doctype; } + public boolean isDoctypeOption() { + return this.doctype != null; + } + public String getOutFile() { return this.outFile; } @@ -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)); diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java b/asciidoctorj-core/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java index d1c13c80..3b971eb9 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java @@ -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() { diff --git a/asciidoctorj-core/src/test/resources/sample-book.adoc b/asciidoctorj-core/src/test/resources/sample-book.adoc new file mode 100644 index 00000000..e7417bb1 --- /dev/null +++ b/asciidoctorj-core/src/test/resources/sample-book.adoc @@ -0,0 +1,8 @@ += Title +:doctype: book + += Part 1 + +== Chapter 1 + +It was a dark and stormy night.