Fix mkdocs rendering symbols in notebook code #2033
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of PR
Is your Pull Request linked to an existing Issue or Pull Request?
Closes #1767.
Was also ultimately the root cause of #2018.
The issue is that the
mknotebooks
plugin converts.ipynb
files into.html
files, vianbconvert
. As such, in code-blocks when we have a'<'
literal (such as in custom SQL for comparisons, or blocking rules) it is converted to'<'
so that it can be correctly displayed as part of the html.But at some later stage this html is processed by
mkdocs
itself, and it escapes everything in a code-block (so that for instance blocks of html code would display correctly), so this then gets converted to'&lt;'
- i.e. the ampersand gets rendered as-is.[NB: I'm not certain on all of the details here, but this seems to at least approximately be what is occurring]
Ultimately this means we end up with code that appears as e.g.
which is incorrect, and as the code will copy as such, will lead to confusing errors for anyone who tries to run it.
Give a brief description for the solution you have provided
In the end the most straightforward solution was to override the mkdocs
config
option whichmknotebooks
uses to convert notebook files with a class that converts to markdown, rather than html (with the md -> html conversion handled by mkdocs as usual).This runs as a hook after any other
on_config
hooks/plugins run, so we make sure to override themknotebooks
version.This may not be a fully general solution for any configuration of
mknotebooks
, but as we are using only a simple set of its features there should not be a problem.See the built version on my fork.
Additionally in the course of researching this I discovered that
mkdocs-simple-hooks
(which I introduced in #1913) is deprecated, as the functionality is included in coremkdocs
since 1.4, so I ditched this dependency and used the nativehooks
feature.PR Checklist