Fix output with --full-html command line options. Fixes #150.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee51733..6d09292 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,11 @@ Fixes:
A HTML block started in a container block (and not explicitly finished in
the block) could eat 1 line of actual contents.
+ * [#150](https://github.com/mity/md4c/issues/150):
+ Fix md2html utility to output proper DOCTYPE and HTML tags when `full-html`
+ command line options is used, accordingly to the expected output format
+ (HTML or XHTML).
+
## Version 0.4.7
diff --git a/md2html/md2html.c b/md2html/md2html.c
index 818a9cf..1758b0b 100644
--- a/md2html/md2html.c
+++ b/md2html/md2html.c
@@ -152,7 +152,15 @@ process_file(FILE* in, FILE* out)
/* Write down the document in the HTML format. */
if(want_fullhtml) {
- fprintf(out, "<html>\n");
+ if(want_xhtml) {
+ fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ fprintf(out, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" "
+ "\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n");
+ fprintf(out, "<html xmlns=\"http://www.w3.org/1999/xhtml\">");
+ } else {
+ fprintf(out, "<!DOCTYPE html>\n");
+ fprintf(out, "<html>\n");
+ }
fprintf(out, "<head>\n");
fprintf(out, "<title></title>\n");
fprintf(out, "<meta name=\"generator\" content=\"md2html\"%s>\n", want_xhtml ? " /" : "");