-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
react-markdown doesn't support transformer plugins (remarkjs/react-markdown#188), so we can't use remark-ping with it. My hand-coded @tag plugin was buggy--better to use remark-ping
- Loading branch information
Showing
9 changed files
with
408 additions
and
134 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,38 @@ | ||
import React from "react"; | ||
import t from "prop-types"; | ||
import remark from "remark"; | ||
import remarkPing from "remark-ping"; | ||
import remarkRehype from "remark-rehype"; | ||
import rehypeStringify from "rehype-stringify"; | ||
import rehypeHighlight from "rehype-highlight"; | ||
|
||
export default class Markdown extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
rendered: "" | ||
}; | ||
} | ||
componentDidMount() { | ||
const remarkInst = remark() | ||
// Use remark-ping to transform tags (e.g. @javascript) into links | ||
.use(remarkPing, { | ||
pingUsername: tag => true, | ||
userURL: this.props.tagURL | ||
}) | ||
.use(remarkRehype) | ||
.use(rehypeStringify) | ||
.use(rehypeHighlight); | ||
const result = remarkInst.process(this.props.source, (err, rendered) => { | ||
if (err) throw err; | ||
this.setState({ rendered }); | ||
}); | ||
} | ||
render() { | ||
return <div dangerouslySetInnerHTML={{ __html: this.state.rendered }} />; | ||
} | ||
} | ||
Markdown.propTypes = { | ||
source: t.string.isRequired, | ||
tagURL: t.func | ||
}; |
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,10 @@ | ||
// https://stackoverflow.com/a/901144/1157536 | ||
export default function getQueryParam(name, url) { | ||
if (!url) url = window.location.href; | ||
name = name.replace(/[\[\]]/g, "\\$&"); | ||
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), | ||
results = regex.exec(url); | ||
if (!results) return null; | ||
if (!results[2]) return ""; | ||
return decodeURIComponent(results[2].replace(/\+/g, " ")); | ||
} |
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