-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
Fixes swagger-editor/#1502. #3712
Merged
shockey
merged 3 commits into
swagger-api:master
from
owenconti:bug/swagger-editor-1502
Sep 29, 2017
Merged
Changes from all commits
Commits
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 |
---|---|---|
@@ -1,37 +1,40 @@ | ||
import React from "react" | ||
import PropTypes from "prop-types" | ||
import Remarkable from "react-remarkable" | ||
import Remarkable from "remarkable" | ||
import sanitize from "sanitize-html" | ||
|
||
function Markdown({ source }) { | ||
const sanitized = sanitizer(source) | ||
const html = new Remarkable({ | ||
html: true, | ||
typographer: true, | ||
breaks: true, | ||
linkify: true, | ||
linkTarget: "_blank" | ||
}).render(source) | ||
const sanitized = sanitizer(html) | ||
|
||
// sometimes the sanitizer returns "undefined" as a string | ||
if(!source || !sanitized || sanitized === "undefined") { | ||
return null | ||
} | ||
if ( !source || !html || !sanitized ) { | ||
return null | ||
} | ||
|
||
return <div className="markdown"> | ||
<Remarkable | ||
options={{html: true, typographer: true, breaks: true, linkify: true, linkTarget: "_blank"}} | ||
source={sanitized} | ||
></Remarkable> | ||
</div> | ||
return ( | ||
<div className="markdown" dangerouslySetInnerHTML={{ __html: sanitized }}></div> | ||
) | ||
} | ||
|
||
Markdown.propTypes = { | ||
source: PropTypes.string.isRequired | ||
source: PropTypes.string.isRequired | ||
} | ||
|
||
export default Markdown | ||
|
||
const sanitizeOptions = { | ||
textFilter: function(text) { | ||
return text | ||
.replace(/"/g, "\"") | ||
} | ||
allowedTags: sanitize.defaults.allowedTags.concat([ "img" ]), | ||
textFilter: function(text) { | ||
return text.replace(/"/g, "\"") | ||
} | ||
} | ||
|
||
export function sanitizer(str) { | ||
return sanitize(str, sanitizeOptions) | ||
return sanitize(str, sanitizeOptions) | ||
} |
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 |
---|---|---|
@@ -1,11 +1,26 @@ | ||
import React from "react" | ||
import ReactMarkdown from "react-markdown" | ||
import { Parser, HtmlRenderer } from "commonmark" | ||
import { OAS3ComponentWrapFactory } from "../helpers" | ||
import { sanitizer } from "core/components/providers/markdown" | ||
|
||
export default OAS3ComponentWrapFactory(({ source }) => { return source ? ( | ||
<ReactMarkdown | ||
source={sanitizer(source)} | ||
className={"renderedMarkdown"} | ||
/> | ||
) : null}) | ||
export default OAS3ComponentWrapFactory(({ source }) => { | ||
if ( source ) { | ||
const parser = new Parser() | ||
const writer = new HtmlRenderer() | ||
const html = writer.render(parser.parse(source || "")) | ||
const sanitized = sanitizer(html) | ||
|
||
if ( !source || !html || !sanitized ) { | ||
return null | ||
} | ||
|
||
return ( | ||
<ReactMarkdown | ||
source={sanitized} | ||
className={"renderedMarkdown"} | ||
/> | ||
) | ||
} | ||
return null | ||
}) |
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.
Since we're using Remarkable directly, do we need
react-remarkable
anymore?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.
Nope, I think we can remove it. I also want to try removing
ReactMarkdown
from the OAS3 component and replace it withdangerouslySetInnerHTML
like in the 2.0 component.