Guest User

Untitled

a guest
Jun 7th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. returnIframe = (matchedString, embedArray) => {
  2. let iframe
  3. let url = matchedString.match(/@\[youtube\]\(([^\)]+)\)/i)[1]
  4. for (let i = 0; i < embedArray.length; i++) {
  5. if (embedArray[i] == url) {
  6. iframe = `<iframe style="width: 100%; height: 560px" src="${url}" />`
  7. break
  8. }
  9. }
  10. return iframe
  11. }
  12.  
  13. setArticle = () => {
  14. const { articles } = this.model
  15. const converter = new showdown.Converter()
  16. for (let i = 0; i < articles.length; i++) {
  17. if (articles[i].slug === this.props.match.params.slug) {
  18. let embeds = articles[i].body.match(/@\[youtube\]\(([^\)]+)\)/g)
  19. embeds = embeds.map(link => link.match(/@\[youtube\]\(([^\)]+)\)/im)[1])
  20. let newBod = articles[
  21. i
  22. ].body.replace(/@\[youtube\]\(([^\)]+)\)/, matchedString => {
  23. return this.returnIframe(matchedString, embeds)
  24. })
  25. let htmlBody = converter.makeHtml(newBod)
  26. this.setState({ article: articles[i], htmlBody })
  27. break
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment