Markdown Review UI
Review Request #3434 — Created Oct. 21, 2012 and discarded
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 … |
chipx86 | |
Place these before the screenshot ones. |
chipx86 | |
Same. |
chipx86 | |
The new branch I mentioned has a FileAttachmentReviewable, which you'll want to look at. It should provide everything this currently … |
chipx86 | |
Remove the trailing comma. |
chipx86 | |
No need for this. |
chipx86 | |
Make sure not to have trailing commas, or things will break in some browsers. |
chipx86 | |
Trailing commas bad. |
chipx86 | |
Sync master and you'll be able to take advantage of registration. Look at reviewboard/reviews/ui/__init__.py. |
chipx86 | |
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. |
chipx86 | |
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 … |
chipx86 | |
Unless you have additional work to do here, don't bother overriding it. |
chipx86 | |
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. |
chipx86 | |
No need to return anything. |
chipx86 | |
You want {{markdown.caption|escapejs}} |
chipx86 | |
Same. |
chipx86 | |
This should append view.$el. |
chipx86 | |
Should be included alphabetically, and have a trailing comma. |
chipx86 | |
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 … |
mike_conley | |
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 … |
mike_conley | |
We tend to keep the trailing commas in Python. |
mike_conley | |
Again, I have to ask - why are these being added? I don't see these files being added in this … |
mike_conley | |
Should inherit from FileAttachmentReviewable, and then you won't need 'caption' or 'attachmentID'. |
chipx86 | |
Nit: alphabetical |
mike_conley | |
Nit: remove this newline. |
mike_conley | |
I think this is indented too much. |
mike_conley | |
StringIO is part of the standard library, so your imports should read like this: import StringIO import markdown from reviewboard.reviews.ui.base … |
david | |
Should be: try: from cStringIO import StringIO except ImportError: from StringIO import StringIO That'll use cStringIO when available, which is … |
chipx86 |
-
-
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).
-
-
-
The new branch I mentioned has a FileAttachmentReviewable, which you'll want to look at. It should provide everything this currently does.
-
-
-
-
- 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:
-
markdown-uimaster
- 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:
-
WIP - Starter code for Markdown Pluggable UIRender Markdown attachments as HTML
- Description:
-
- Basic backend model and template set up for Markdown pluggable UI.
- Hard code FileAttachmentReviewUI:get_best_handler to work only with the Markdown pluggable UI until mimetype registration is implemented.
- Create the files (i.e. the Backbone model and view) needed for the frontend component of the Markdown pluggable UI.
- Update JS pipeline in settings.py to include the Javascript files for the new files created.
~ - Introduce member variables 'caption' and 'attachmentID' in the Backbone.js model for Markdown. These two values will be needed to render the UI.
~ - Introduce member variables 'caption', 'attachmentID' and 'rendered' in the Backbone.js model for Markdown. These values will be needed to render the UI.
+ - Use the 'markdown' package to render the file attachment to HTML. This HTML is referenced is then referenced in markdown.html and displayed on the page.
Future changes to the frontend and backend of the Markdown pluggable UI will most likely be built on top of these files.
- Change Summary:
-
Added screenshot of how the rendered Markdown file looks like as of now
- Screenshots:
-
Initial version of Markdown rendering
-
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.
-
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?
-
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
-
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.
-
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?
-
-
Sync master and you'll be able to take advantage of registration. Look at reviewboard/reviews/ui/__init__.py.
-
This is a bit expensive. You should use the file attachment provided. You'll need to subclass FileAttachmentReviewUI for that.
-
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.
-
-
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.
-
-
-
-
-
- Change Summary:
-
Addressed issues/comments from code review
- Description:
-
~ - Basic backend model and template set up for Markdown pluggable UI.
~ Currently completed for Markdown Pluggable UI:
- - Hard code FileAttachmentReviewUI:get_best_handler to work only with the Markdown pluggable UI until mimetype registration is implemented.
- - Create the files (i.e. the Backbone model and view) needed for the frontend component of the Markdown pluggable UI.
- - Update JS pipeline in settings.py to include the Javascript files for the new files created.
- - Introduce member variables 'caption', 'attachmentID' and 'rendered' in the Backbone.js model for Markdown. These values will be needed to render the UI.
- - Use the 'markdown' package to render the file attachment to HTML. This HTML is referenced is then referenced in markdown.html and displayed on the page.
~ Future changes to the frontend and backend of the Markdown pluggable UI will most likely be built on top of these files.
~ - Created Backbone model and view for Markdown
+ - Wrote code to register the Markdown Pluggable UI
+ - Updated JS pipeline and required packages in settings.py to include the Backbone JS files as well as the Python "markdown" package
+ - Use the 'markdown' package to render the file attachment to HTML.
+ - Set up a basic template to display rendered Markdown HTML
- Diff:
-
Revision 5 (+80 -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:
-
WIP - Markdown Pluggable UIMarkdown Pluggable UI
- Description:
-
~ Currently completed for Markdown Pluggable UI:
~ Adds functionality to render Markdown file attachments in Review Board.
~ - Created Backbone model and view for Markdown
~ - Wrote code to register the Markdown Pluggable UI
~ - Updated JS pipeline and required packages in settings.py to include the Backbone JS files as well as the Python "markdown" package
~ - Use the 'markdown' package to render the file attachment to HTML.
~ - Set up a basic template to display rendered Markdown HTML
~ 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: The screenshot attached is how the UI looks at the moment (disregard the "Initial version" part in the Caption)
~ ~ Follow-up features: Load the pluggable UI in a lightbox rather than on a new page.
- Testing Done:
-
+ "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)
-
-
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.
-
-
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.
-
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?
-
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)
- Change Summary:
-
Rebased on commenting functionality (http://reviews.reviewboard.org/r/3613/).
- Description:
-
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: The screenshot attached is how the UI looks at the moment (disregard the "Initial version" part in the Caption)
~ Note: This code depends on this review request: http://reviews.reviewboard.org/r/3613/
- - Follow-up features: Load the pluggable UI in a lightbox rather than on a new page.
- Diff:
-
Revision 9 (+88 -1)
- Added Files:
- Screenshots:
-
Initial version of Markdown rendering
- Change Summary:
-
Removed accidental extra blank line.
- Diff:
-
Revision 10 (+87 -1)
- Change Summary:
-
- Fixed order of imports - cStringIO is imported when available - Did --parent= when posting patch
- Diff:
-
Revision 12 (+91 -1)