Migrate your Markdown to HonKit 8

HonKit 8 reads Markdown by the rules of CommonMark and GitHub Flavored Markdown. HonKit 7 reads it with an older parser, which accepts some text that CommonMark does not.

Most books need no change. Five ways of writing are read differently in a way that readers see. honkit migrate rewrites them. The changed text has the same output in both versions.

The command is in HonKit 7.3 or later and in HonKit 8. The command of HonKit 8 finds more: an emphasis with a space inside of the marks, and the files that a page includes.

Before the update, with HonKit 7

Update to the latest HonKit 7 first. honkit build and honkit serve print a warning for each place, with the file, the line and the change:

warn: README.md:12 "###Example" will not be a heading in HonKit 8. Add a space after "#": "### Example"
warn: SUMMARY.md:8 "[Guide](my guide.md)" will not be a link in HonKit 8. Put the address in <...>: "[Guide](<my guide.md>)"
warn: 2 places need a change before HonKit 8. Run "honkit migrate" to change them.

Change them with the command:

$ npx honkit migrate

honkit migrate rewrites the Markdown files of the book: SUMMARY.md, GLOSSARY.md, LANGS.md and the pages of the summary. It changes only these places, and lists each change. Commit your work before you run it, so that you can review the changes with git diff.

A file that a page includes with {% include %} is not a page of the summary. HonKit 7 does not check it: honkit migrate of HonKit 8 does.

When the build has no warning, update to HonKit 8.

After the update, with HonKit 8

  1. Update honkit to version 8. It needs a newer Node.js than HonKit 7: see Setup.

  2. Run npx honkit migrate, also when you ran it with HonKit 7. It changes the same places, and two more: an emphasis with a space inside of the marks, and the Markdown files that a page includes.

  3. Build the book and look at the warnings. HonKit 8 warns about one case: a link that is not read as a link, because its address has a space.

    warn: SUMMARY.md:8 "[Guide](my guide.md)" is not a link in CommonMark. Put the address in <...>: "[Guide](<my guide.md>)"
    warn: 1 link is not read as a link. Run "honkit migrate" to change it.
    
  4. Look at the pages that use the ways of writing in Other differences.

Keep the parser of HonKit 7

A book that can not be changed now can keep the old parser. HonKit 8 does not include it, so install the package in the book and choose it in book.json:

$ npm install --save-dev @honkit/markdown-legacy
{
    "markdown": {
        "parser": "legacy"
    }
}

The old parser gets no new features and no fixes. Use it as a step of the migration.

What changes

A heading needs a space after #

#Title        <!-- HonKit 7: heading, HonKit 8: paragraph -->
# Title       <!-- heading in both -->

CommonMark reads #Title as text, so that #hashtag and #123 at the start of a line are not headings. The closing # of a heading needs a space too: ## Title ##.

[Guide](my guide.md)      <!-- HonKit 7: link, HonKit 8: text -->
[Guide](<my guide.md>)    <!-- link in both -->
[Guide](my%20guide.md)    <!-- link in both -->

The same rule applies to images and to SUMMARY.md. In SUMMARY.md, an entry that is not a link has no page.

A backtick in a <code> tag starts inline code

A <code>`</code> starts a template literal, and `\n` is a line break.

HonKit 7 reads the <code> tag first, so the backtick in it is text. CommonMark reads the backtick in the tag and the next backtick of the paragraph as inline code. </code> is then a part of that code, and the <code> tag is not closed: the rest of the page can become code.

Write it as inline code: two backticks and a space on each side. HonKit 7 warns only when the paragraph has another backtick.

A `` ` `` starts a template literal, and `\n` is a line break.

HonKit 7 keeps the space after the backtick in the code, so the code is one space wider there. HonKit 8 removes it. When the book has to look the same in HonKit 7, write <code>&#96;</code>: both versions show a backtick without a space.

[guide]: https://example.com/old    <!-- HonKit 8 uses this one -->
[guide]: guide.md                   <!-- HonKit 7 uses this one -->

HonKit 7 uses the last definition of a name, CommonMark uses the first. honkit migrate removes the definitions before the last one, so that the links keep their address. Names are compared without case: [Guide] and [guide] are the same name.

An emphasis has no space inside of the marks

** Note **, **Note ** and *note *    <!-- HonKit 7: emphasis, HonKit 8: text with the marks -->
**Note** and *note*                  <!-- emphasis in both -->

CommonMark reads ** or * as the start of an emphasis only when text follows it, and as the end only when text is before it. So 2 * 3 * 4 is not an emphasis, which HonKit 7 read as one. Translated text often has such spaces.

honkit migrate of HonKit 8 moves the space out of the marks: a **bold **word becomes a **bold** word. The same goes for __ and _. It keeps what HonKit 7 showed, so 2 * 3 * 4 becomes 2 *3* 4. When the marks are signs and not an emphasis, undo that change. The build does not warn about it, because the marks with spaces are valid text in CommonMark.

The id of a heading is made as GitHub makes it

Since HonKit 8.0.1, a heading gets the same id as on GitHub. This was planned for HonKit 8.0.0.

Heading HonKit 8.0.0 and before HonKit 8.0.1 and later
## The post_new view the-postnew-view the-post_new-view
## Party ๐ŸŽ‰ time party-๐ŸŽ‰-time party--time
## CSS โ€“ make it pretty css-โ€“-make-it-pretty css--make-it-pretty
the second ## Example of a page example example-1
  • _ stays in the id.
  • Characters that are not letters, numbers, - or _ are removed, also an emoji and punctuation outside of ASCII.
  • When a page has several headings with the same text, the second one gets -1 at the end, the third one -2. Before, they had the same id, and a link went to the first one.

Most ids stay the same: the id of a heading with letters, numbers and spaces does not change.

honkit migrate changes the links of the book that have an old id: [text](page.md#the-postnew-view) becomes [text](page.md#the-post_new-view). It reads links in Markdown, link definitions and href of HTML links.

The command can not change a link from outside of the book, such as a link from another site or a bookmark. To keep the old id of a heading for these links, write the id in the heading:

## The post_new view {#the-postnew-view}

A heading with an id in the source keeps that id in every version.

Other differences

The other differences are smaller. For example, task lists (- [ ]) become checkboxes, a bare e-mail address becomes a link, and _ inside a word (snake_case_name) is not an emphasis any more. The line that closes a fenced code block has only the fence: text followed by ``` on the same line does not close the block. The README of @honkit/markdown lists them.

results matching ""

    No results matching ""