Skip to content

Instantly share code, notes, and snippets.

@astrotim
Last active December 29, 2017 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrotim/564a9650ff995122efb63d909efcb065 to your computer and use it in GitHub Desktop.
Save astrotim/564a9650ff995122efb63d909efcb065 to your computer and use it in GitHub Desktop.
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