Skip to content

Instantly share code, notes, and snippets.

@astrotim astrotim/Post.js.diff
Last active Dec 29, 2017

Embed
What would you like to do?
added Markdown support to Post.js
-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
You can’t perform that action at this time.