diff --git a/.astylerc b/.astylerc index 0ff809fc..a234a421 100644 --- a/.astylerc +++ b/.astylerc @@ -21,7 +21,7 @@ # Indent pre-processor directives --indent-preproc-block --indent-preproc-define ---indent-preproc-cond +# --indent-preproc-cond # Line endings @@ -42,9 +42,14 @@ # Pointers/References +--align-pointer=middle --align-reference=name +# Line endings +--lineend=linux + + # Excludes --exclude="Sources/libMultiMarkdown/scanners.c" --exclude="Sources/libMultiMarkdown/parser.c" diff --git a/CMakeLists.txt b/CMakeLists.txt index a738a35e..ca59615c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,14 +8,14 @@ cmake_minimum_required (VERSION 2.6) set (My_Project_Title "MultiMarkdown") set (My_Project_Description "Lightweight markup processor to produce HTML, LaTeX, and more.") set (My_Project_Author "Fletcher T. Penney") -set (My_Project_Revised_Date "2018-09-01") +set (My_Project_Revised_Date "2019-12-11") set (My_Project_Version_Major 6) -set (My_Project_Version_Minor 4) +set (My_Project_Version_Minor 5) set (My_Project_Version_Patch 0) set (My_Project_Version "${My_Project_Version_Major}.${My_Project_Version_Minor}.${My_Project_Version_Patch}") -set (My_Project_Copyright_Date "2016 - 2018") +set (My_Project_Copyright_Date "2016 - 2019") set (My_Project_Copyright "Copyright © ${My_Project_Copyright_Date} ${My_Project_Author}.") string(TOUPPER ${My_Project_Title} My_Project_Title_Caps ) @@ -46,12 +46,10 @@ include_directories( ${PROJECT_SOURCE_DIR}/Sources/multimarkdown) include_directories( ${PROJECT_SOURCE_DIR}/test ) include_directories(${PROJECT_BINARY_DIR}) -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") +if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # using Clang # Default is 256 -- needed for localization hash function add_definitions("-fbracket-depth=264") -else() - add_definitions("-std=c99") endif() set(CMAKE_SUPPRESS_REGENERATION 1) @@ -109,7 +107,7 @@ MACRO(ADD_PUBLIC_HEADER target filename) SET_TARGET_PROPERTIES(${target} PROPERTIES XCODE_ATTRIBUTE_VALID_ARCHITECTURES - "x86_64 i386 armv6 armv7 armv7s arm64" + "x86_64 armv6 armv7 armv7s arm64" ) ENDMACRO(ADD_PUBLIC_HEADER) @@ -185,6 +183,10 @@ set(src_files Sources/libMultiMarkdown/epub.c Sources/libMultiMarkdown/file.c Sources/libMultiMarkdown/html.c + Sources/libMultiMarkdown/itmz.c + Sources/libMultiMarkdown/itmz-lexer.c + Sources/libMultiMarkdown/itmz-parser.c + Sources/libMultiMarkdown/itmz-reader.c Sources/libMultiMarkdown/latex.c Sources/libMultiMarkdown/lexer.c Sources/libMultiMarkdown/memoir.c @@ -206,6 +208,7 @@ set(src_files Sources/libMultiMarkdown/token_pairs.c Sources/libMultiMarkdown/transclude.c Sources/libMultiMarkdown/uuid.c + Sources/libMultiMarkdown/xml.c Sources/libMultiMarkdown/writer.c Sources/libMultiMarkdown/zip.c ) @@ -220,6 +223,10 @@ set(header_files Sources/libMultiMarkdown/epub.h Sources/libMultiMarkdown/file.h Sources/libMultiMarkdown/html.h + Sources/libMultiMarkdown/itmz.h + Sources/libMultiMarkdown/itmz-lexer.h + Sources/libMultiMarkdown/itmz-parser.h + Sources/libMultiMarkdown/itmz-reader.h Sources/libMultiMarkdown/latex.h Sources/libMultiMarkdown/lexer.h Sources/libMultiMarkdown/include/libMultiMarkdown.h @@ -241,6 +248,7 @@ set(header_files Sources/libMultiMarkdown/transclude.h Sources/libMultiMarkdown/uthash.h Sources/libMultiMarkdown/uuid.h + Sources/libMultiMarkdown/xml.h Sources/libMultiMarkdown/writer.h Sources/libMultiMarkdown/zip.h ) @@ -349,15 +357,21 @@ configure_file ( # from http://stackoverflow.com/questions/25199677/how-to-detect-if-current-scope-has-a-parent-in-cmake get_directory_property(hasParent PARENT_DIRECTORY) +set(test_files + test/CuTest.c + test/CuTest.h + ${PROJECT_BINARY_DIR}/AllTests.c +) + +# Process source files to look for tests to run +add_custom_command ( + OUTPUT ${PROJECT_BINARY_DIR}/AllTests.c + COMMAND sh ${PROJECT_SOURCE_DIR}/test/make-tests.sh ${PROJECT_SOURCE_DIR}/Sources/libMultiMarkdown/*.c > ${PROJECT_BINARY_DIR}/AllTests.c +) + if(hasParent) # Don't create "run_tests" when we're a sub-project for something else else() - set(test_files - test/CuTest.c - test/CuTest.h - ${PROJECT_BINARY_DIR}/AllTests.c - ) - if (DEFINED TEST) add_definitions(-DTEST) @@ -369,12 +383,6 @@ else() ${header_utility_files} ) - # Process source files to look for tests to run - add_custom_command ( - OUTPUT ${PROJECT_BINARY_DIR}/AllTests.c - COMMAND sh ${PROJECT_SOURCE_DIR}/test/make-tests.sh ${PROJECT_SOURCE_DIR}/Sources/libMultiMarkdown/*.c > ${PROJECT_BINARY_DIR}/AllTests.c - ) - enable_testing() add_test( test ${PROJECT_BINARY_DIR}/run_tests) @@ -397,11 +405,11 @@ endif() if (APPLE) # Configure backwards-compatible support (if your project allows it) - SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.4" CACHE STRING "Deployment target for OSX" FORCE) + SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE STRING "Deployment target for OSX" FORCE) # Compile for x86_64 and i386. ppc no longer supported if(CMAKE_BUILD_TYPE MATCHES "Release") - SET (CMAKE_OSX_ARCHITECTURES x86_64;i386) + SET (CMAKE_OSX_ARCHITECTURES x86_64) endif(CMAKE_BUILD_TYPE MATCHES "Release") # Use PackageMaker for installers? @@ -515,6 +523,7 @@ SET_TARGET_PROPERTIES(libMultiMarkdown PROPERTIES FRAMEWORK TRUE FRAMEWORK_VERSION A MACOSX_FRAMEWORK_IDENTIFIER net.multimarkdown.mmd6 + XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "net.multimarkdown.mmd6" ) ADD_PUBLIC_HEADER(libMultiMarkdown Sources/libMultiMarkdown/include/libMultiMarkdown.h) @@ -670,7 +679,7 @@ ADD_MMD_TEST(mmd-6-beamer "-t beamer" Beamer tex) ADD_MMD_TEST(mmd-6-memoir "-t memoir" Memoir tex) -ADD_MMD_TEST(mmd-6-odf "-t fodt" MMD6Tests fodt) +ADD_MMD_TEST(mmd-6-fodt "-t fodt" MMD6Tests fodt) ADD_MMD_TEST(mmd-6-opml "-t opml" MMD6Tests opml) diff --git a/QuickStart/QuickStart.epub b/QuickStart/QuickStart.epub index 72b0489d..199833d2 100644 Binary files a/QuickStart/QuickStart.epub and b/QuickStart/QuickStart.epub differ diff --git a/QuickStart/QuickStart.fodt b/QuickStart/QuickStart.fodt index 0d9da237..ecbe21ba 100644 --- a/QuickStart/QuickStart.fodt +++ b/QuickStart/QuickStart.fodt @@ -323,89 +323,34 @@ office:mimetype="application/vnd.oasis.opendocument.text"> Version: 6.4.0 -This document serves as a description of MultiMarkdown (MMD) v6, as well as a sample -document to demonstrate the various features. Specifically, differences from -MMD v5 will be pointed out. +This document serves as a description of MultiMarkdown (MMD) v6, as well as a sample document to demonstrate the various features. Specifically, differences from MMD v5 will be pointed out. Performance -A big motivating factor leading to the development of MMD v6 was -performance. When MMD first migrated from Perl to C (based on peg- -markdown), it was among the fastest -Markdown parsers available. That was many years ago, and the “competition” -has made a great deal of progress since that time. +A big motivating factor leading to the development of MMD v6 was performance. When MMD first migrated from Perl to C (based on peg- markdown), it was among the fastest Markdown parsers available. That was many years ago, and the “competition” has made a great deal of progress since that time. -When developing MMD v6, one of my goals was to keep MMD at least in the -ballpark of the fastest processors. Of course, being the fastest would be -fantastic, but I was more concerned with ensuring that the code was easily -understood, and easily updated with new features in the future. +When developing MMD v6, one of my goals was to keep MMD at least in the ballpark of the fastest processors. Of course, being the fastest would be fantastic, but I was more concerned with ensuring that the code was easily understood, and easily updated with new features in the future. -MMD v3 – v5 used a PEGParsing Expression Grammar https://en.wikipedia.org/wiki/Parsing_expression_grammar to handle the parsing. This made it easy to -understand the relationship between the MMD grammar and the parsing code, -since they were one and the same. However, the parsing code generated by -the parsers was not particularly fast, and was prone to troublesome edge -cases with terrible performance characteristics. +MMD v3 – v5 used a PEGParsing Expression Grammar https://en.wikipedia.org/wiki/Parsing_expression_grammar to handle the parsing. This made it easy to understand the relationship between the MMD grammar and the parsing code, since they were one and the same. However, the parsing code generated by the parsers was not particularly fast, and was prone to troublesome edge cases with terrible performance characteristics. -The first step in MMD v6 parsing is to break the source text into a series -of tokens, which may consist of plain text, whitespace, or special characters -such as ‘*’, ‘[’, etc. This chain of tokens is then used to perform the -actual parsing. +The first step in MMD v6 parsing is to break the source text into a series of tokens, which may consist of plain text, whitespace, or special characters such as ‘*’, ‘[’, etc. This chain of tokens is then used to perform the actual parsing. -MMD v6 divides the parsing into two separate phases, which actually fits -more with Markdown’s design philosophically. +MMD v6 divides the parsing into two separate phases, which actually fits more with Markdown’s design philosophically. -Block parsing consists of identifying the “type” of each line of the -source text, and grouping the lines into blocks (e.g. paragraphs, lists, -blockquotes, etc.) Some blocks are a single line (e.g. ATX headers), and -others can be many lines long. The block parsing in MMD v6 is handled -by a parser generated by lemon. This -parser allows the block structure to be more readily understood by -non-programmers, but the generated parser is still fast. - - -Span parsing consists of identifying Markdown/MMD structures that occur -inside of blocks, such as links, images, strong, emph, etc. Most of these -structures require matching pairs of tokens to specify where the span starts -and where it ends. Most of these spans allow arbitrary levels of nesting as -well. This made parsing them correctly in the PEG-based code difficult and -slow. MMD v6 uses a different approach that is accurate and has good -performance characteristics even with edge cases. Basically, it keeps a stack -of each “opening” token as it steps through the token chain. When a “closing” -token is found, it is paired with the most recent appropriate opener on the -stack. Any tokens in between the opener and closer are removed, as they are -not able to be matched any more. To avoid unnecessary searches for non- -existent openers, the parser keeps track of which opening tokens have been -discovered. This allows the parser to continue moving forwards without having -to go backwards and re-parse any previously visited tokens. +Block parsing consists of identifying the “type” of each line of the source text, and grouping the lines into blocks (e.g. paragraphs, lists, blockquotes, etc.) Some blocks are a single line (e.g. ATX headers), and others can be many lines long. The block parsing in MMD v6 is handled by a parser generated by lemon. This parser allows the block structure to be more readily understood by non-programmers, but the generated parser is still fast. + + +Span parsing consists of identifying Markdown/MMD structures that occur inside of blocks, such as links, images, strong, emph, etc. Most of these structures require matching pairs of tokens to specify where the span starts and where it ends. Most of these spans allow arbitrary levels of nesting as well. This made parsing them correctly in the PEG-based code difficult and slow. MMD v6 uses a different approach that is accurate and has good performance characteristics even with edge cases. Basically, it keeps a stack of each “opening” token as it steps through the token chain. When a “closing” token is found, it is paired with the most recent appropriate opener on the stack. Any tokens in between the opener and closer are removed, as they are not able to be matched any more. To avoid unnecessary searches for non- existent openers, the parser keeps track of which opening tokens have been discovered. This allows the parser to continue moving forwards without having to go backwards and re-parse any previously visited tokens. -The result of this redesigned MMD parser is that it can parse short -documents more quickly than CommonMark, and takes -only 15% – 20% longer to parse long documents. I have not delved too deeply -into this, but I presume that CommonMark has a bit more “set-up” time that -becomes expensive when parsing a short document (e.g. a paragraph or two). But -this cost becomes negligible when parsing longer documents (e.g. file sizes of -1 MB). So depending on your use case, CommonMark may well be faster than -MMD, but we’re talking about splitting hairs here…. Recent comparisons -show MMD v6 taking approximately 4.37 seconds to parse a 108 MB file -(approximately 24.8 MB/second), and CommonMark took 3.72 seconds for the same -file (29.2 MB/second). For comparison, MMD v5.4 took approximately 94 -second for the same file (1.15 MB/second). - -For a more realistic file of approx 28 kb (the source of the Markdown Syntax -web page), both MMD and CommonMark parse it too quickly to accurately -measure. In fact, it requires a file consisting of the original file copied -32 times over (0.85 MB) before /usr/bin/env time reports a time over the -minimum threshold of 0.01 seconds for either program. - -There is still potentially room for additional optimization in MMD. -However, even if I can’t close the performance gap with CommonMark on longer -files, the additional features of MMD compared with Markdown in addition to -the increased legibility of the source code of MMD (in my biased opinion -anyway) make this project worthwhile. +The result of this redesigned MMD parser is that it can parse short documents more quickly than CommonMark, and takes only 15% – 20% longer to parse long documents. I have not delved too deeply into this, but I presume that CommonMark has a bit more “set-up” time that becomes expensive when parsing a short document (e.g. a paragraph or two). But this cost becomes negligible when parsing longer documents (e.g. file sizes of 1 MB). So depending on your use case, CommonMark may well be faster than MMD, but we’re talking about splitting hairs here…. Recent comparisons show MMD v6 taking approximately 4.37 seconds to parse a 108 MB file (approximately 24.8 MB/second), and CommonMark took 3.72 seconds for the same file (29.2 MB/second). For comparison, MMD v5.4 took approximately 94 second for the same file (1.15 MB/second). + +For a more realistic file of approx 28 kb (the source of the Markdown Syntax web page), both MMD and CommonMark parse it too quickly to accurately measure. In fact, it requires a file consisting of the original file copied 32 times over (0.85 MB) before /usr/bin/env time reports a time over the minimum threshold of 0.01 seconds for either program. + +There is still potentially room for additional optimization in MMD. However, even if I can’t close the performance gap with CommonMark on longer files, the additional features of MMD compared with Markdown in addition to the increased legibility of the source code of MMD (in my biased opinion anyway) make this project worthwhile. Parse Tree @@ -422,12 +367,10 @@ anyway) make this project worthwhile. Parse token chain into blocks -Parse tokens within each block into span level structures (e.g. strong, -emph, etc.) +Parse tokens within each block into span level structures (e.g. strong, emph, etc.) -Export the token tree into the desired output format (e.g. HTML, LaTeX, -etc.) and return the resulting C style string +Export the token tree into the desired output format (e.g. HTML, LaTeX, etc.) and return the resulting C style string OR @@ -436,72 +379,37 @@ etc.) and return the resulting C style string -The token tree (ASTAbstract Syntax Tree https://en.wikipedia.org/wiki/Abstract_syntax_tree) includes starting offsets and length of each token, -allowing you to use MMD as part of a syntax highlighter. MMD v5 did not -have this functionality in the public version, in part because the PEG parsers -used did not provide reliable offset positions, requiring a great deal of -effort when I adapted MMD for use in MultiMarkdown -Composer. +The token tree (ASTAbstract Syntax Tree https://en.wikipedia.org/wiki/Abstract_syntax_tree) includes starting offsets and length of each token, allowing you to use MMD as part of a syntax highlighter. MMD v5 did not have this functionality in the public version, in part because the PEG parsers used did not provide reliable offset positions, requiring a great deal of effort when I adapted MMD for use in MultiMarkdown Composer. -These steps are managed using the mmd_engine “object”. An individual -mmd_engine cannot be used by multiple threads simultaneously, so if -libMultiMarkdown is to be used in a multithreaded program, a separate -mmd_engine should be created for each thread. Alternatively, just use the -slightly more abstracted mmd_convert_string() function that handles creating -and destroying the mmd_engine automatically. +These steps are managed using the mmd_engine “object”. An individual mmd_engine cannot be used by multiple threads simultaneously, so if libMultiMarkdown is to be used in a multithreaded program, a separate mmd_engine should be created for each thread. Alternatively, just use the slightly more abstracted mmd_convert_string() function that handles creating and destroying the mmd_engine automatically. Features Abbreviations (Or Acronyms) -This file includes the use of MMD as an abbreviation for MultiMarkdown. The -abbreviation will be expanded on the first use, and the shortened form will be -used on subsequent occurrences. +This file includes the use of MMD as an abbreviation for MultiMarkdown. The abbreviation will be expanded on the first use, and the shortened form will be used on subsequent occurrences. -Abbreviations can be specified using inline or reference syntax. The inline -variant requires that the abbreviation be wrapped in parentheses and -immediately follows the >. +Abbreviations can be specified using inline or reference syntax. The inline variant requires that the abbreviation be wrapped in parentheses and immediately follows the >. [>MMD] is an abbreviation. So is [>(MD) Markdown].[>MMD]: MultiMarkdown -There is also a “shortcut” method for abbreviations that is similar to the -approach used in prior versions of MMD. You specify the definition for the -abbreviation in the usual manner, but MMD will automatically identify each -instance where the abbreviation is used and substitute it automatically. In -this case, the abbreviation is limited to a more basic character set which -includes letters, numbers, periods, and hyphens, but not much else. For more -complex abbreviations, you must explicitly mark uses of the abbreviation. +There is also a “shortcut” method for abbreviations that is similar to the approach used in prior versions of MMD. You specify the definition for the abbreviation in the usual manner, but MMD will automatically identify each instance where the abbreviation is used and substitute it automatically. In this case, the abbreviation is limited to a more basic character set which includes letters, numbers, periods, and hyphens, but not much else. For more complex abbreviations, you must explicitly mark uses of the abbreviation. Citations -Citations can be specified using an inline syntax, just like inline footnotes. -If you wish to use BibTeX, then configure the bibtex metadata (required) and -the biblio style metadata (optional). +Citations can be specified using an inline syntax, just like inline footnotes. If you wish to use BibTeX, then configure the bibtex metadata (required) and the biblio style metadata (optional). -The HTML output for citations now uses parentheses instead of brackets, e.g. -(1) instead of [1]. +The HTML output for citations now uses parentheses instead of brackets, e.g. (1) instead of [1]. CriticMarkup -MMD v6 has improved support for CriticMarkup, both in terms of parsing, and -in terms of support for each output format. You can insert text, -delete text, substitute one thingfor another, highlight text, -and leave comments in the text. - -If you don’t specify any command line options, then MMD will apply special -formatting to the CriticMarkup formatting as in the preceding paragraph. -Alternatively, you can use the -a\--accept or -r\--reject options to cause -MMD to accept or reject, respectively, the proposed changes within the CM -markup. When doing this, CM will work across blank lines. Without either of -these two options, then CriticMarkup that spans a blank line is not recogniz +MMD v6 has improved support for CriticMarkup, both in terms of parsing, and in terms of support for each output format. You can insert text, delete text, substitute one thingfor another, highlight text, and leave comments in the text. -T -formats). +If you don’t specify any command line options, then MMD will apply special formatting to the CriticMarkup formatting as in the preceding paragraph. Alternatively, you can use the -a\--accept or -r\--reject options to cause MMD to accept or reject, respectively, the proposed changes within the CM markup. When doing this, CM will work across blank lines. Without either of these two options, then CriticMarkup that spans a blank line is not recognized as such. I am working on options for this for the future. Embedded Images -Supported export formats (odt, epub, bundle, bundlezip) include -images inside the export document: +Supported export formats (odt, epub, bundle, bundlezip) include images inside the export document: @@ -509,42 +417,23 @@ images inside the export document: Local images are embedded automatically -Images stored on remote servers are embedded if libCurl is -properly installed when MMD is compiled. This is true f +Images stored on remote servers are embedded if libCurl is properly installed when MMD is compiled. This is true for macOS builds. -ed -as such. I working on options for this for the future. - Emph and Strong -The basics of emphasis and strong emphasis are unchanged, but the parsing -engine has been improved to be more accurate, particularly in various edge -cases where proper parsing can be difficult. +The basics of emphasis and strong emphasis are unchanged, but the parsing 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. +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. +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. +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. +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 @@ -552,80 +441,55 @@ outputs the HTML 5 file that would serve as the primary content for the EPUB. -The leading and trailing fences can be 3, 4, or 5 backticks in length. That -should be sufficient to account for complex documents without requiring a more -complex parser. +The leading and trailing fences can be 3, 4, or 5 backticks in length. That should be sufficient to account for complex documents without requiring a more complex parser. -If there is no trailing fence, then everything after the leading fence is -considered to be part of the code block. +If there is no trailing fence, then everything after the leading fence is considered to be part of the code block. Footnotes -The HTML output for footnotes now uses superscripts instead of brackets, e.g. -<sup>1</sup> instead of [1]. +The HTML output for footnotes now uses superscripts instead of brackets, e.g. <sup>1</sup> instead of [1]. Glossary Terms -If there are terms in your document you wish to define in a glossaryThe -glossary collects information about important terms used in your document at -the end of your document, you can define them using the glossary syntax. +If there are terms in your document you wish to define in a glossaryThe glossary collects information about important terms used in your document at the end of your document, you can define them using the glossary syntax. -Glossary terms can be specified using inline or reference syntax. The inline -variant requires that the abbreviation be wrapped in parentheses and -immediately follows the ?. +Glossary terms can be specified using inline or reference syntax. The inline variant requires that the abbreviation be wrapped in parentheses and immediately follows the ?. [?(glossary) The glossary collects information about importantterms used in your document] is a glossary term.[?glossary] is also a glossary term.[?glossary]: The glossary collects information about importantterms used in your document -Much like abbreviations, there is also a “shortcut” method that is similar to -the approach used in prior versions of MMD. You specify the definition for -the glossary term in the usual manner, but MMD will automatically identify -each instance where the term is used and substitute it automatically. In this -case, the term is limited to a more basic character set which includes -letters, numbers, periods, and hyphens, but not much else. For more complex -glossary terms, you must explicitly mark uses of the term. +Much like abbreviations, there is also a “shortcut” method that is similar to the approach used in prior versions of MMD. You specify the definition for the glossary term in the usual manner, but MMD will automatically identify each instance where the term is used and substitute it automatically. In this case, the term is limited to a more basic character set which includes letters, numbers, periods, and hyphens, but not much else. For more complex glossary terms, you must explicitly mark uses of the term. HTML Comments -Previously, HTML Comments were used by MultiMarkdown to include raw text for -inclusion in the output file. This was useful, but limited, as it could only -work for one output format at a time. +Previously, HTML Comments were used by MultiMarkdown to include raw text for inclusion in the output file. This was useful, but limited, as it could only work for one output format at a time. -HTML Comments are now only included in HTML output, but not in any other -format since they would cause errors. +HTML Comments are now only included in HTML output, but not in any other format since they would cause errors. -Take a look at the HTML Comments.text file in the test suite for a better -understanding of comment blocks vs comment spans, and how they are parsed. +Take a look at the HTML Comments.text file in the test suite for a better understanding of comment blocks vs comment spans, and how they are parsed. Internationalization -MMD v6 includes support for substituting certain text phrases in other -languages. This only affects the HTML format. +MMD v6 includes support for substituting certain text phrases in other languages. This only affects the HTML format. LaTeX Changes -LaTeX support is slightly different than in prior versions of MMD. It is -designed to be a bit more consistent, and easier for basic use. +LaTeX support is slightly different than in prior versions of MMD. It is designed to be a bit more consistent, and easier for basic use. The previous approach used two types of metadata: -latex input – this uses the name of a latex file that will be used in a -\input{file} command. This key can be used multiple times (the only -metadata key that worked this way), and all the basic metadata is written to -the LaTeX file in order. +latex input – this uses the name of a latex file that will be used in a \input{file} command. This key can be used multiple times (the only metadata key that worked this way), and all the basic metadata is written to the LaTeX file in order. -latex footer – this file worked the same way as latex input, but was -inserted at the end of the file +latex footer – this file worked the same way as latex input, but was inserted at the end of the file -In practice, one typically needs to be able to insert \input commands at -only a few key places in the final document: +In practice, one typically needs to be able to insert \input commands at only a few key places in the final document: @@ -645,43 +509,47 @@ After metadata, and before the body of the document -latex leader – this specifies a file that will be used at the very -beginning of the document. +latex leader – this specifies a file that will be used at the very beginning of the document. -latex begin – this comes after metadata, and before the body of the -document. This will usually include the \begin{document} command, hence the -name. +latex begin – this comes after metadata, and before the body of the document. This will usually include the \begin{document} command, hence the name. latex footer – this comes after the body of the document. -You can use these 3 keys to replace the old latex input metadata keys, as -long as you pay attention as to which is which. If you used more than three -include statements, you may have to combine your latex files to fit into the -new system. +You can use these 3 keys to replace the old latex input metadata keys, as long as you pay attention as to which is which. If you used more than three include statements, you may have to combine your latex files to fit into the new system. -In addition, there is a new shortcut key – latex config. This allows -you to specify a “document name” that is used to automatically identify the -corresponding latex leader, latex begin, and latex footer files. For -example, using latex config: article is the same as using: +In addition, there is a new shortcut key – latex config. This allows you to specify a “document name” that is used to automatically identify the corresponding latex leader, latex begin, and latex footer files. For example, using latex config: article is the same as using: latex leader:mmd6-article-leaderlatex begin:mmd6-article-beginlatex footer:mmd6-article-footer -Using the new system will require migrating your old configuration to the new -naming convention, but once done I believe it should me much more intuitive to -use. +Using the new system will require migrating your old configuration to the new naming convention, but once done I believe it should me much more intuitive to use. -The LaTeX support files included with the MMD v6 repository support the use of -the following latex config values by default: +The LaTeX support files included with the MMD v6 repository support the use of the following latex config values by default: article + + +beamer + + + +letterhead + + + +manuscript + + + +memoir-book + tufte-book @@ -691,46 +559,30 @@ the following latex config -NOTE: You do have to install the MMD support files into the proper -location for your system. I would like to make this easier, but haven’t found -the best configuration yet. +NOTE: You do have to install the MMD support files into the proper location for your system. I would like to make this easier, but haven’t found the best configuration yet. Metadata -Metadata in MMD v6 includes new support for LaTeX – the latex config key -allows you to automatically setup of multiple latex include files at once. -The default setups that I use would typically consist of one LaTeX file to be -included at the top of the file, one to be included right at the beginning of -the document, and one to be included at the end of the document. If you want -to specify the latex files separately, you can use latex leader, latexbegin, and latex footer. +Metadata in MMD v6 includes new support for LaTeX – the latex config key allows you to automatically setup of multiple latex include files at once. The default setups that I use would typically consist of one LaTeX file to be included at the top of the file, one to be included right at the beginning of the document, and one to be included at the end of the document. If you want to specify the latex files separately, you can use latex leader, latex begin, and latex footer. There are new metadata keys for controlling internationalization: -language – specify the content language for a document, using the two -letter code for the language (e.g. en for English). Where possible, this -will also set the default quotes language. +language – specify the content language for a document, using the two letter code for the language (e.g. en for English). Where possible, this will also set the default quotes language. -quotes language – specify which variant of smart quotes to use. Valid -options are dutch, french, german, germanguillemets, swedish, nl, -fr, de, sv. Anything else defaults to English. +quotes language – specify which variant of smart quotes to use. Valid options are dutch, french, german, germanguillemets, swedish, nl, fr, de, sv. Anything else defaults to English. -Additionally, the MMD Header and MMD Footer metadata work slightly -differently. In v5, these fields were used to list names of files that should -be transcluded before and after the main body. In v6, these fields represent -the actual text to be inserted. If you want them to reference separate files, -use the transclusion functionality: +Additionally, the MMD Header and MMD Footer metadata work slightly differently. In v5, these fields were used to list names of files that should be transcluded before and after the main body. In v6, these fields represent the actual text to be inserted. If you want them to reference separate files, use the transclusion functionality: Title:Some TitleMMD Header:This is *MMD* text.MMD Footer:{{footer.txt}} Output Formats -MultiMarkdown 6 supports the following output formats, using the -t -command-line argument: +MultiMarkdown 6 supports the following output formats, using the -t command-line argument: @@ -738,49 +590,51 @@ command-line argument: html – (Default) create HTML 5 -latex – create LaTeX for conversion to PDF using high quality -typography + +latex – create LaTeX for conversion to PDF using high quality typography + + + +beamer and memoir – two additional LaTeX variants for creating slide presentations and longer documents, respectively + + + +mmd – output the MMD text before converting to another format, but after performing transclusion. This format is not generally needed. -beamer and memoir – two additional LaTeX variants for creating -slide presentations and longer documents, respectively + +odt – OpenDocument text file, used by OpenOffice and compatible word processors. Images are embedded inside the file package. -mmd – output the MMD text before converting to another format, -but after performing transclusion. This format is not generally needed. + +fodt – OpenDocument text variant using a single text (XML) file instead of a compressed zip file. Images are not embedded in this format. -odt – OpenDocument text file, used by OpenOffice and compatible -word processors. Images are embedded inside the file package. + +epub – EPUB 3 ebook format. Images and CSS are embedded in the file package. -fodt – OpenDocument text variant using a single text (XML) file -instead of a compressed zip file. Images are not embedded in this format. + +opmlOPML is a standard file format used for a wide range of outlining programs. This allows you to use a single file for editing MultiMarkdown text and for outlining longer documents. MultiMarkdown Composer can read/write the OPML format, making it easy to share documents with other programs. -epub – EPUB 3 ebook format. Images and CSS are embedded in the -file package. + +itmz – ITMZ is the file format used for the iThoughts mind mapping software (macOS, iOS, Windows). Much like OPML, this format allows you to use a single file for your outlining/brainstorming and final production. MultiMarkdown Composer can read/write this format as well, giving you additional flexibility. -bundle – [TextBundle] format consisting of Markdown/MultiMarkdown -text file and embedded images and CSS. Useful for sharing Markdown files -and images between applications (on any OS, but especially on iOS) + +bundle – [TextBundle] format consisting of Markdown/MultiMarkdown text file and embedded images and CSS. Useful for sharing Markdown files and images between applications (on any OS, but especially on iOS) -bundlezip – TextPack variant of the TextBundle format – the file -package is compressed to a single zip file (similar to EPUB and ODor macOS builds. +bundlezip – TextPack variant of the TextBundle format – the file package is compressed to a single zip file (similar to EPUB and ODT formats). Raw Source -In older versions of MultiMarkdown you could use an HTML comment to pass raw -LaTeX or other content to the final document. This worked reasonably well, -but was limited and didn’t work well when exporting to multiple formats. It -was time for something new. +In older versions of MultiMarkdown you could use an HTML comment to pass raw LaTeX or other content to the final document. This worked reasonably well, but was limited and didn’t work well when exporting to multiple formats. It was time for something new. -MMD v6 offers a new feature to handle this. Code spans and code blocks can -be flagged as representing raw source: +MMD v6 offers a new feature to handle this. Code spans and code blocks can be flagged as representing raw source: foo `*bar*`{=html}```{=latex}*foo*``` @@ -795,7 +649,7 @@ be flagged as representing raw source: -odt +odt – for ODT and FODT @@ -812,25 +666,17 @@ be flagged as representing raw source: Table of Contents -By placing {{TOC}} in your document, you can insert an automatically -generated Table of Contents in your document. As of MMD v6, the native -Table of Contents functionality is used when exporting to LaTeX or -OpenDocument formats. +By placing {{TOC}} in your document, you can insert an automatically generated Table of Contents in your document. As of MMD v6, the native Table of Contents functionality is used when exporting to LaTeX or OpenDocument formats. Tables -Tables in MultiMarkdown-6 work basically the same as before, but a caption, if -present, must come after the body of the table, not before. +Tables in MultiMarkdown-6 work basically the same as before, but a caption, if present, must come after the body of the table, not before. Transclusion -File transclusion works basically the same way – {{file}} is used to -indicate a file that needs to be transcluded. {{file.*}} allows for -wildcard transclusion. What’s different is that the way search paths are -handled is more flexible, though it may take a moment to understand. +File transclusion works basically the same way – {{file}} is used to indicate a file that needs to be transcluded. {{file.*}} allows for wildcard transclusion. What’s different is that the way search paths are handled is more flexible, though it may take a moment to understand. -When you process a file with MMD, it uses that file’s directory as the search -path for included files. For example: +When you process a file with MMD, it uses that file’s directory as the search path for included files. For example: @@ -886,17 +732,13 @@ path for included files. For example: -This is the same as MMD v 5. What’s different is that when you transclude a -file, the search path stays the same as the “parent” file, UNLESS you use -the transclude base metadata to override it. The simplest override is: +This is the same as MMD v 5. What’s different is that when you transclude a file, the search path stays the same as the “parent” file, UNLESS you use the transclude base metadata to override it. The simplest override is: transclude base: . -This means that any transclusions within the file will be calculated relative -to the file, regardless of the original search path. +This means that any transclusions within the file will be calculated relative to the file, regardless of the original search path. -Alternatively you could specify that any transclusion happens inside a -subfolder: +Alternatively you could specify that any transclusion happens inside a subfolder: transclude base: folder/ @@ -904,45 +746,32 @@ subfolder: transclude base: /some/path -This flexibility means that you can transclude different files based on -whether a file is being processed by itself or as part of a “parent” file. -This can be useful when a particular file can either be a standalone document, -or a chapter inside a larger document. +This flexibility means that you can transclude different files based on whether a file is being processed by itself or as part of a “parent” file. This can be useful when a particular file can either be a standalone document, or a chapter inside a larger document. Developer Notes -If you’re using MMD as a library in another application, there are a few -things to be aware of. +If you’re using MMD as a library in another application, there are a few things to be aware of. Object Pools -To improve performance, MMD has the option to allocate the memory for the -tokens used in parsing in large chunks (“object pools”). Allocating a single -large chunk of memory is more efficient than allocating many smaller chunks. -However, this does complicate memory management. +To improve performance, MMD has the option to allocate the memory for the tokens used in parsing in large chunks (“object pools”). Allocating a single large chunk of memory is more efficient than allocating many smaller chunks. However, this does complicate memory management. -By default token.h defines kUseObjectPool which enables this performance -improvement. This does require more caution with the way that memory is -managed. (See main.c for an example of how the object pool is allocated and -drained.) I recommend disabling object pools unless you really understand C -memory management, and understand MultiMarkdown’s program flow. Failure to -properly manage the object pool can lead to massive memory leaks, freeing -memory before that is still in use, or other potential problems. +By default token.h defines kUseObjectPool which enables this performance improvement. This does require more caution with the way that memory is managed. (See main.c for an example of how the object pool is allocated and drained.) I recommend disabling object pools unless you really understand C memory management, and understand MultiMarkdown’s program flow. Failure to properly manage the object pool can lead to massive memory leaks, freeing memory that is still in use, or other potential problems. HTML Boolean Attributes -Most HTML attributes are of the key-value type (e.g. key="value"). But some -less frequently used attributes are boolean attributes (e.g. <videocontrols>). Properly distinguishing HTML from other uses of the < -character requires matching both types under certain circumstances. +Most HTML attributes are of the key-value type (e.g. key="value"). But some less frequently used attributes are boolean attributes (e.g. <video controls>). Properly distinguishing HTML from other uses of the < character requires matching both types under certain circumstances. There are some trade-offs to be made: -Performance when compiling MultiMarkdown + +Performance when compiling MultiMarkdown -Performance when processing parts of documents that are not HTML + +Performance when processing parts of documents that are not HTML Accuracy when matching HTML @@ -953,28 +782,16 @@ character requires matching both types under certain circumstances. -Ignore boolean attributes – this is how MMD-6 started. This is fast, but -not accurate for some users. Several users found issues with the <video> tag -when MMD was used in HTML heavy documents. +Ignore boolean attributes – this is how MMD-6 started. This is fast, but not accurate for some users. Several users found issues with the <video> tag when MMD was used in HTML heavy documents. -Use regexp to match all boolean attributes. This is fast to compile, but -adds roughly 5–8% processing time (probably due to false positive HTML -matches). This may cause some text to be classified as HTML when it -shouldn’t. +Use regexp to match all boolean attributes. This is fast to compile, but adds roughly 5–8% processing time (probably due to false positive HTML matches). This may cause some text to be classified as HTML when it shouldn’t. -Explicitly match all possible boolean attributes – This would presumably be -relatively fast when processing (due to the nature of re2c lexers), but it may -be prohibitively slow to compile for some users. As someone who compiles MMD -frequently, it is too slow to compile be useful for me during development. +Explicitly match all possible boolean attributes – This would presumably be relatively fast when processing (due to the nature of re2c lexers), but it may be prohibitively slow to compile for some users. As someone who compiles MMD frequently, it is too slow to compile for it to be usable by me during development. -Use a hand-curated list of boolean attributes that are most commonly used – -this does not incur much of a performance hit when parsing, and compiles -faster than the complete list of all boolean attributes. For now, this is the -option I have chosen as default for MMD – it seems to be a reasonable trade- -off. I will continue to research additional options. +Use a hand-curated list of boolean attributes that are most commonly used – this does not incur much of a performance hit when parsing, and compiles faster than the complete list of all boolean attributes. For now, this is the option I have chosen as default for MMD – it seems to be a reasonable trade-off. I will continue to research additional options. @@ -984,11 +801,7 @@ off. I will continue to research additional options. -OPML export support is not available in v6. I plan on adding improved -support for this at some point. I was hoping to be able to re-use the -existing v6 parser but it might be simpler to use the approach from v5 and -earlier, which was to have a separate parser tuned to only identify headers -and “stuff between headers”. +OPML export support is not available in v6. I plan on adding improved support for this at some point. I was hoping to be able to re-use the existing v6 parser but it might be simpler to use the approach from v5 and earlier, which was to have a separate parser tuned to only identify headers and “stuff between headers”.OPML read/write support implemented. diff --git a/QuickStart/QuickStart.html b/QuickStart/QuickStart.html index 2a557632..d76ccdd0 100644 --- a/QuickStart/QuickStart.html +++ b/QuickStart/QuickStart.html @@ -51,85 +51,30 @@

Introduction

Version: 6.4.0

-

This document serves as a description of MultiMarkdown (MMD) v6, as well as a sample -document to demonstrate the various features. Specifically, differences from -MMD v5 will be pointed out.

+

This document serves as a description of MultiMarkdown (MMD) v6, as well as a sample document to demonstrate the various features. Specifically, differences from MMD v5 will be pointed out.

Performance

-

A big motivating factor leading to the development of MMD v6 was -performance. When MMD first migrated from Perl to C (based on peg- -markdown), it was among the fastest -Markdown parsers available. That was many years ago, and the “competition” -has made a great deal of progress since that time.

+

A big motivating factor leading to the development of MMD v6 was performance. When MMD first migrated from Perl to C (based on peg- markdown), it was among the fastest Markdown parsers available. That was many years ago, and the “competition” has made a great deal of progress since that time.

-

When developing MMD v6, one of my goals was to keep MMD at least in the -ballpark of the fastest processors. Of course, being the fastest would be -fantastic, but I was more concerned with ensuring that the code was easily -understood, and easily updated with new features in the future.

+

When developing MMD v6, one of my goals was to keep MMD at least in the ballpark of the fastest processors. Of course, being the fastest would be fantastic, but I was more concerned with ensuring that the code was easily understood, and easily updated with new features in the future.

-

MMD v3 – v5 used a PEG to handle the parsing. This made it easy to -understand the relationship between the MMD grammar and the parsing code, -since they were one and the same. However, the parsing code generated by -the parsers was not particularly fast, and was prone to troublesome edge -cases with terrible performance characteristics.

+

MMD v3 – v5 used a PEG to handle the parsing. This made it easy to understand the relationship between the MMD grammar and the parsing code, since they were one and the same. However, the parsing code generated by the parsers was not particularly fast, and was prone to troublesome edge cases with terrible performance characteristics.

-

The first step in MMD v6 parsing is to break the source text into a series -of tokens, which may consist of plain text, whitespace, or special characters -such as ‘*’, ‘[’, etc. This chain of tokens is then used to perform the -actual parsing.

+

The first step in MMD v6 parsing is to break the source text into a series of tokens, which may consist of plain text, whitespace, or special characters such as ‘*’, ‘[’, etc. This chain of tokens is then used to perform the actual parsing.

-

MMD v6 divides the parsing into two separate phases, which actually fits -more with Markdown’s design philosophically.

+

MMD v6 divides the parsing into two separate phases, which actually fits more with Markdown’s design philosophically.

    -
  1. Block parsing consists of identifying the “type” of each line of the -source text, and grouping the lines into blocks (e.g. paragraphs, lists, -blockquotes, etc.) Some blocks are a single line (e.g. ATX headers), and -others can be many lines long. The block parsing in MMD v6 is handled -by a parser generated by lemon. This -parser allows the block structure to be more readily understood by -non-programmers, but the generated parser is still fast.

  2. -
  3. Span parsing consists of identifying Markdown/MMD structures that occur -inside of blocks, such as links, images, strong, emph, etc. Most of these -structures require matching pairs of tokens to specify where the span starts -and where it ends. Most of these spans allow arbitrary levels of nesting as -well. This made parsing them correctly in the PEG-based code difficult and -slow. MMD v6 uses a different approach that is accurate and has good -performance characteristics even with edge cases. Basically, it keeps a stack -of each “opening” token as it steps through the token chain. When a “closing” -token is found, it is paired with the most recent appropriate opener on the -stack. Any tokens in between the opener and closer are removed, as they are -not able to be matched any more. To avoid unnecessary searches for non- -existent openers, the parser keeps track of which opening tokens have been -discovered. This allows the parser to continue moving forwards without having -to go backwards and re-parse any previously visited tokens.

  4. +
  5. Block parsing consists of identifying the “type” of each line of the source text, and grouping the lines into blocks (e.g. paragraphs, lists, blockquotes, etc.) Some blocks are a single line (e.g. ATX headers), and others can be many lines long. The block parsing in MMD v6 is handled by a parser generated by lemon. This parser allows the block structure to be more readily understood by non-programmers, but the generated parser is still fast.

  6. +
  7. Span parsing consists of identifying Markdown/MMD structures that occur inside of blocks, such as links, images, strong, emph, etc. Most of these structures require matching pairs of tokens to specify where the span starts and where it ends. Most of these spans allow arbitrary levels of nesting as well. This made parsing them correctly in the PEG-based code difficult and slow. MMD v6 uses a different approach that is accurate and has good performance characteristics even with edge cases. Basically, it keeps a stack of each “opening” token as it steps through the token chain. When a “closing” token is found, it is paired with the most recent appropriate opener on the stack. Any tokens in between the opener and closer are removed, as they are not able to be matched any more. To avoid unnecessary searches for non- existent openers, the parser keeps track of which opening tokens have been discovered. This allows the parser to continue moving forwards without having to go backwards and re-parse any previously visited tokens.

-

The result of this redesigned MMD parser is that it can parse short -documents more quickly than CommonMark, and takes -only 15% – 20% longer to parse long documents. I have not delved too deeply -into this, but I presume that CommonMark has a bit more “set-up” time that -becomes expensive when parsing a short document (e.g. a paragraph or two). But -this cost becomes negligible when parsing longer documents (e.g. file sizes of -1 MB). So depending on your use case, CommonMark may well be faster than -MMD, but we’re talking about splitting hairs here…. Recent comparisons -show MMD v6 taking approximately 4.37 seconds to parse a 108 MB file -(approximately 24.8 MB/second), and CommonMark took 3.72 seconds for the same -file (29.2 MB/second). For comparison, MMD v5.4 took approximately 94 -second for the same file (1.15 MB/second).

- -

For a more realistic file of approx 28 kb (the source of the Markdown Syntax -web page), both MMD and CommonMark parse it too quickly to accurately -measure. In fact, it requires a file consisting of the original file copied -32 times over (0.85 MB) before /usr/bin/env time reports a time over the -minimum threshold of 0.01 seconds for either program.

- -

There is still potentially room for additional optimization in MMD. -However, even if I can’t close the performance gap with CommonMark on longer -files, the additional features of MMD compared with Markdown in addition to -the increased legibility of the source code of MMD (in my biased opinion -anyway) make this project worthwhile.

+

The result of this redesigned MMD parser is that it can parse short documents more quickly than CommonMark, and takes only 15% – 20% longer to parse long documents. I have not delved too deeply into this, but I presume that CommonMark has a bit more “set-up” time that becomes expensive when parsing a short document (e.g. a paragraph or two). But this cost becomes negligible when parsing longer documents (e.g. file sizes of 1 MB). So depending on your use case, CommonMark may well be faster than MMD, but we’re talking about splitting hairs here…. Recent comparisons show MMD v6 taking approximately 4.37 seconds to parse a 108 MB file (approximately 24.8 MB/second), and CommonMark took 3.72 seconds for the same file (29.2 MB/second). For comparison, MMD v5.4 took approximately 94 second for the same file (1.15 MB/second).

+ +

For a more realistic file of approx 28 kb (the source of the Markdown Syntax web page), both MMD and CommonMark parse it too quickly to accurately measure. In fact, it requires a file consisting of the original file copied 32 times over (0.85 MB) before /usr/bin/env time reports a time over the minimum threshold of 0.01 seconds for either program.

+ +

There is still potentially room for additional optimization in MMD. However, even if I can’t close the performance gap with CommonMark on longer files, the additional features of MMD compared with Markdown in addition to the increased legibility of the source code of MMD (in my biased opinion anyway) make this project worthwhile.

Parse Tree

@@ -139,148 +84,85 @@

Parse Tree

  • Start with a null-terminated string of source text (C style string)

  • Lex string into token chain

  • Parse token chain into blocks

  • -
  • Parse tokens within each block into span level structures (e.g. strong, -emph, etc.)

  • -
  • Export the token tree into the desired output format (e.g. HTML, LaTeX, -etc.) and return the resulting C style string

    +
  • Parse tokens within each block into span level structures (e.g. strong, emph, etc.)

  • +
  • Export the token tree into the desired output format (e.g. HTML, LaTeX, etc.) and return the resulting C style string

    OR

  • Use the resulting token tree for your own purposes.

  • -

    The token tree (AST) includes starting offsets and length of each token, -allowing you to use MMD as part of a syntax highlighter. MMD v5 did not -have this functionality in the public version, in part because the PEG parsers -used did not provide reliable offset positions, requiring a great deal of -effort when I adapted MMD for use in MultiMarkdown -Composer.

    +

    The token tree (AST) includes starting offsets and length of each token, allowing you to use MMD as part of a syntax highlighter. MMD v5 did not have this functionality in the public version, in part because the PEG parsers used did not provide reliable offset positions, requiring a great deal of effort when I adapted MMD for use in MultiMarkdown Composer.

    -

    These steps are managed using the mmd_engine “object”. An individual -mmd_engine cannot be used by multiple threads simultaneously, so if -libMultiMarkdown is to be used in a multithreaded program, a separate -mmd_engine should be created for each thread. Alternatively, just use the -slightly more abstracted mmd_convert_string() function that handles creating -and destroying the mmd_engine automatically.

    +

    These steps are managed using the mmd_engine “object”. An individual mmd_engine cannot be used by multiple threads simultaneously, so if libMultiMarkdown is to be used in a multithreaded program, a separate mmd_engine should be created for each thread. Alternatively, just use the slightly more abstracted mmd_convert_string() function that handles creating and destroying the mmd_engine automatically.

    Features

    Abbreviations (Or Acronyms)

    -

    This file includes the use of MMD as an abbreviation for MultiMarkdown. The -abbreviation will be expanded on the first use, and the shortened form will be -used on subsequent occurrences.

    +

    This file includes the use of MMD as an abbreviation for MultiMarkdown. The abbreviation will be expanded on the first use, and the shortened form will be used on subsequent occurrences.

    -

    Abbreviations can be specified using inline or reference syntax. The inline -variant requires that the abbreviation be wrapped in parentheses and -immediately follows the >.

    +

    Abbreviations can be specified using inline or reference syntax. The inline variant requires that the abbreviation be wrapped in parentheses and immediately follows the >.

    [>MMD] is an abbreviation.  So is [>(MD) Markdown].
     
     [>MMD]: MultiMarkdown
     
    -

    There is also a “shortcut” method for abbreviations that is similar to the -approach used in prior versions of MMD. You specify the definition for the -abbreviation in the usual manner, but MMD will automatically identify each -instance where the abbreviation is used and substitute it automatically. In -this case, the abbreviation is limited to a more basic character set which -includes letters, numbers, periods, and hyphens, but not much else. For more -complex abbreviations, you must explicitly mark uses of the abbreviation.

    +

    There is also a “shortcut” method for abbreviations that is similar to the approach used in prior versions of MMD. You specify the definition for the abbreviation in the usual manner, but MMD will automatically identify each instance where the abbreviation is used and substitute it automatically. In this case, the abbreviation is limited to a more basic character set which includes letters, numbers, periods, and hyphens, but not much else. For more complex abbreviations, you must explicitly mark uses of the abbreviation.

    Citations

    -

    Citations can be specified using an inline syntax, just like inline footnotes. -If you wish to use BibTeX, then configure the bibtex metadata (required) and -the biblio style metadata (optional).

    +

    Citations can be specified using an inline syntax, just like inline footnotes. If you wish to use BibTeX, then configure the bibtex metadata (required) and the biblio style metadata (optional).

    -

    The HTML output for citations now uses parentheses instead of brackets, e.g. -(1) instead of [1].

    +

    The HTML output for citations now uses parentheses instead of brackets, e.g. (1) instead of [1].

    CriticMarkup

    -

    MMD v6 has improved support for CriticMarkup, both in terms of parsing, and -in terms of support for each output format. You can insert text, -delete text, substitute one thingfor another, highlight text, -and leave comments in the text.

    +

    MMD v6 has improved support for CriticMarkup, both in terms of parsing, and in terms of support for each output format. You can insert text, delete text, substitute one thingfor another, highlight text, and leave comments in the text.

    -

    If you don’t specify any command line options, then MMD will apply special -formatting to the CriticMarkup formatting as in the preceding paragraph. -Alternatively, you can use the -a\--accept or -r\--reject options to cause -MMD to accept or reject, respectively, the proposed changes within the CM -markup. When doing this, CM will work across blank lines. Without either of -these two options, then CriticMarkup that spans a blank line is not recogniz

    - -

    T -formats).

    +

    If you don’t specify any command line options, then MMD will apply special formatting to the CriticMarkup formatting as in the preceding paragraph. Alternatively, you can use the -a\--accept or -r\--reject options to cause MMD to accept or reject, respectively, the proposed changes within the CM markup. When doing this, CM will work across blank lines. Without either of these two options, then CriticMarkup that spans a blank line is not recognized as such. I am working on options for this for the future.

    Embedded Images

    -

    Supported export formats (odt, epub, bundle, bundlezip) include -images inside the export document:

    +

    Supported export formats (odt, epub, bundle, bundlezip) include images inside the export document:

    • Local images are embedded automatically
    • -
    • Images stored on remote servers are embedded if libCurl is -properly installed when MMD is compiled. This is true f
    • +
    • Images stored on remote servers are embedded if libCurl is properly installed when MMD is compiled. This is true for macOS builds.
    -

    ed -as such. I working on options for this for the future.

    -

    Emph and Strong

    -

    The basics of emphasis and strong emphasis are unchanged, but the parsing -engine has been improved to be more accurate, particularly in various edge -cases where proper parsing can be difficult.

    +

    The basics of emphasis and strong emphasis are unchanged, but the parsing 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.

    +

    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.

    +

    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.

    +

    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.

    +

    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:

      -
    1. The leading and trailing fences can be 3, 4, or 5 backticks in length. That -should be sufficient to account for complex documents without requiring a more -complex parser.

    2. -
    3. If there is no trailing fence, then everything after the leading fence is -considered to be part of the code block.

    4. +
    5. The leading and trailing fences can be 3, 4, or 5 backticks in length. That should be sufficient to account for complex documents without requiring a more complex parser.

    6. +
    7. If there is no trailing fence, then everything after the leading fence is considered to be part of the code block.

    Footnotes

    -

    The HTML output for footnotes now uses superscripts instead of brackets, e.g. -<sup>1</sup> instead of [1].

    +

    The HTML output for footnotes now uses superscripts instead of brackets, e.g. <sup>1</sup> instead of [1].

    Glossary Terms

    -

    If there are terms in your document you wish to define in a glossary at -the end of your document, you can define them using the glossary syntax.

    +

    If there are terms in your document you wish to define in a glossary at the end of your document, you can define them using the glossary syntax.

    -

    Glossary terms can be specified using inline or reference syntax. The inline -variant requires that the abbreviation be wrapped in parentheses and -immediately follows the ?.

    +

    Glossary terms can be specified using inline or reference syntax. The inline variant requires that the abbreviation be wrapped in parentheses and immediately follows the ?.

    [?(glossary) The glossary collects information about important
     terms used in your document] is a glossary term.
    @@ -291,49 +173,32 @@ 

    Glossary Terms

    terms used in your document
    -

    Much like abbreviations, there is also a “shortcut” method that is similar to -the approach used in prior versions of MMD. You specify the definition for -the glossary term in the usual manner, but MMD will automatically identify -each instance where the term is used and substitute it automatically. In this -case, the term is limited to a more basic character set which includes -letters, numbers, periods, and hyphens, but not much else. For more complex -glossary terms, you must explicitly mark uses of the term.

    +

    Much like abbreviations, there is also a “shortcut” method that is similar to the approach used in prior versions of MMD. You specify the definition for the glossary term in the usual manner, but MMD will automatically identify each instance where the term is used and substitute it automatically. In this case, the term is limited to a more basic character set which includes letters, numbers, periods, and hyphens, but not much else. For more complex glossary terms, you must explicitly mark uses of the term.

    HTML Comments

    -

    Previously, HTML Comments were used by MultiMarkdown to include raw text for -inclusion in the output file. This was useful, but limited, as it could only -work for one output format at a time.

    +

    Previously, HTML Comments were used by MultiMarkdown to include raw text for inclusion in the output file. This was useful, but limited, as it could only work for one output format at a time.

    -

    HTML Comments are now only included in HTML output, but not in any other -format since they would cause errors.

    +

    HTML Comments are now only included in HTML output, but not in any other format since they would cause errors.

    -

    Take a look at the HTML Comments.text file in the test suite for a better -understanding of comment blocks vs comment spans, and how they are parsed.

    +

    Take a look at the HTML Comments.text file in the test suite for a better understanding of comment blocks vs comment spans, and how they are parsed.

    Internationalization

    -

    MMD v6 includes support for substituting certain text phrases in other -languages. This only affects the HTML format.

    +

    MMD v6 includes support for substituting certain text phrases in other languages. This only affects the HTML format.

    LaTeX Changes

    -

    LaTeX support is slightly different than in prior versions of MMD. It is -designed to be a bit more consistent, and easier for basic use.

    +

    LaTeX support is slightly different than in prior versions of MMD. It is designed to be a bit more consistent, and easier for basic use.

    The previous approach used two types of metadata:

      -
    • latex input – this uses the name of a latex file that will be used in a -\input{file} command. This key can be used multiple times (the only -metadata key that worked this way), and all the basic metadata is written to -the LaTeX file in order.

    • -
    • latex footer – this file worked the same way as latex input, but was -inserted at the end of the file

    • +
    • latex input – this uses the name of a latex file that will be used in a \input{file} command. This key can be used multiple times (the only metadata key that worked this way), and all the basic metadata is written to the LaTeX file in order.

    • +
    • latex footer – this file worked the same way as latex input, but was inserted at the end of the file

    -

    In practice, one typically needs to be able to insert \input commands at -only a few key places in the final document:

    +

    In practice, one typically needs to be able to insert \input commands at only a few key places in the final document:

    1. At the very beginning
    2. @@ -344,72 +209,48 @@

      LaTeX Changes

      MMD 6 standardizes the metadata to use 3 new keys:

        -
      1. latex leader – this specifies a file that will be used at the very -beginning of the document.

      2. -
      3. latex begin – this comes after metadata, and before the body of the -document. This will usually include the \begin{document} command, hence the -name.

      4. +
      5. latex leader – this specifies a file that will be used at the very beginning of the document.

      6. +
      7. latex begin – this comes after metadata, and before the body of the document. This will usually include the \begin{document} command, hence the name.

      8. latex footer – this comes after the body of the document.

      -

      You can use these 3 keys to replace the old latex input metadata keys, as -long as you pay attention as to which is which. If you used more than three -include statements, you may have to combine your latex files to fit into the -new system.

      +

      You can use these 3 keys to replace the old latex input metadata keys, as long as you pay attention as to which is which. If you used more than three include statements, you may have to combine your latex files to fit into the new system.

      -

      In addition, there is a new shortcut key – latex config. This allows -you to specify a “document name” that is used to automatically identify the -corresponding latex leader, latex begin, and latex footer files. For -example, using latex config: article is the same as using:

      +

      In addition, there is a new shortcut key – latex config. This allows you to specify a “document name” that is used to automatically identify the corresponding latex leader, latex begin, and latex footer files. For example, using latex config: article is the same as using:

      latex leader:	mmd6-article-leader
       latex begin:	mmd6-article-begin
       latex footer:	mmd6-article-footer
       
      -

      Using the new system will require migrating your old configuration to the new -naming convention, but once done I believe it should me much more intuitive to -use.

      +

      Using the new system will require migrating your old configuration to the new naming convention, but once done I believe it should me much more intuitive to use.

      -

      The LaTeX support files included with the MMD v6 repository support the use of -the following latex config values by default:

      +

      The LaTeX support files included with the MMD v6 repository support the use of the following latex config values by default:

      • article
      • +
      • beamer
      • +
      • letterhead
      • +
      • manuscript
      • +
      • memoir-book
      • tufte-book
      • tufte-handout
      -

      NOTE: You do have to install the MMD support files into the proper -location for your system. I would like to make this easier, but haven’t found -the best configuration yet.

      +

      NOTE: You do have to install the MMD support files into the proper location for your system. I would like to make this easier, but haven’t found the best configuration yet.

      Metadata

      -

      Metadata in MMD v6 includes new support for LaTeX – the latex config key -allows you to automatically setup of multiple latex include files at once. -The default setups that I use would typically consist of one LaTeX file to be -included at the top of the file, one to be included right at the beginning of -the document, and one to be included at the end of the document. If you want -to specify the latex files separately, you can use latex leader, latex -begin, and latex footer.

      +

      Metadata in MMD v6 includes new support for LaTeX – the latex config key allows you to automatically setup of multiple latex include files at once. The default setups that I use would typically consist of one LaTeX file to be included at the top of the file, one to be included right at the beginning of the document, and one to be included at the end of the document. If you want to specify the latex files separately, you can use latex leader, latex begin, and latex footer.

      There are new metadata keys for controlling internationalization:

        -
      • language – specify the content language for a document, using the two -letter code for the language (e.g. en for English). Where possible, this -will also set the default quotes language.

      • -
      • quotes language – specify which variant of smart quotes to use. Valid -options are dutch, french, german, germanguillemets, swedish, nl, -fr, de, sv. Anything else defaults to English.

      • +
      • language – specify the content language for a document, using the two letter code for the language (e.g. en for English). Where possible, this will also set the default quotes language.

      • +
      • quotes language – specify which variant of smart quotes to use. Valid options are dutch, french, german, germanguillemets, swedish, nl, fr, de, sv. Anything else defaults to English.

      -

      Additionally, the MMD Header and MMD Footer metadata work slightly -differently. In v5, these fields were used to list names of files that should -be transcluded before and after the main body. In v6, these fields represent -the actual text to be inserted. If you want them to reference separate files, -use the transclusion functionality:

      +

      Additionally, the MMD Header and MMD Footer metadata work slightly differently. In v5, these fields were used to list names of files that should be transcluded before and after the main body. In v6, these fields represent the actual text to be inserted. If you want them to reference separate files, use the transclusion functionality:

      Title:	Some Title
       MMD Header:	This is *MMD* text.
      @@ -418,39 +259,27 @@ 

      Metadata

      Output Formats

      -

      MultiMarkdown 6 supports the following output formats, using the -t -command-line argument:

      +

      MultiMarkdown 6 supports the following output formats, using the -t command-line argument:

      • html – (Default) create HTML 5
      • -
      • latex – create LaTeX for conversion to PDF using high quality -typography
      • -
      • beamer and memoir – two additional LaTeX variants for creating -slide presentations and longer documents, respectively
      • -
      • mmd – output the MMD text before converting to another format, -but after performing transclusion. This format is not generally needed.
      • -
      • odt – OpenDocument text file, used by OpenOffice and compatible -word processors. Images are embedded inside the file package.
      • -
      • fodt – OpenDocument text variant using a single text (XML) file -instead of a compressed zip file. Images are not embedded in this format.
      • -
      • epub – EPUB 3 ebook format. Images and CSS are embedded in the -file package.
      • -
      • bundle – [TextBundle] format consisting of Markdown/MultiMarkdown -text file and embedded images and CSS. Useful for sharing Markdown files -and images between applications (on any OS, but especially on iOS)
      • -
      • bundlezip – TextPack variant of the TextBundle format – the file -package is compressed to a single zip file (similar to EPUB and ODor macOS builds.
      • +
      • latex – create LaTeX for conversion to PDF using high quality typography
      • +
      • beamer and memoir – two additional LaTeX variants for creating slide presentations and longer documents, respectively
      • +
      • mmd – output the MMD text before converting to another format, but after performing transclusion. This format is not generally needed.
      • +
      • odt – OpenDocument text file, used by OpenOffice and compatible word processors. Images are embedded inside the file package.
      • +
      • fodt – OpenDocument text variant using a single text (XML) file instead of a compressed zip file. Images are not embedded in this format.
      • +
      • epub – EPUB 3 ebook format. Images and CSS are embedded in the file package.
      • +
      • opmlOPML is a standard file format used for a wide range of outlining programs. This allows you to use a single file for editing MultiMarkdown text and for outlining longer documents. MultiMarkdown Composer can read/write the OPML format, making it easy to share documents with other programs.
      • +
      • itmz – ITMZ is the file format used for the iThoughts mind mapping software (macOS, iOS, Windows). Much like OPML, this format allows you to use a single file for your outlining/brainstorming and final production. MultiMarkdown Composer can read/write this format as well, giving you additional flexibility.
      • +
      • bundle – [TextBundle] format consisting of Markdown/MultiMarkdown text file and embedded images and CSS. Useful for sharing Markdown files and images between applications (on any OS, but especially on iOS)
      • +
      • bundlezip – TextPack variant of the TextBundle format – the file package is compressed to a single zip file (similar to EPUB and ODT formats).

      Raw Source

      -

      In older versions of MultiMarkdown you could use an HTML comment to pass raw -LaTeX or other content to the final document. This worked reasonably well, -but was limited and didn’t work well when exporting to multiple formats. It -was time for something new.

      +

      In older versions of MultiMarkdown you could use an HTML comment to pass raw LaTeX or other content to the final document. This worked reasonably well, but was limited and didn’t work well when exporting to multiple formats. It was time for something new.

      -

      MMD v6 offers a new feature to handle this. Code spans and code blocks can -be flagged as representing raw source:

      +

      MMD v6 offers a new feature to handle this. Code spans and code blocks can be flagged as representing raw source:

      foo `*bar*`{=html}
       
      @@ -465,7 +294,7 @@ 

      Raw Source

      • html
      • -
      • odt
      • +
      • odt – for ODT and FODT
      • epub
      • latex
      • * – wildcard matches any output format
      • @@ -473,25 +302,17 @@

        Raw Source

        Table of Contents

        -

        By placing {{TOC}} in your document, you can insert an automatically -generated Table of Contents in your document. As of MMD v6, the native -Table of Contents functionality is used when exporting to LaTeX or -OpenDocument formats.

        +

        By placing {{TOC}} in your document, you can insert an automatically generated Table of Contents in your document. As of MMD v6, the native Table of Contents functionality is used when exporting to LaTeX or OpenDocument formats.

        Tables

        -

        Tables in MultiMarkdown-6 work basically the same as before, but a caption, if -present, must come after the body of the table, not before.

        +

        Tables in MultiMarkdown-6 work basically the same as before, but a caption, if present, must come after the body of the table, not before.

        Transclusion

        -

        File transclusion works basically the same way – {{file}} is used to -indicate a file that needs to be transcluded. {{file.*}} allows for -wildcard transclusion. What’s different is that the way search paths are -handled is more flexible, though it may take a moment to understand.

        +

        File transclusion works basically the same way – {{file}} is used to indicate a file that needs to be transcluded. {{file.*}} allows for wildcard transclusion. What’s different is that the way search paths are handled is more flexible, though it may take a moment to understand.

        -

        When you process a file with MMD, it uses that file’s directory as the search -path for included files. For example:

        +

        When you process a file with MMD, it uses that file’s directory as the search path for included files. For example:

        @@ -527,18 +348,14 @@

        Transclusion

        -

        This is the same as MMD v 5. What’s different is that when you transclude a -file, the search path stays the same as the “parent” file, UNLESS you use -the transclude base metadata to override it. The simplest override is:

        +

        This is the same as MMD v 5. What’s different is that when you transclude a file, the search path stays the same as the “parent” file, UNLESS you use the transclude base metadata to override it. The simplest override is:

        transclude base: .
         
        -

        This means that any transclusions within the file will be calculated relative -to the file, regardless of the original search path.

        +

        This means that any transclusions within the file will be calculated relative to the file, regardless of the original search path.

        -

        Alternatively you could specify that any transclusion happens inside a -subfolder:

        +

        Alternatively you could specify that any transclusion happens inside a subfolder:

        transclude base: folder/
         
        @@ -548,65 +365,37 @@

        Transclusion

        transclude base: /some/path
         
        -

        This flexibility means that you can transclude different files based on -whether a file is being processed by itself or as part of a “parent” file. -This can be useful when a particular file can either be a standalone document, -or a chapter inside a larger document.

        +

        This flexibility means that you can transclude different files based on whether a file is being processed by itself or as part of a “parent” file. This can be useful when a particular file can either be a standalone document, or a chapter inside a larger document.

        Developer Notes

        -

        If you’re using MMD as a library in another application, there are a few -things to be aware of.

        +

        If you’re using MMD as a library in another application, there are a few things to be aware of.

        Object Pools

        -

        To improve performance, MMD has the option to allocate the memory for the -tokens used in parsing in large chunks (“object pools”). Allocating a single -large chunk of memory is more efficient than allocating many smaller chunks. -However, this does complicate memory management.

        +

        To improve performance, MMD has the option to allocate the memory for the tokens used in parsing in large chunks (“object pools”). Allocating a single large chunk of memory is more efficient than allocating many smaller chunks. However, this does complicate memory management.

        -

        By default token.h defines kUseObjectPool which enables this performance -improvement. This does require more caution with the way that memory is -managed. (See main.c for an example of how the object pool is allocated and -drained.) I recommend disabling object pools unless you really understand C -memory management, and understand MultiMarkdown’s program flow. Failure to -properly manage the object pool can lead to massive memory leaks, freeing -memory before that is still in use, or other potential problems.

        +

        By default token.h defines kUseObjectPool which enables this performance improvement. This does require more caution with the way that memory is managed. (See main.c for an example of how the object pool is allocated and drained.) I recommend disabling object pools unless you really understand C memory management, and understand MultiMarkdown’s program flow. Failure to properly manage the object pool can lead to massive memory leaks, freeing memory that is still in use, or other potential problems.

        HTML Boolean Attributes

        -

        Most HTML attributes are of the key-value type (e.g. key="value"). But some -less frequently used attributes are boolean attributes (e.g. <video -controls>). Properly distinguishing HTML from other uses of the < -character requires matching both types under certain circumstances.

        +

        Most HTML attributes are of the key-value type (e.g. key="value"). But some less frequently used attributes are boolean attributes (e.g. <video controls>). Properly distinguishing HTML from other uses of the < character requires matching both types under certain circumstances.

        There are some trade-offs to be made:

          -
        • Performance when compiling MultiMarkdown

        • -
        • Performance when processing parts of documents that are not HTML

        • -
        • Accuracy when matching HTML

        • +
        • Performance when compiling MultiMarkdown
        • +
        • Performance when processing parts of documents that are not HTML
        • +
        • Accuracy when matching HTML

        So far, there seem to be four main approaches:

          -
        • Ignore boolean attributes – this is how MMD-6 started. This is fast, but -not accurate for some users. Several users found issues with the <video> tag -when MMD was used in HTML heavy documents.

        • -
        • Use regexp to match all boolean attributes. This is fast to compile, but -adds roughly 5–8% processing time (probably due to false positive HTML -matches). This may cause some text to be classified as HTML when it -shouldn’t.

        • -
        • Explicitly match all possible boolean attributes – This would presumably be -relatively fast when processing (due to the nature of re2c lexers), but it may -be prohibitively slow to compile for some users. As someone who compiles MMD -frequently, it is too slow to compile be useful for me during development.

        • -
        • Use a hand-curated list of boolean attributes that are most commonly used – -this does not incur much of a performance hit when parsing, and compiles -faster than the complete list of all boolean attributes. For now, this is the -option I have chosen as default for MMD – it seems to be a reasonable trade- -off. I will continue to research additional options.

        • +
        • Ignore boolean attributes – this is how MMD-6 started. This is fast, but not accurate for some users. Several users found issues with the <video> tag when MMD was used in HTML heavy documents.

        • +
        • Use regexp to match all boolean attributes. This is fast to compile, but adds roughly 5–8% processing time (probably due to false positive HTML matches). This may cause some text to be classified as HTML when it shouldn’t.

        • +
        • Explicitly match all possible boolean attributes – This would presumably be relatively fast when processing (due to the nature of re2c lexers), but it may be prohibitively slow to compile for some users. As someone who compiles MMD frequently, it is too slow to compile for it to be usable by me during development.

        • +
        • Use a hand-curated list of boolean attributes that are most commonly used – this does not incur much of a performance hit when parsing, and compiles faster than the complete list of all boolean attributes. For now, this is the option I have chosen as default for MMD – it seems to be a reasonable trade-off. I will continue to research additional options.

        Future Steps

        @@ -614,11 +403,7 @@

        Future Steps

        Some features I plan to implement at some point:

          -
        1. OPML export support is not available in v6. I plan on adding improved -support for this at some point. I was hoping to be able to re-use the -existing v6 parser but it might be simpler to use the approach from v5 and -earlier, which was to have a separate parser tuned to only identify headers -and “stuff between headers”.
        2. +
        3. OPML export support is not available in v6. I plan on adding improved support for this at some point. I was hoping to be able to re-use the existing v6 parser but it might be simpler to use the approach from v5 and earlier, which was to have a separate parser tuned to only identify headers and “stuff between headers”.OPML read/write support implemented.
        @@ -634,8 +419,7 @@

        Future Steps

      • -glossary:

        The -glossary collects information about important terms used in your document  ↩

        +glossary:

        The glossary collects information about important terms used in your document  ↩

    diff --git a/QuickStart/QuickStart.pdf b/QuickStart/QuickStart.pdf index 3b3ff112..9632066c 100644 Binary files a/QuickStart/QuickStart.pdf and b/QuickStart/QuickStart.pdf differ diff --git a/QuickStart/QuickStart.txt b/QuickStart/QuickStart.txt index 08a04bf0..8c2be541 100644 --- a/QuickStart/QuickStart.txt +++ b/QuickStart/QuickStart.txt @@ -11,251 +11,132 @@ uuid: 0d6313fa-9135-477e-9c14-7d62c1977833 # Introduction # -Version: [%version] +Version: [%version] -This document serves as a description of MMD v6, as well as a sample -document to demonstrate the various features. Specifically, differences from -MMD v5 will be pointed out. +This document serves as a description of MMD v6, as well as a sample document to demonstrate the various features. Specifically, differences from MMD v5 will be pointed out. # Performance # -A big motivating factor leading to the development of MMD v6 was -performance. When MMD first migrated from Perl to C (based on [peg- -markdown](https://github.com/jgm/peg-markdown)), it was among the fastest -Markdown parsers available. That was many years ago, and the "competition" -has made a great deal of progress since that time. - -When developing MMD v6, one of my goals was to keep MMD at least in the -ballpark of the fastest processors. Of course, being *the* fastest would be -fantastic, but I was more concerned with ensuring that the code was easily -understood, and easily updated with new features in the future. - -MMD v3 -- v5 used a PEG to handle the parsing. This made it easy to -understand the relationship between the MMD grammar and the parsing code, -since they were one and the same. However, the parsing code generated by -the parsers was not particularly fast, and was prone to troublesome edge -cases with terrible performance characteristics. - -The first step in MMD v6 parsing is to break the source text into a series -of tokens, which may consist of plain text, whitespace, or special characters -such as '*', '[', etc. This chain of tokens is then used to perform the -actual parsing. - -MMD v6 divides the parsing into two separate phases, which actually fits -more with Markdown's design philosophically. - -1. Block parsing consists of identifying the "type" of each line of the -source text, and grouping the lines into blocks (e.g. paragraphs, lists, -blockquotes, etc.) Some blocks are a single line (e.g. ATX headers), and -others can be many lines long. The block parsing in MMD v6 is handled -by a parser generated by [lemon](http://www.hwaci.com/sw/lemon/). This -parser allows the block structure to be more readily understood by -non-programmers, but the generated parser is still fast. - - -2. Span parsing consists of identifying Markdown/MMD structures that occur -inside of blocks, such as links, images, strong, emph, etc. Most of these -structures require matching pairs of tokens to specify where the span starts -and where it ends. Most of these spans allow arbitrary levels of nesting as -well. This made parsing them correctly in the PEG-based code difficult and -slow. MMD v6 uses a different approach that is accurate and has good -performance characteristics even with edge cases. Basically, it keeps a stack -of each "opening" token as it steps through the token chain. When a "closing" -token is found, it is paired with the most recent appropriate opener on the -stack. Any tokens in between the opener and closer are removed, as they are -not able to be matched any more. To avoid unnecessary searches for non- -existent openers, the parser keeps track of which opening tokens have been -discovered. This allows the parser to continue moving forwards without having -to go backwards and re-parse any previously visited tokens. - -The result of this redesigned MMD parser is that it can parse short -documents more quickly than [CommonMark](http://commonmark.org/), and takes -only 15% -- 20% longer to parse long documents. I have not delved too deeply -into this, but I presume that CommonMark has a bit more "set-up" time that -becomes expensive when parsing a short document (e.g. a paragraph or two). But -this cost becomes negligible when parsing longer documents (e.g. file sizes of -1 MB). So depending on your use case, CommonMark may well be faster than -MMD, but we're talking about splitting hairs here.... Recent comparisons -show MMD v6 taking approximately 4.37 seconds to parse a 108 MB file -(approximately 24.8 MB/second), and CommonMark took 3.72 seconds for the same -file (29.2 MB/second). For comparison, MMD v5.4 took approximately 94 -second for the same file (1.15 MB/second). - -For a more realistic file of approx 28 kb (the source of the Markdown Syntax -web page), both MMD and CommonMark parse it too quickly to accurately -measure. In fact, it requires a file consisting of the original file copied -32 times over (0.85 MB) before `/usr/bin/env time` reports a time over the -minimum threshold of 0.01 seconds for either program. - -There is still potentially room for additional optimization in MMD. -However, even if I can't close the performance gap with CommonMark on longer -files, the additional features of MMD compared with Markdown in addition to -the increased legibility of the source code of MMD (in my biased opinion -anyway) make this project worthwhile. +A big motivating factor leading to the development of MMD v6 was performance. When MMD first migrated from Perl to C (based on [peg- markdown](https://github.com/jgm/peg-markdown)), it was among the fastest Markdown parsers available. That was many years ago, and the "competition" has made a great deal of progress since that time. + +When developing MMD v6, one of my goals was to keep MMD at least in the ballpark of the fastest processors. Of course, being *the* fastest would be fantastic, but I was more concerned with ensuring that the code was easily understood, and easily updated with new features in the future. + +MMD v3 -- v5 used a PEG to handle the parsing. This made it easy to understand the relationship between the MMD grammar and the parsing code, since they were one and the same. However, the parsing code generated by the parsers was not particularly fast, and was prone to troublesome edge cases with terrible performance characteristics. + +The first step in MMD v6 parsing is to break the source text into a series of tokens, which may consist of plain text, whitespace, or special characters such as '*', '[', etc. This chain of tokens is then used to perform the actual parsing. + +MMD v6 divides the parsing into two separate phases, which actually fits more with Markdown's design philosophically. + +1. Block parsing consists of identifying the "type" of each line of the source text, and grouping the lines into blocks (e.g. paragraphs, lists, blockquotes, etc.) Some blocks are a single line (e.g. ATX headers), and others can be many lines long. The block parsing in MMD v6 is handled by a parser generated by [lemon](http://www.hwaci.com/sw/lemon/). This parser allows the block structure to be more readily understood by non-programmers, but the generated parser is still fast. + +2. Span parsing consists of identifying Markdown/MMD structures that occur inside of blocks, such as links, images, strong, emph, etc. Most of these structures require matching pairs of tokens to specify where the span starts and where it ends. Most of these spans allow arbitrary levels of nesting as well. This made parsing them correctly in the PEG-based code difficult and slow. MMD v6 uses a different approach that is accurate and has good performance characteristics even with edge cases. Basically, it keeps a stack of each "opening" token as it steps through the token chain. When a "closing" token is found, it is paired with the most recent appropriate opener on the stack. Any tokens in between the opener and closer are removed, as they are not able to be matched any more. To avoid unnecessary searches for non- existent openers, the parser keeps track of which opening tokens have been discovered. This allows the parser to continue moving forwards without having to go backwards and re-parse any previously visited tokens. + +The result of this redesigned MMD parser is that it can parse short documents more quickly than [CommonMark](http://commonmark.org/), and takes only 15% -- 20% longer to parse long documents. I have not delved too deeply into this, but I presume that CommonMark has a bit more "set-up" time that becomes expensive when parsing a short document (e.g. a paragraph or two). But this cost becomes negligible when parsing longer documents (e.g. file sizes of 1 MB). So depending on your use case, CommonMark may well be faster than MMD, but we're talking about splitting hairs here.... Recent comparisons show MMD v6 taking approximately 4.37 seconds to parse a 108 MB file (approximately 24.8 MB/second), and CommonMark took 3.72 seconds for the same file (29.2 MB/second). For comparison, MMD v5.4 took approximately 94 second for the same file (1.15 MB/second). + +For a more realistic file of approx 28 kb (the source of the Markdown Syntax web page), both MMD and CommonMark parse it too quickly to accurately measure. In fact, it requires a file consisting of the original file copied 32 times over (0.85 MB) before `/usr/bin/env time` reports a time over the minimum threshold of 0.01 seconds for either program. + +There is still potentially room for additional optimization in MMD. However, even if I can't close the performance gap with CommonMark on longer files, the additional features of MMD compared with Markdown in addition to the increased legibility of the source code of MMD (in my biased opinion anyway) make this project worthwhile. # Parse Tree # -MMD v6 performs its parsing in the following steps: +MMD v6 performs its parsing in the following steps: -1. Start with a null-terminated string of source text (C style string) +1. Start with a null-terminated string of source text (C style string) -2. Lex string into token chain +2. Lex string into token chain -3. Parse token chain into blocks +3. Parse token chain into blocks -4. Parse tokens within each block into span level structures (e.g. strong, -emph, etc.) +4. Parse tokens within each block into span level structures (e.g. strong, emph, etc.) -5. Export the token tree into the desired output format (e.g. HTML, LaTeX, -etc.) and return the resulting C style string +5. Export the token tree into the desired output format (e.g. HTML, LaTeX, etc.) and return the resulting C style string - **OR** + **OR** -6. Use the resulting token tree for your own purposes. +6. Use the resulting token tree for your own purposes. -The token tree ([?AST]) includes starting offsets and length of each token, -allowing you to use MMD as part of a syntax highlighter. MMD v5 did not -have this functionality in the public version, in part because the PEG parsers -used did not provide reliable offset positions, requiring a great deal of -effort when I adapted MMD for use in [MultiMarkdown -Composer](http://multimarkdown.com/). +The token tree ([?AST]) includes starting offsets and length of each token, allowing you to use MMD as part of a syntax highlighter. MMD v5 did not have this functionality in the public version, in part because the PEG parsers used did not provide reliable offset positions, requiring a great deal of effort when I adapted MMD for use in [MultiMarkdown Composer](http://multimarkdown.com/). -These steps are managed using the `mmd_engine` "object". An individual -`mmd_engine` cannot be used by multiple threads simultaneously, so if -libMultiMarkdown is to be used in a multithreaded program, a separate -`mmd_engine` should be created for each thread. Alternatively, just use the -slightly more abstracted `mmd_convert_string()` function that handles creating -and destroying the `mmd_engine` automatically. +These steps are managed using the `mmd_engine` "object". An individual `mmd_engine` cannot be used by multiple threads simultaneously, so if libMultiMarkdown is to be used in a multithreaded program, a separate `mmd_engine` should be created for each thread. Alternatively, just use the slightly more abstracted `mmd_convert_string()` function that handles creating and destroying the `mmd_engine` automatically. # Features # ## Abbreviations (Or Acronyms) ## -This file includes the use of MMD as an abbreviation for MultiMarkdown. The -abbreviation will be expanded on the first use, and the shortened form will be -used on subsequent occurrences. +This file includes the use of MMD as an abbreviation for MultiMarkdown. The abbreviation will be expanded on the first use, and the shortened form will be used on subsequent occurrences. -Abbreviations can be specified using inline or reference syntax. The inline -variant requires that the abbreviation be wrapped in parentheses and -immediately follows the `>`. +Abbreviations can be specified using inline or reference syntax. The inline variant requires that the abbreviation be wrapped in parentheses and immediately follows the `>`. [>MMD] is an abbreviation. So is [>(MD) Markdown]. [>MMD]: MultiMarkdown -There is also a "shortcut" method for abbreviations that is similar to the -approach used in prior versions of MMD. You specify the definition for the -abbreviation in the usual manner, but MMD will automatically identify each -instance where the abbreviation is used and substitute it automatically. In -this case, the abbreviation is limited to a more basic character set which -includes letters, numbers, periods, and hyphens, but not much else. For more -complex abbreviations, you must explicitly mark uses of the abbreviation. +There is also a "shortcut" method for abbreviations that is similar to the approach used in prior versions of MMD. You specify the definition for the abbreviation in the usual manner, but MMD will automatically identify each instance where the abbreviation is used and substitute it automatically. In this case, the abbreviation is limited to a more basic character set which includes letters, numbers, periods, and hyphens, but not much else. For more complex abbreviations, you must explicitly mark uses of the abbreviation. ## Citations ## -Citations can be specified using an inline syntax, just like inline footnotes. -If you wish to use BibTeX, then configure the `bibtex` metadata (required) and -the `biblio style` metadata (optional). +Citations can be specified using an inline syntax, just like inline footnotes. If you wish to use BibTeX, then configure the `bibtex` metadata (required) and the `biblio style` metadata (optional). -The HTML output for citations now uses parentheses instead of brackets, e.g. -`(1)` instead of `[1]`. +The HTML output for citations now uses parentheses instead of brackets, e.g. `(1)` instead of `[1]`. ## CriticMarkup ## -MMD v6 has improved support for [CriticMarkup], both in terms of parsing, and -in terms of support for each output format. You can {++insert text++}, -{--delete text--}, substitute {~~one thing~>for another~~}, {==highlight text==}, -and {>>leave comments<<} in the text. - -If you don't specify any command line options, then MMD will apply special -formatting to the CriticMarkup formatting as in the preceding paragraph. -Alternatively, you can use the `-a\--accept` or `-r\--reject` options to cause -MMD to accept or reject, respectively, the proposed changes within the CM -markup. When doing this, CM will work across blank lines. Without either of -these two options, then CriticMarkup that spans a blank line is not recogniz +MMD v6 has improved support for [CriticMarkup], both in terms of parsing, and in terms of support for each output format. You can {++insert text++}, {--delete text--}, substitute {~~one thing~>for another~~}, {==highlight text==}, and {>>leave comments<<} in the text. -T -formats). - -[LaTeX]: https://en.wikipedia.org/wiki/LaTeX +If you don't specify any command line options, then MMD will apply special formatting to the CriticMarkup formatting as in the preceding paragraph. Alternatively, you can use the `-a\--accept` or `-r\--reject` options to cause MMD to accept or reject, respectively, the proposed changes within the CM markup. When doing this, CM will work across blank lines. Without either of these two options, then CriticMarkup that spans a blank line is not recognized as such. I am working on options for this for the future. ## Embedded Images ## -Supported export formats (`odt`, `epub`, `bundle`, `bundlezip`) include -images inside the export document: +Supported export formats (`odt`, `epub`, `bundle`, `bundlezip`) include images inside the export document: -* Local images are embedded automatically -* Images stored on remote servers are embedded *if* [libCurl] is -properly installed when MMD is compiled. This is true f +* Local images are embedded automatically +* Images stored on remote servers are embedded *if* [libCurl] is properly installed when MMD is compiled. This is true for macOS builds. -ed -as such. I working on options for this for the future. +[libCurl]: https://curl.haxx.se/libcurl/ ## Emph and Strong ## -The basics of emphasis and strong emphasis are unchanged, but the parsing -engine has been improved to be more accurate, particularly in various edge -cases where proper parsing can be difficult. +The basics of emphasis and strong emphasis are unchanged, but the parsing 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. +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. +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. +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. +**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: +Fenced code blocks are fundamentally the same as MMD v5, except: -1. The leading and trailing fences can be 3, 4, or 5 backticks in length. That -should be sufficient to account for complex documents without requiring a more -complex parser. +1. The leading and trailing fences can be 3, 4, or 5 backticks in length. That should be sufficient to account for complex documents without requiring a more complex parser. -2. If there is no trailing fence, then everything after the leading fence is -considered to be part of the code block. +2. If there is no trailing fence, then everything after the leading fence is considered to be part of the code block. ## Footnotes ## -The HTML output for footnotes now uses superscripts instead of brackets, e.g. -`1` instead of `[1]`. +The HTML output for footnotes now uses superscripts instead of brackets, e.g. `1` instead of `[1]`. ## Glossary Terms ## -If there are terms in your document you wish to define in a [?(glossary) The -glossary collects information about important terms used in your document] at -the end of your document, you can define them using the glossary syntax. +If there are terms in your document you wish to define in a [?(glossary) The glossary collects information about important terms used in your document] at the end of your document, you can define them using the glossary syntax. -Glossary terms can be specified using inline or reference syntax. The inline -variant requires that the abbreviation be wrapped in parentheses and -immediately follows the `?`. +Glossary terms can be specified using inline or reference syntax. The inline variant requires that the abbreviation be wrapped in parentheses and immediately follows the `?`. [?(glossary) The glossary collects information about important terms used in your document] is a glossary term. @@ -265,122 +146,81 @@ immediately follows the `?`. [?glossary]: The glossary collects information about important terms used in your document -Much like abbreviations, there is also a "shortcut" method that is similar to -the approach used in prior versions of MMD. You specify the definition for -the glossary term in the usual manner, but MMD will automatically identify -each instance where the term is used and substitute it automatically. In this -case, the term is limited to a more basic character set which includes -letters, numbers, periods, and hyphens, but not much else. For more complex -glossary terms, you must explicitly mark uses of the term. +Much like abbreviations, there is also a "shortcut" method that is similar to the approach used in prior versions of MMD. You specify the definition for the glossary term in the usual manner, but MMD will automatically identify each instance where the term is used and substitute it automatically. In this case, the term is limited to a more basic character set which includes letters, numbers, periods, and hyphens, but not much else. For more complex glossary terms, you must explicitly mark uses of the term. ## HTML Comments ## -Previously, HTML Comments were used by MultiMarkdown to include raw text for -inclusion in the output file. This was useful, but limited, as it could only -work for one output format at a time. +Previously, HTML Comments were used by MultiMarkdown to include raw text for inclusion in the output file. This was useful, but limited, as it could only work for one output format at a time. -HTML Comments are now only included in HTML output, but not in any other -format since they would cause errors. +HTML Comments are now only included in HTML output, but not in any other format since they would cause errors. -Take a look at the `HTML Comments.text` file in the test suite for a better -understanding of comment blocks vs comment spans, and how they are parsed. +Take a look at the `HTML Comments.text` file in the test suite for a better understanding of comment blocks vs comment spans, and how they are parsed. ## Internationalization ## -MMD v6 includes support for substituting certain text phrases in other -languages. This only affects the HTML format. +MMD v6 includes support for substituting certain text phrases in other languages. This only affects the HTML format. ## LaTeX Changes ## -LaTeX support is slightly different than in prior versions of MMD. It is -designed to be a bit more consistent, and easier for basic use. +LaTeX support is slightly different than in prior versions of MMD. It is designed to be a bit more consistent, and easier for basic use. -The previous approach used two types of metadata: +The previous approach used two types of metadata: -* `latex input` -- this uses the name of a latex file that will be used in a -`\input{file}` command. This key can be used multiple times (the only -metadata key that worked this way), and all the basic metadata is written to -the LaTeX file in order. +* `latex input` -- this uses the name of a latex file that will be used in a `\input{file}` command. This key can be used multiple times (the only metadata key that worked this way), and all the basic metadata is written to the LaTeX file in order. -* `latex footer` -- this file worked the same way as `latex input`, but was -inserted at the end of the file +* `latex footer` -- this file worked the same way as `latex input`, but was inserted at the end of the file -In practice, one typically needs to be able to insert `\input` commands at -only a few key places in the final document: +In practice, one typically needs to be able to insert `\input` commands at only a few key places in the final document: -1. At the very beginning -2. After metadata, and before the body of the document -3. After the body of the document +1. At the very beginning +2. After metadata, and before the body of the document +3. After the body of the document -MMD 6 standardizes the metadata to use 3 new keys: +MMD 6 standardizes the metadata to use 3 new keys: -1. `latex leader` -- this specifies a file that will be used at the very -beginning of the document. +1. `latex leader` -- this specifies a file that will be used at the very beginning of the document. -2. `latex begin` -- this comes after metadata, and before the body of the -document. This will usually include the `\begin{document}` command, hence the -name. +2. `latex begin` -- this comes after metadata, and before the body of the document. This will usually include the `\begin{document}` command, hence the name. -3. `latex footer` -- this comes after the body of the document. +3. `latex footer` -- this comes after the body of the document. -You can use these 3 keys to replace the old `latex input` metadata keys, as -long as you pay attention as to which is which. If you used more than three -include statements, you may have to combine your latex files to fit into the -new system. +You can use these 3 keys to replace the old `latex input` metadata keys, as long as you pay attention as to which is which. If you used more than three include statements, you may have to combine your latex files to fit into the new system. -***In addition***, there is a new shortcut key -- `latex config`. This allows -you to specify a "document name" that is used to automatically identify the -corresponding `latex leader`, `latex begin`, and `latex footer` files. For -example, using `latex config: article` is the same as using: +***In addition***, there is a new shortcut key -- `latex config`. This allows you to specify a "document name" that is used to automatically identify the corresponding `latex leader`, `latex begin`, and `latex footer` files. For example, using `latex config: article` is the same as using: latex leader: mmd6-article-leader latex begin: mmd6-article-begin latex footer: mmd6-article-footer -Using the new system will require migrating your old configuration to the new -naming convention, but once done I believe it should me much more intuitive to -use. +Using the new system will require migrating your old configuration to the new naming convention, but once done I believe it should me much more intuitive to use. -The LaTeX support files included with the MMD v6 repository support the use of -the following `latex config` values by default: +The LaTeX support files included with the MMD v6 repository support the use of the following `latex config` values by default: -* `article` -* `tufte-book` -* `tufte-handout` +* `article` +* `beamer` +* `letterhead` +* `manuscript` +* `memoir-book` +* `tufte-book` +* `tufte-handout` -**NOTE**: You do have to install the MMD support files into the proper -location for your system. I would like to make this easier, but haven't found -the best configuration yet. +**NOTE**: You do have to install the MMD support files into the proper location for your system. I would like to make this easier, but haven't found the best configuration yet. ## Metadata ## -Metadata in MMD v6 includes new support for LaTeX -- the `latex config` key -allows you to automatically setup of multiple `latex include` files at once. -The default setups that I use would typically consist of one LaTeX file to be -included at the top of the file, one to be included right at the beginning of -the document, and one to be included at the end of the document. If you want -to specify the latex files separately, you can use `latex leader`, `latex -begin`, and `latex footer`. +Metadata in MMD v6 includes new support for LaTeX -- the `latex config` key allows you to automatically setup of multiple `latex include` files at once. The default setups that I use would typically consist of one LaTeX file to be included at the top of the file, one to be included right at the beginning of the document, and one to be included at the end of the document. If you want to specify the latex files separately, you can use `latex leader`, `latex begin`, and `latex footer`. -There are new metadata keys for controlling internationalization: +There are new metadata keys for controlling internationalization: -* `language` -- specify the content language for a document, using the two -letter code for the language (e.g. `en` for English). Where possible, this -will also set the default `quotes language`. +* `language` -- specify the content language for a document, using the two letter code for the language (e.g. `en` for English). Where possible, this will also set the default `quotes language`. -* `quotes language` -- specify which variant of smart quotes to use. Valid -options are `dutch`, `french`, `german`, `germanguillemets`, `swedish`, `nl`, -`fr`, `de`, `sv`. Anything else defaults to English. +* `quotes language` -- specify which variant of smart quotes to use. Valid options are `dutch`, `french`, `german`, `germanguillemets`, `swedish`, `nl`, `fr`, `de`, `sv`. Anything else defaults to English. -Additionally, the `MMD Header` and `MMD Footer` metadata work slightly -differently. In v5, these fields were used to list names of files that should -be transcluded before and after the main body. In v6, these fields represent -the actual text to be inserted. If you want them to reference separate files, -use the transclusion functionality: +Additionally, the `MMD Header` and `MMD Footer` metadata work slightly differently. In v5, these fields were used to list names of files that should be transcluded before and after the main body. In v6, these fields represent the actual text to be inserted. If you want them to reference separate files, use the transclusion functionality: Title: Some Title MMD Header: This is *MMD* text. @@ -389,40 +229,32 @@ use the transclusion functionality: ## Output Formats ## -MultiMarkdown 6 supports the following output formats, using the `-t` -command-line argument: +MultiMarkdown 6 supports the following output formats, using the `-t` command-line argument: * `html` -- (Default) create HTML 5 -* `latex` -- create [LaTeX] for conversion to PDF using high quality -typography -* `beamer` and `memoir` -- two additional LaTeX variants for creating -slide presentations and longer documents, respectively -* `mmd` -- output the MMD text before converting to another format, -but after performing transclusion. This format is not generally needed. -* `odt` -- OpenDocument text file, used by OpenOffice and compatible -word processors. Images are embedded inside the file package. -* `fodt` -- OpenDocument text variant using a single text (XML) file -instead of a compressed zip file. Images are not embedded in this format. -* `epub` -- EPUB 3 ebook format. Images and CSS are embedded in the -file package. -* `bundle` -- [TextBundle] format consisting of Markdown/MultiMarkdown -text file and embedded images and CSS. Useful for sharing Markdown files -and images between applications (on any OS, but especially on iOS) -* `bundlezip` -- TextPack variant of the TextBundle format -- the file -package is compressed to a single zip file (similar to EPUB and ODor macOS builds. - -[libCurl]: https://curl.haxx.se/libcurl/ +* `latex` -- create [LaTeX] for conversion to PDF using high quality typography +* `beamer` and `memoir` -- two additional LaTeX variants for creating slide presentations and longer documents, respectively +* `mmd` -- output the MMD text before converting to another format, but after performing transclusion. This format is not generally needed. +* `odt` -- OpenDocument text file, used by OpenOffice and compatible word processors. Images are embedded inside the file package. +* `fodt` -- OpenDocument text variant using a single text (XML) file instead of a compressed zip file. Images are not embedded in this format. +* `epub` -- EPUB 3 ebook format. Images and CSS are embedded in the file package. +* `opml` -- [OPML] is a standard file format used for a wide range of outlining programs. This allows you to use a single file for editing MultiMarkdown text and for outlining longer documents. [MultiMarkdown Composer] can read/write the OPML format, making it easy to share documents with other programs. +* `itmz` -- ITMZ is the file format used for the [iThoughts] mind mapping software (macOS, iOS, Windows). Much like OPML, this format allows you to use a single file for your outlining/brainstorming and final production. [MultiMarkdown Composer] can read/write this format as well, giving you additional flexibility. +* `bundle` -- [TextBundle] format consisting of Markdown/MultiMarkdown text file and embedded images and CSS. Useful for sharing Markdown files and images between applications (on any OS, but especially on iOS) +* `bundlezip` -- TextPack variant of the TextBundle format -- the file package is compressed to a single zip file (similar to EPUB and ODT formats). + + +[iThoughts]: http://www.ithoughts.co.uk/ +[LaTeX]: https://en.wikipedia.org/wiki/LaTeX +[MultiMarkdown Composer]: https://multimarkdown.com/ +[OPML]: http://en.wikipedia.org/wiki/OPML ## Raw Source ## -In older versions of MultiMarkdown you could use an HTML comment to pass raw -LaTeX or other content to the final document. This worked reasonably well, -but was limited and didn't work well when exporting to multiple formats. It -was time for something new. +In older versions of MultiMarkdown you could use an HTML comment to pass raw LaTeX or other content to the final document. This worked reasonably well, but was limited and didn't work well when exporting to multiple formats. It was time for something new. -MMD v6 offers a new feature to handle this. Code spans and code blocks can -be flagged as representing raw source: +MMD v6 offers a new feature to handle this. Code spans and code blocks can be flagged as representing raw source: foo `*bar*`{=html} @@ -430,40 +262,32 @@ be flagged as representing raw source: *foo* ``` -The contents of the span/block will be passed through unchanged. +The contents of the span/block will be passed through unchanged. -You can specify which output format is compatible with the specified source: +You can specify which output format is compatible with the specified source: * `html` -* `odt` +* `odt` -- for ODT and FODT * `epub` * `latex` -* `*` -- wildcard matches any output format +* `*` -- wildcard matches any output format ## Table of Contents ## -By placing `{{TOC}}` in your document, you can insert an automatically -generated Table of Contents in your document. As of MMD v6, the native -Table of Contents functionality is used when exporting to LaTeX or -OpenDocument formats. +By placing `{{TOC}}` in your document, you can insert an automatically generated Table of Contents in your document. As of MMD v6, the native Table of Contents functionality is used when exporting to LaTeX or OpenDocument formats. ## Tables ## -Tables in MultiMarkdown-6 work basically the same as before, but a caption, if -present, must come *after* the body of the table, not *before*. +Tables in MultiMarkdown-6 work basically the same as before, but a caption, if present, must come *after* the body of the table, not *before*. ## Transclusion ## -File transclusion works basically the same way -- `{{file}}` is used to -indicate a file that needs to be transcluded. `{{file.*}}` allows for -wildcard transclusion. What's different is that the way search paths are -handled is more flexible, though it may take a moment to understand. +File transclusion works basically the same way -- `{{file}}` is used to indicate a file that needs to be transcluded. `{{file.*}}` allows for wildcard transclusion. What's different is that the way search paths are handled is more flexible, though it may take a moment to understand. -When you process a file with MMD, it uses that file's directory as the search -path for included files. For example: +When you process a file with MMD, it uses that file's directory as the search path for included files. For example: | Directory | Transcluded Filename | Resolved Path | | ------------------ | ----------------------------- | ------------------------------ | @@ -471,105 +295,68 @@ path for included files. For example: | `/foo/bar/` | `baz/bat` | `/foo/bar/baz/bat` | | `/foo/bar/` | `../bat` | `/foo/bat` | -This is the same as MMD v 5. What's different is that when you transclude a -file, the search path stays the same as the "parent" file, **UNLESS** you use -the `transclude base` metadata to override it. The simplest override is: +This is the same as MMD v 5. What's different is that when you transclude a file, the search path stays the same as the "parent" file, **UNLESS** you use the `transclude base` metadata to override it. The simplest override is: transclude base: . -This means that any transclusions within the file will be calculated relative -to the file, regardless of the original search path. +This means that any transclusions within the file will be calculated relative to the file, regardless of the original search path. + -Alternatively you could specify that any transclusion happens inside a -subfolder: +Alternatively you could specify that any transclusion happens inside a subfolder: transclude base: folder/ -Or you can specify an absolute path: +Or you can specify an absolute path: transclude base: /some/path -This flexibility means that you can transclude different files based on -whether a file is being processed by itself or as part of a "parent" file. -This can be useful when a particular file can either be a standalone document, -or a chapter inside a larger document. +This flexibility means that you can transclude different files based on whether a file is being processed by itself or as part of a "parent" file. This can be useful when a particular file can either be a standalone document, or a chapter inside a larger document. # Developer Notes # -If you're using MMD as a library in another application, there are a few -things to be aware of. +If you're using MMD as a library in another application, there are a few things to be aware of. ## Object Pools ## -To improve performance, MMD has the option to allocate the memory for the -tokens used in parsing in large chunks ("object pools"). Allocating a single -large chunk of memory is more efficient than allocating many smaller chunks. -However, this does complicate memory management. +To improve performance, MMD has the option to allocate the memory for the tokens used in parsing in large chunks ("object pools"). Allocating a single large chunk of memory is more efficient than allocating many smaller chunks. However, this does complicate memory management. -By default `token.h` defines `kUseObjectPool` which enables this performance -improvement. This does require more caution with the way that memory is -managed. (See `main.c` for an example of how the object pool is allocated and -drained.) I recommend disabling object pools unless you really understand C -memory management, and understand MultiMarkdown's program flow. Failure to -properly manage the object pool can lead to massive memory leaks, freeing -memory before that is still in use, or other potential problems. +By default `token.h` defines `kUseObjectPool` which enables this performance improvement. This does require more caution with the way that memory is managed. (See `main.c` for an example of how the object pool is allocated and drained.) I recommend disabling object pools unless you really understand C memory management, and understand MultiMarkdown's program flow. Failure to properly manage the object pool can lead to massive memory leaks, freeing memory that is still in use, or other potential problems. ## HTML Boolean Attributes ## -Most HTML attributes are of the key-value type (e.g. `key="value"`). But some -less frequently used attributes are boolean attributes (e.g. `