-
Notifications
You must be signed in to change notification settings - Fork 568
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
Allow including text/x-rst
outputs in rst conversion, transition away from text/restructuredtext
#2167
Merged
Merged
Allow including text/x-rst
outputs in rst conversion, transition away from text/restructuredtext
#2167
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
354ed80
Allow including text/restructuredtext outputs in rst conversion
takluyver 5d1e7b1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b79ce43
Satisfy the hobgoblins
takluyver 4daa384
Add docstring
takluyver bb09112
Try to work around pip bug
takluyver 4d1009f
Better test for presence of rst output
takluyver f214342
Correct rst mimetype to text/x-rst
takluyver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "d5202f0f-21b8-4509-a9e2-45caf1c7db7a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from textwrap import indent\n", | ||
"\n", | ||
"\n", | ||
"class Note:\n", | ||
" def __init__(self, text):\n", | ||
" self.text = text\n", | ||
"\n", | ||
" def _repr_html_(self):\n", | ||
" return f'<div style=\"font-weight: bold; font-size: 16pt;\">{self.text}</div>'\n", | ||
"\n", | ||
" def _repr_mimebundle_(self, include=None, exclude=None):\n", | ||
" return {\"text/restructuredtext\": \".. note::\\n\\n\" + indent(self.text, \" \")}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "5145b05f-3a07-4cff-8738-516a9c27cb58", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div style=\"font-weight: bold; font-size: 16pt;\">Testing testing</div>" | ||
], | ||
"text/plain": [ | ||
"<__main__.Note at 0x7fe804028740>" | ||
], | ||
"text/restructuredtext": [ | ||
".. note::\n", | ||
"\n", | ||
" Testing testing" | ||
] | ||
}, | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"Note(\"Testing testing\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
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
Oops, something went wrong.
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.
Should it also support
text/x-rst
andtext/prs.fallenstein.rst
?text/restructuredtext
seems pretty non-standard to me (although I acknowledge that this is what nbconverte is already using for some reason)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.
Huh, good point. 🤔
I think it's best for users to have 1 MIME type for rst, rather than trying to wrangle several. So maybe we should change
RSTExporter.output_mimetype
as well - probably totext/x-rst
, since that's what docutils suggests.What would break if we do that?
text/restructuredtext
would stop showing up - but we could work around that by overridingraw_mimetypes
to add backtext/restructuredtext
for compatibility.output_mimetype
, so custom templates markedtext/restructuredtext
would no longer work. I can't imagine that many people have custom rst templates, and it's an easy change, so I'd be inclined to document that as a breaking change rather than adding extra complexity to keep them working.Does that sound reasonable?
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.
I think it is reasonable. If I were doing the change I would probably try to make it as backward compatible as possible.
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.
Feel free to ping me for review once you think it is ready
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.
I've done what I described, with compatibility for raw cells using the old mimetype but not for custom templates.
I'm generally keen to keep backwards compatibility, but my impression is that it's unusual to use custom templates at all, it's an easy fix for anyone affected, and the logic for finding templates is already complex enough, so I'm reluctant to add yet another dimension to it to allow multiple mimetypes per exporter. If you want to insist, though, let me know and I'll try to add compatibility for that too.
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.
I trust your judgement. If your assessment is accurate, I would say it might be ok to release and see if anyone complains and only then add back the extra compatibility layer.
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.
Thanks!