-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixing jupytext markdown inconsistencies #288
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,10 @@ | |
from nbconvert.exporters import HTMLExporter | ||
from nbconvert.writers import FilesWriter | ||
import jupytext as jpt | ||
import nbformat as nbf | ||
from ruamel.yaml import YAML | ||
|
||
from .utils import _clean_markdown_cells | ||
from .utils import _clean_markdown_cells, _split_yaml | ||
from .run import run_ntbk | ||
|
||
|
||
|
@@ -35,8 +37,26 @@ def build_page(path_ntbk, path_html_output, path_media_output=None, execute=Fals | |
|
||
######################################## | ||
# Load in the notebook | ||
notebook_name = op.splitext(op.basename(path_ntbk))[0] | ||
ntbk = jpt.read(path_ntbk) | ||
notebook_name, suff = op.splitext(op.basename(path_ntbk)) | ||
|
||
if suff in ['.md', '.markdown']: | ||
# If it's a markdown file, we need to check whether it's a jupytext format | ||
with open(path_ntbk, 'r') as ff: | ||
lines = ff.readlines() | ||
yaml, content = _split_yaml(lines) | ||
yaml = YAML().load(''.join(yaml)) | ||
|
||
if (yaml is not None) and yaml.get('jupyter', {}).get('jupytext'): | ||
# If we have jupytext metadata, then use it to read the markdown file | ||
ntbk = jpt.reads(''.join(lines), 'md') | ||
else: | ||
# Otherwise, create an empty notebook and add all of the file contents as a markdown file | ||
ntbk = nbf.v4.new_notebook() | ||
ntbk['cells'].append(nbf.v4.new_markdown_cell(source=''.join(content))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Chris, yes sure, at least this way we're going to fix the rendering of the Jupyter Book book itself. I think this is good enough for a quick fix, and as you suggest we will follow-up on this. |
||
else: | ||
# If it's not markdown, we assume it's either ipynb or a jupytext format | ||
ntbk = jpt.read(path_ntbk) | ||
|
||
if _is_jupytext_file(ntbk): | ||
execute = True | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe changing this file is not necessary.
And the changes I see below (with Markdown comments surrounding the python code cells) raise an interesting question: should Python code blocks in the Markdown file always appear as executable code cells? As you noticed, these Markdown comments allow to preserve Jupyter's Markdown cells whatever there content is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, I needed to change the file so that I could use the right sidebar popout, which Jupyter Book can only use with notebooks instead of markdown files, this is why I added the jupytext header. I'll put my thoughts about choosing markdown syntax in the issue so that we don't lose the conversation when this is merged!