Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- returnIframe = (matchedString, embedArray) => {
- let iframe
- let url = matchedString.match(/@\[youtube\]\(([^\)]+)\)/i)[1]
- for (let i = 0; i < embedArray.length; i++) {
- if (embedArray[i] == url) {
- iframe = `<iframe style="width: 100%; height: 560px" src="${url}" />`
- break
- }
- }
- return iframe
- }
- setArticle = () => {
- const { articles } = this.model
- const converter = new showdown.Converter()
- for (let i = 0; i < articles.length; i++) {
- if (articles[i].slug === this.props.match.params.slug) {
- let embeds = articles[i].body.match(/@\[youtube\]\(([^\)]+)\)/g)
- embeds = embeds.map(link => link.match(/@\[youtube\]\(([^\)]+)\)/im)[1])
- let newBod = articles[
- i
- ].body.replace(/@\[youtube\]\(([^\)]+)\)/, matchedString => {
- return this.returnIframe(matchedString, embeds)
- })
- let htmlBody = converter.makeHtml(newBod)
- this.setState({ article: articles[i], htmlBody })
- break
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment