Markdown Review UI
Review Request #3434 — Created Oct. 21, 2012 and discarded
Information | |
---|---|
aam1r | |
Review Board | |
master | |
Reviewers | |
reviewboard | |
Adds functionality to render Markdown file attachments in Review Board. The rendering is handled by the "markdown" Python package which, given a file, returns the HTML code for it. This HTML code is then passed to the Backbone view for the Markdown Pluggable UI through the template and rendered in the browser. Note: This code depends on this review request: http://reviews.reviewboard.org/r/3613/
"Valid" Case: 1) Created a review request and uploaded multiple random files to it 2) Then, uploaded a valid Markdown file (with the extension .md) to that review request 3) Clicked the "Review" link for the Markdown file 4) The new page loaded should render the Markdown file "Invalid" Case: 1) Created a review request and uploaded multiple random files to it 2) Then, uploaded an image to that review request by changed the file extension to be ".md". For example, wallpaper.png -> wallpaper.md 3) Clicked the "Review" link for the invalid Markdown file 4) The new page loaded did not render anything (i.e. it displayed the title and caption but nothing was displayed in the section where the HTML would have rendered)
Description | From | Last Updated |
---|---|---|
My latest change (up for review) for image review UI has registration support. You should be able to look into … |
|
|
Place these before the screenshot ones. |
|
|
Same. |
|
|
The new branch I mentioned has a FileAttachmentReviewable, which you'll want to look at. It should provide everything this currently … |
|
|
Remove the trailing comma. |
|
|
No need for this. |
|
|
Make sure not to have trailing commas, or things will break in some browsers. |
|
|
Trailing commas bad. |
|
|
Sync master and you'll be able to take advantage of registration. Look at reviewboard/reviews/ui/__init__.py. |
|
|
I might be very wrong here, but I think you need to be inheriting from FileAttachmentReviewUI, otherwise your MarkdownReviewUI won't … |
KA Karl-L | |
This is a bit expensive. You should use the file attachment provided. You'll need to subclass FileAttachmentReviewUI for that. |
|
|
I might (again) be very wrong here, but your MarkdownReviewUI instance should have been given the FileAttachment object to render … |
KA Karl-L | |
I don't think you need to do this. It's more expensive to process this than to just let the browser … |
|
|
Unless you have additional work to do here, don't bother overriding it. |
|
|
You shouldn't define a new type of render function. What you really should be doing is: this.$el.html(this.model.get('rendered')); in renderContent. |
|
|
No need to return anything. |
|
|
You want {{markdown.caption|escapejs}} |
|
|
Same. |
|
|
This should append view.$el. |
|
|
Should be included alphabetically, and have a trailing comma. |
|
|
I wonder if it'd make more sense to just call it reviewboard.reviews.ui.markdown, as opposed to reviewboard.reviews.ui.markdownui. The ui in markdownui … |
|
|
It would be nice to simply prioritize the mimetype when looking for a best handler. So, instead of checking the … |
KA Karl-L | |
This would be more visible at the top of the file. |
KA Karl-L | |
Maybe I'm missing something here, but why are you changing these? Seems only tangentially related to the rest of the … |
|
|
We tend to keep the trailing commas in Python. |
|
|
Again, I have to ask - why are these being added? I don't see these files being added in this … |
|
|
Should inherit from FileAttachmentReviewable, and then you won't need 'caption' or 'attachmentID'. |
|
|
Nit: alphabetical |
|
|
Nit: remove this newline. |
|
|
I think this is indented too much. |
|
|
StringIO is part of the standard library, so your imports should read like this: import StringIO import markdown from reviewboard.reviews.ui.base … |
|
|
Should be: try: from cStringIO import StringIO except ImportError: from StringIO import StringIO That'll use cStringIO when available, which is … |
|
-
-
reviewboard/reviews/ui/base.py (Diff revision 1) My latest change (up for review) for image review UI has registration support. You should be able to look into that and use it. I recommend applying it to a branch for now, then rebasing your code on top of it, until we get it in (soon).
-
-
-
reviewboard/static/rb/js/models/markdownReviewableModel.js (Diff revision 1) The new branch I mentioned has a FileAttachmentReviewable, which you'll want to look at. It should provide everything this currently does.
-
reviewboard/static/rb/js/models/markdownReviewableModel.js (Diff revision 1) Remove the trailing comma.
-
-
reviewboard/static/rb/js/views/markdownReviewableView.js (Diff revision 1) Make sure not to have trailing commas, or things will break in some browsers.
-
Change Summary:
Addressed some issues from code review - Reordered Markdown model/view inclusion to be before Screenshot view/model - Removed unnecessary trailing commas and unused variables
Branch: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 2 (+71) |
Change Summary:
Create and associate Markdown model with Pluggable UI - Create a model for Markdown that will hold the appropriate data for Markdown files. It will also provide functionality to render Markdown as HTML - Associate the MarkdownReviewUI to the Markdown model - Make the 'markdown' package an installation requirement for Review Board
Diff: |
Revision 3 (+80) |
---|
Change Summary:
Added code to render Markdown to HTML
Summary: |
|
|||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description: |
|
|||||||||||||||||||||||||||
Diff: |
Revision 4 (+94) |
-
-
reviewboard/reviews/ui/markdownui.py (Diff revision 4) Instead of replacing new line characters over here, I can also do {{ review_ui.render|linebreaksbr }} (https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#linebreaksbr) Is one method better than/preferred over another?
-
-
reviewboard/reviews/ui/markdownui.py (Diff revision 4) Is there a more elegant / more-Pythonic way to get the FileAttachment object of the Markdown file? I don't think this will work if there is a review request with multiple attachments or when the first attachment is not a markdown file
-
Pretty cool to see markdown being rendered in RB! I couldn't find where to leave comments on the screenshot, but maybe adding a light border and some extra margin (well...padding) around the rendering would help make it clear that we're looking at the file and not some other content, sort of like a page-within-a-page type deal? Just a thought.
-
reviewboard/reviews/ui/base.py (Diff revision 4) I know this is temporary, but just curious what your plans are for handling markdown files. I don't think (?) the mimetype is to be trusted (it might just be text/plain), so will you be augmenting this method to look at file extensions as well?
-
reviewboard/reviews/ui/markdownui.py (Diff revision 4) I might be very wrong here, but I think you need to be inheriting from FileAttachmentReviewUI, otherwise your MarkdownReviewUI won't get picked as the best handler. You'll still need to fix FileAttachmentReviewUI.get_best_handler to support markdown, of course. See the FileAttachment.review_ui property in attachments/models.py
-
reviewboard/reviews/ui/markdownui.py (Diff revision 4) I might (again) be very wrong here, but your MarkdownReviewUI instance should have been given the FileAttachment object to render when it got instantiated (as `self.obj`). So, instead of getting the file attachments for the review request and picking one from the list, the file to be rendered should already be available as `self.obj.file`. See FileAttachmentReviewUI in ui/base.py.
-
reviewboard/reviews/ui/markdownui.py (Diff revision 4) I think the template filter is the better option -- might as well keep that part of the presentation separate. . It cleans up the python code a little and leaves the door open to getting the regular markdown output if we want. Out of curiosity, why remove the newlines? Does it affect the rendered HTML?
-
-
reviewboard/reviews/ui/base.py (Diff revision 4) Sync master and you'll be able to take advantage of registration. Look at reviewboard/reviews/ui/__init__.py.
-
reviewboard/reviews/ui/markdownui.py (Diff revision 4) This is a bit expensive. You should use the file attachment provided. You'll need to subclass FileAttachmentReviewUI for that.
-
reviewboard/reviews/ui/markdownui.py (Diff revision 4) I don't think you need to do this. It's more expensive to process this than to just let the browser handle it. Also, if we were going to, a regex would be faster. One loop through and not 3.
-
reviewboard/static/rb/js/views/markdownReviewableView.js (Diff revision 4) Unless you have additional work to do here, don't bother overriding it.
-
reviewboard/static/rb/js/views/markdownReviewableView.js (Diff revision 4) You shouldn't define a new type of render function. What you really should be doing is: this.$el.html(this.model.get('rendered')); in renderContent.
-
reviewboard/static/rb/js/views/markdownReviewableView.js (Diff revision 4) No need to return anything.
-
reviewboard/templates/reviews/ui/markdown.html (Diff revision 4) You want {{markdown.caption|escapejs}}
-
-
-
Change Summary:
Addressed issues/comments from code review
Description: |
|
||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 5 (+80 -5) |
-
-
reviewboard/reviews/ui/markdownui.py (Diff revision 5) There is no standardized mimetype for Markdown yet. I tested with a few Markdown files and were plain text, some were "text/x-markdown" and some were "application/octet-stream". I think we should do as follows: - support_mimetypes should be ['text/x-markdown', 'text/x-web-markdown'] (until something is standardized) - Additionally, there should be a property to match against the file extension. For example: extension_pattern = "*.md" Instead of relying on mimetypes, we can use the file extension to match an attachment to a pluggable UI.
Change Summary:
Pluggable UI handler matching now supports file extensions Rather than just relying on mimetypes to match an attachment to a Pluggable UI, we can now use file extensions to determine the Pluggable UI for an attachment. This allows us to override the mimetype when mimeparse detects the mimetype for an attachment to be "octet-stream". Note: I will be taking this out of WIP tonight once I have updated the 'Description' and 'Testing Done' sections of the review request.
Diff: |
Revision 6 (+93 -5) |
---|
Change Summary:
Updated description, added details about how testing was done and took the review request out of WIP.
Summary: |
|
|||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description: |
|
|||||||||||||||||||||||||||||||||||||||
Testing Done: |
|
-
-
reviewboard/reviews/ui/base.py (Diff revision 6) It would be nice to simply prioritize the mimetype when looking for a best handler. So, instead of checking the file extension here, let get_best_handler run its course. If it couldn't find a handler using the mimetype, then check the file extension. This way, if, say a jpeg is uploaded with the right mimetype, but a file extension in the MIMETYPE_EXTENSIONS, it will still pick the right handler. Also, checking the extension separately should make it a little easier to have many file extensions for the same file. You could add a class property of supported_file_extensions, and fill it with a list of file extensions. I know, for me, I've used '.md', '.mdown' and '.markdown' for Markdown files. Any thoughts?
-
-
Other than the comments I've left, this is looking pretty good to me.
-
-
reviewboard/reviews/ui/__init__.py (Diff revision 6) I wonder if it'd make more sense to just call it reviewboard.reviews.ui.markdown, as opposed to reviewboard.reviews.ui.markdownui. The ui in markdownui is a bit redundant. Just a nit.
-
reviewboard/settings.py (Diff revision 6) Maybe I'm missing something here, but why are you changing these? Seems only tangentially related to the rest of the patch.
-
Change Summary:
Addressed issues brought up here and in r/3526 (which is based off this review request)
Diff: |
Revision 7 (+96 -1) |
---|
-
Hey - so the code looks pretty good, and I tried the patch and was able to render some Markdown, which was awesome. I'm curious though - am I supposed to be able to attach comments to this Markdown? Did I miss something? Where does that come in?
-
reviewboard/settings.py (Diff revision 7) Again, I have to ask - why are these being added? I don't see these files being added in this patch...
Change Summary:
Pulled in latest changes from 'master'. Removed code that was duplicate between master and this review request (such as declaring MARKDOWN_EXTENSIONS).
Diff: |
Revision 8 (+88 -2) |
---|
-
What's needed before this can go in? Anything, or is it standalone at this point?
-
reviewboard/static/rb/js/models/markdownReviewableModel.js (Diff revision 8) Should inherit from FileAttachmentReviewable, and then you won't need 'caption' or 'attachmentID'.
Change Summary:
Rebased on commenting functionality (http://reviews.reviewboard.org/r/3613/).
Description: |
|
||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 9 (+88 -1) |
||||||||||||||||||||||||
Added Files: |
|||||||||||||||||||||||||
Screenshots: |
|
Change Summary:
Removed accidental extra blank line.
-
-
reviewboard/reviews/ui/markdownui.py (Diff revision 11) StringIO is part of the standard library, so your imports should read like this: import StringIO import markdown from reviewboard.reviews.ui.base import FileAttachmentReviewUI
-
It looks like this is including the text change as well. Can you make sure you're using --parent?
-
reviewboard/reviews/ui/markdownui.py (Diff revision 11) Should be: try: from cStringIO import StringIO except ImportError: from StringIO import StringIO That'll use cStringIO when available, which is faster.
Change Summary:
- Fixed order of imports - cStringIO is imported when available - Did --parent= when posting patch
Diff: |
Revision 12 (+91 -1)
|
---|