Skip to content

Commit

Permalink
Merge pull request #11 from manikmagar/image-src-path-fix
Browse files Browse the repository at this point in the history
Prevent adding extra <body></body> element.
  • Loading branch information
manikmagar authored Jun 13, 2017
2 parents d090788 + 4326856 commit 9c0da5b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/org/jbake/util/HtmlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public static void fixImageSourceUrls(Map<String, Object> fileContents, Composit
}
}

fileContents.put(Attributes.BODY, document.body().toString());
//User body().children() to prevent adding <body></body> wrap.
fileContents.put(Attributes.BODY, document.body().children().toString());
}

}
16 changes: 16 additions & 0 deletions src/test/java/org/jbake/util/HtmlUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ public class HtmlUtilTest {
public void setUp() throws Exception{
config = ConfigUtil.load(new File(this.getClass().getResource("/fixture").getFile()));
}

@Test
public void shouldNotAddBodyHTMLElement(){
Map<String, Object> fileContent = new HashMap<String, Object>();
fileContent.put(Attributes.ROOTPATH, "../../../");
fileContent.put(Attributes.URI, "blog/2017/05/first_post.html");
fileContent.put(Attributes.BODY, "<div> Test <img src='blog/2017/05/first.jpg' /></div>");

HtmlUtil.fixImageSourceUrls(fileContent, config);

String body = fileContent.get(Attributes.BODY).toString();

assertThat(body).doesNotContain("<body>");
assertThat(body).doesNotContain("</body>");

}

@Test
public void shouldAddRootpath(){
Expand Down

0 comments on commit 9c0da5b

Please sign in to comment.