Code cleanup

This commit is contained in:
Jori Lallo 2016-06-05 23:24:26 -07:00
parent 33b823b66e
commit e3371ed06a
5 changed files with 2 additions and 108 deletions

View File

@ -91,11 +91,7 @@
"react-dom": "^0.14.7",
"react-dropzone": "^3.3.2",
"react-helmet": "^3.1.0",
"react-keyframes": "^0.1.4",
"react-medium-editor": "^1.6.2",
"react-redux": "^4.4.0",
"react-router": "^2.0.0",
"react-router-redux": "^4.0.4",
"rebass": "^0.2.6",
"safestart": "^0.8.0",
"sass-loader": "^3.2.0",
@ -104,7 +100,6 @@
"sequelize-encrypted": "^0.1.0",
"slug": "^0.9.1",
"style-loader": "^0.13.0",
"to-markdown": "^2.0.1",
"truncate-html": "0.0.6",
"url-loader": "^0.5.7",
"uuid": "^2.0.2",

View File

@ -12,7 +12,7 @@ import ClickablePadding from './components/ClickablePadding';
import styles from './MarkdownEditor.scss';
import './codemirror.scss';
import { client } from '../../utils/ApiClient';
import { client } from 'utils/ApiClient';
@observer
class MarkdownEditor extends React.Component {
@ -124,9 +124,6 @@ class MarkdownEditor extends React.Component {
placeholder: "# Start with a title...",
};
// http://codepen.io/lubelski/pen/fnGae
// TODO:
// - Emojify
return (
<Dropzone
onDropAccepted={this.onDropAccepted}

View File

@ -2,7 +2,7 @@ import React from 'react';
import store from 'stores/UserStore';
import { browserHistory } from 'react-router'
import SlackAuthLink from '../../components/SlackAuthLink';
import SlackAuthLink from 'components/SlackAuthLink';
import styles from './Home.scss';

View File

@ -1,40 +0,0 @@
import toMd from 'to-markdown';
const liConverter = {
filter: 'li',
replacement: (content, node) => {
// Change `replace(/\n/gm, '\n ')` to work with our case here :/
content = content.replace(/^\s+/, '').replace(/\n/gm, '\n ');
var prefix = '- ';
var parent = node.parentNode;
var index = Array.prototype.indexOf.call(parent.children, node) + 1;
prefix = /ol/i.test(parent.nodeName) ? index + '. ' : '- ';
return prefix + content;
}
};
const ulConverter = {
filter: ['ul', 'ol'],
replacement: function (content, node) {
var strings = [];
for (var i = 0; i < node.childNodes.length; i++) {
strings.push(node.childNodes[i]._replacement);
}
if (/li/i.test(node.parentNode.nodeName)) {
return '\n' + strings.join('\n');
}
return '\n\n' + strings.join('\n') + '\n\n';
}
};
export function toMarkdown(html) {
const markdown = toMd(
html, {
gfm: true,
converters: [ liConverter, ulConverter ],
},
);
return markdown;
}

View File

@ -1,58 +0,0 @@
import slug from 'slug';
import truncate from 'truncate-html';
import marked, { Renderer } from 'marked';
import highlight from 'highlight.js';
slug.defaults.mode ='rfc3986';
const renderer = new Renderer();
renderer.code = (code, language) => {
const validLang = !!(language && highlight.getLanguage(language));
const highlighted = validLang ? highlight.highlight(language, code).value : code;
return `<pre><code class="hljs ${language}">${highlighted}</code></pre>`;
};
renderer.heading = (text, level) => {
const headingSlug = slug(text);
return `
<h${level}>
<a name="${headingSlug}" class="anchor" href="#${headingSlug}">
<span class="header-link">&nbsp;</span>
</a>
${text}
</h${level}>
`;
},
marked.setOptions({
renderer: renderer,
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: true,
});
// TODO: This is syncronous and can be costly,
// should be performed outside http request
const convertToMarkdown = (text) => {
return marked(text);
};
truncate.defaultOptions = {
stripTags: false,
ellipsis: '...',
decodeEntities: false,
excludes: ['h1', 'pre', ],
};
const truncateMarkdown = (text, length) => {
const html = convertToMarkdown(text);
return truncate(html, length);
};
export {
convertToMarkdown,
truncateMarkdown,
};