From: Fletcher T. Penney
Date: Mon, 13 Mar 2017 19:29:06 +0000 (-0400)
Subject: ADDED: Update QuickStart and EPUB code
X-Git-Tag: 6.0.0-b2~1^2~1
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d47d82c4284ede9a40bc36a1e4552d43eb18ddf3;p=multimarkdown
ADDED: Update QuickStart and EPUB code
---
diff --git a/QuickStart.epub b/QuickStart.epub
index b42caa1..d2da72e 100644
Binary files a/QuickStart.epub and b/QuickStart.epub differ
diff --git a/QuickStart.fodt b/QuickStart.fodt
index c782e8f..10238a1 100644
--- a/QuickStart.fodt
+++ b/QuickStart.fodt
@@ -275,6 +275,7 @@
MultiMarkdown v6 Quick Start Guide
Fletcher T. Penney
6.0-b
+ 0d6313fa-9135-477e-9c14-7d62c1977833
@@ -294,6 +295,7 @@
Citations 1
CriticMarkup 1
Emph and Strong 1
+EPUB 3 Support 1
Fenced Code Blocks 1
Glossary Terms 1
Internationalization 1
@@ -482,6 +484,30 @@ as such. I working on options for this for the future.
engine has been improved to be more accurate, particularly in various edge
cases where proper parsing can be difficult.
+EPUB 3 Support
+
+MMD v6 now provides support for direct creation of EPUB 3 files. Previously
+a separate tool was required to create EPUB files from MMD. It’s now built-
+in. Currently, EPUB 3 files are built using the usual HTML 5 output. No
+extra CSS is applied, so the default from the reader will be used. Images are
+not yet supported, but are planned for the future.
+
+EPUB files can be highly customized with other tools, and I recommend doing
+that for production quality files. For example, apparently performance is
+improved when the content is divided into multiple files (e.g. one file per
+chapter). MMD creates EPUB 3 files using a single file. Tools like Sigil
+are useful for improving your EPUB files, and I recommend doing that.
+
+Not all EPUB readers support v3 files. I don’t plan on adding support for
+older versions of the EPUB format, but other tools can convert to other
+document formats you need. Same goes for Amazon’s ebook formats – the
+Calibre program can also be used to interconvert between formats.
+
+**NOTE: Because EPUB documents are binary files, MMD only creates them when
+**run in batch mode (using the -b\--batch options). Otherwise, it simply
+**outputs the HTML 5 file that would serve as the primary content for the
+**EPUB.
+
Fenced Code Blocks
Fenced code blocks are fundamentally the same as MMD v5, except:
diff --git a/QuickStart.html b/QuickStart.html
index b42ce25..4d1ec69 100644
--- a/QuickStart.html
+++ b/QuickStart.html
@@ -1,10 +1,11 @@
-
+
MultiMarkdown v6 Quick Start Guide
+
@@ -20,6 +21,7 @@
Citations
CriticMarkup
Emph and Strong
+EPUB 3 Support
Fenced Code Blocks
Glossary Terms
Internationalization
@@ -196,6 +198,30 @@ as such. I working on options for this for the future.
engine has been improved to be more accurate, particularly in various edge
cases where proper parsing can be difficult.
+EPUB 3 Support
+
+MMD v6 now provides support for direct creation of EPUB 3 files. Previously
+a separate tool was required to create EPUB files from MMD. It’s now built-
+in. Currently, EPUB 3 files are built using the usual HTML 5 output. No
+extra CSS is applied, so the default from the reader will be used. Images are
+not yet supported, but are planned for the future.
+
+EPUB files can be highly customized with other tools, and I recommend doing
+that for production quality files. For example, apparently performance is
+improved when the content is divided into multiple files (e.g. one file per
+chapter). MMD creates EPUB 3 files using a single file. Tools like Sigil
+are useful for improving your EPUB files, and I recommend doing that.
+
+Not all EPUB readers support v3 files. I don’t plan on adding support for
+older versions of the EPUB format, but other tools can convert to other
+document formats you need. Same goes for Amazon’s ebook formats – the
+Calibre program can also be used to interconvert between formats.
+
+**NOTE: Because EPUB documents are binary files, MMD only creates them when
+**run in batch mode (using the -b\--batch
options). Otherwise, it simply
+**outputs the HTML 5 file that would serve as the primary content for the
+**EPUB.
+
Fenced Code Blocks
Fenced code blocks are fundamentally the same as MMD v5, except:
diff --git a/QuickStart.pdf b/QuickStart.pdf
index 2145d9d..72752fe 100644
Binary files a/QuickStart.pdf and b/QuickStart.pdf differ
diff --git a/QuickStart.txt b/QuickStart.txt
index f3bbdab..491975e 100644
--- a/QuickStart.txt
+++ b/QuickStart.txt
@@ -183,6 +183,31 @@ engine has been improved to be more accurate, particularly in various edge
cases where proper parsing can be difficult.
+## EPUB 3 Support ##
+
+MMD v6 now provides support for direct creation of [EPUB 3] files. Previously
+a separate tool was required to create EPUB files from MMD. It's now built-
+in. Currently, EPUB 3 files are built using the usual HTML 5 output. No
+extra CSS is applied, so the default from the reader will be used. Images are
+not yet supported, but are planned for the future.
+
+EPUB files can be highly customized with other tools, and I recommend doing
+that for production quality files. For example, apparently performance is
+improved when the content is divided into multiple files (e.g. one file per
+chapter). MMD creates EPUB 3 files using a single file. Tools like [Sigil]
+are useful for improving your EPUB files, and I recommend doing that.
+
+Not all EPUB readers support v3 files. I don't plan on adding support for
+older versions of the EPUB format, but other tools can convert to other
+document formats you need. Same goes for Amazon's ebook formats -- the
+[Calibre] program can also be used to interconvert between formats.
+
+**NOTE: Because EPUB documents are binary files, MMD only creates them when
+**run in batch mode (using the `-b\--batch` options). Otherwise, it simply
+**outputs the HTML 5 file that would serve as the primary content for the
+**EPUB.
+
+
## Fenced Code Blocks ##
Fenced code blocks are fundamentally the same as MMD v5, except:
@@ -270,3 +295,9 @@ better integrate this into MMD itself.
[?PEG]: Parsing Expression Grammar
[?AST]: Abstract Syntax Tree
+
+[EPUB 3]: https://en.wikipedia.org/wiki/EPUB
+
+[Sigil]: https://sigil-ebook.com/
+
+[Calibre]: https://calibre-ebook.com/
diff --git a/Sources/libMultiMarkdown/html.c b/Sources/libMultiMarkdown/html.c
index a9fb54d..c6bf025 100644
--- a/Sources/libMultiMarkdown/html.c
+++ b/Sources/libMultiMarkdown/html.c
@@ -1605,10 +1605,18 @@ void mmd_export_token_html_raw(DString * out, const char * source, token * t, sc
void mmd_start_complete_html(DString * out, const char * source, scratch_pad * scratch) {
- print_const("\n\n\n\t\n");
+ meta * m;
+
+ print_const("\nmeta_hash, "language", m);
+ if (m) {
+ printf(" lang=\"%s\"", m->value);
+ } else {
+ print_const(" lang=\"en\"");
+ }
+ print_const(">\n\n\t\n");
// Iterate over metadata keys
- meta * m;
for (m = scratch->meta_hash; m != NULL; m = m->hh.next) {
if (strcmp(m->key, "baseheaderlevel") == 0) {
diff --git a/Sources/multimarkdown/main.c b/Sources/multimarkdown/main.c
index 821b574..7e9445b 100644
--- a/Sources/multimarkdown/main.c
+++ b/Sources/multimarkdown/main.c
@@ -63,6 +63,7 @@
#include "argtable3.h"
#include "critic_markup.h"
#include "d_string.h"
+#include "epub.h"
#include "i18n.h"
#include "libMultiMarkdown.h"
#include "html.h"
@@ -169,7 +170,7 @@ int main(int argc, char** argv) {
a_rem1 = arg_rem("", ""),
- a_format = arg_str0("t", "to", "FORMAT", "convert to FORMAT, FORMAT = html|latex|beamer|memoir|mmd|odf"),
+ a_format = arg_str0("t", "to", "FORMAT", "convert to FORMAT, FORMAT = html|latex|beamer|memoir|mmd|odf|epub"),
a_o = arg_file0("o", "output", "FILE", "send output to FILE"),
a_batch = arg_lit0("b", "batch", "process each file separately"),
@@ -280,6 +281,8 @@ int main(int argc, char** argv) {
format = FORMAT_MMD;
else if (strcmp(a_format->sval[0], "odf") == 0)
format = FORMAT_ODF;
+ else if (strcmp(a_format->sval[0], "epub") == 0)
+ format = FORMAT_EPUB;
else {
// No valid format found
fprintf(stderr, "%s: Unknown output format '%s'\n", binname, a_format->sval[0]);
@@ -340,6 +343,9 @@ int main(int argc, char** argv) {
case FORMAT_MMD:
output_filename = filename_with_extension(a_file->filename[i], ".mmdtext");
break;
+ case FORMAT_EPUB:
+ output_filename = filename_with_extension(a_file->filename[i], ".epub");
+ break;
}
// Perform transclusion(s)
@@ -365,19 +371,24 @@ int main(int argc, char** argv) {
token_pool_init();
#endif
- if (FORMAT_MMD == format) {
+ if (FORMAT_EPUB == format) {
+ mmd_write_to_file(buffer, extensions, format, language, output_filename);
+ result = NULL;
+ } else if (FORMAT_MMD == format) {
result = buffer->str;
} else {
result = mmd_convert_d_string(buffer, extensions, format, language);
}
- if (!(output_stream = fopen(output_filename, "w"))) {
- // Failed to open file
- perror(output_filename);
- } else {
- fputs(result, output_stream);
- fputc('\n', output_stream);
- fclose(output_stream);
+ if (result) {
+ if (!(output_stream = fopen(output_filename, "w"))) {
+ // Failed to open file
+ perror(output_filename);
+ } else {
+ fputs(result, output_stream);
+ fputc('\n', output_stream);
+ fclose(output_stream);
+ }
}
d_string_free(buffer, true);