diff --git a/package.json b/package.json index 73711519..80d5086d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/MarkdownEditor/MarkdownEditor.js b/src/components/MarkdownEditor/MarkdownEditor.js index 251fbea7..f18f5ec9 100644 --- a/src/components/MarkdownEditor/MarkdownEditor.js +++ b/src/components/MarkdownEditor/MarkdownEditor.js @@ -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 ( { - // 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; -} diff --git a/src/utils/markdown2.js b/src/utils/markdown2.js deleted file mode 100644 index c5355456..00000000 --- a/src/utils/markdown2.js +++ /dev/null @@ -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 `
${highlighted}
`; -}; -renderer.heading = (text, level) => { - const headingSlug = slug(text); - return ` - - -   - - ${text} - - `; -}, - -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, -};