Last active
December 29, 2017 01:48
-
-
Save astrotim/564a9650ff995122efb63d909efcb065 to your computer and use it in GitHub Desktop.
added Markdown support to Post.js
This file contains hidden or 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
-import React from 'react'; | |
+import React, { createElement } from 'react'; | |
import { createClient } from 'contentful'; | |
import Helmet from 'react-helmet'; | |
+import marksy from 'marksy'; | |
+ | |
+// Markdown helper function | |
+const getMarkup = field => { | |
+ if (!field) return null; | |
+ const compile = marksy({ | |
+ createElement, | |
+ elements: {} | |
+ }); | |
+ return compile(field).tree; | |
+}; | |
render() { | |
if (!this.state.data) return null; | |
+ const content = getMarkup(this.state.data.content); | |
+ | |
return ( | |
<div> | |
<Helmet title={this.state.data.title} /> | |
<h1>{this.state.data.title}</h1> | |
- {this.state.data.content} | |
+ {content} | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment