From 45637a050b0f43d2d4a57684f41c1dd1b3ff123b Mon Sep 17 00:00:00 2001 From: btzr-io Date: Sun, 10 Jun 2018 15:57:46 -0600 Subject: [PATCH] render actual markdown preview component --- package.json | 3 +- .../common/form-components/form-field.jsx | 12 +- .../view.jsx => common/markdown-preview.js} | 11 +- src/renderer/component/fileDetails/view.jsx | 4 +- .../component/markdownPreview/index.js | 8 - yarn.lock | 139 ++---------------- 6 files changed, 33 insertions(+), 144 deletions(-) rename src/renderer/component/{markdownPreview/view.jsx => common/markdown-preview.js} (72%) delete mode 100644 src/renderer/component/markdownPreview/index.js diff --git a/package.json b/package.json index f31f046de..b54e3f956 100644 --- a/package.json +++ b/package.json @@ -57,11 +57,10 @@ "react": "^16.3.0", "react-dom": "^16.3.0", "react-feather": "^1.0.8", - "react-markdown": "^2.5.0", "react-modal": "^3.1.7", "react-paginate": "^5.2.1", "react-redux": "^5.0.3", - "react-simplemde-editor": "3.6.11", + "react-simplemde-editor": "^3.6.15", "react-transition-group": "1.x", "redux": "^3.6.0", "redux-logger": "^3.0.1", diff --git a/src/renderer/component/common/form-components/form-field.jsx b/src/renderer/component/common/form-components/form-field.jsx index 441646447..bbeefe5ad 100644 --- a/src/renderer/component/common/form-components/form-field.jsx +++ b/src/renderer/component/common/form-components/form-field.jsx @@ -1,8 +1,10 @@ // @flow import * as React from 'react'; +import ReactDOMServer from 'react-dom/server'; import classnames from 'classnames'; +import MarkdownPreview from 'component/common/markdown-preview'; import SimpleMDE from 'react-simplemde-editor'; -import style from 'react-simplemde-editor/dist/simplemde.min.css'; // eslint-disable-line no-unused-vars +import "simplemde/dist/simplemde.min.css"; type Props = { name: string, @@ -52,7 +54,13 @@ export class FormField extends React.PureComponent { ; + return ReactDOMServer.renderToString(preview); + } + }} /> ); diff --git a/src/renderer/component/markdownPreview/view.jsx b/src/renderer/component/common/markdown-preview.js similarity index 72% rename from src/renderer/component/markdownPreview/view.jsx rename to src/renderer/component/common/markdown-preview.js index 1f2267c5f..e50210aa2 100644 --- a/src/renderer/component/markdownPreview/view.jsx +++ b/src/renderer/component/common/markdown-preview.js @@ -11,14 +11,19 @@ const schema = { ...defaultSchema }; // Extend sanitation schema to support lbry protocol schema.protocols.href[3] = 'lbry'; -type MarkdownProps = { content: string }; +type MarkdownProps = { + content: string, + promptLinks?: boolean, +}; + +const SimpleLink = ({ href, title, children }) => ({children}); const MarkdownPreview = (props: MarkdownProps) => { - const { content } = props; + const { content, externalLinks, promptLinks } = props; const remarkOptions = { sanitize: schema, remarkReactComponents: { - a: ExternalLink, + a: promptLinks ? ExternalLink : SimpleLink, }, }; return ( diff --git a/src/renderer/component/fileDetails/view.jsx b/src/renderer/component/fileDetails/view.jsx index 28c52ad08..f36cad539 100644 --- a/src/renderer/component/fileDetails/view.jsx +++ b/src/renderer/component/fileDetails/view.jsx @@ -1,6 +1,6 @@ // @flow import * as React from 'react'; -import MarkdownPreview from 'component/markdownPreview'; +import MarkdownPreview from 'component/common/markdown-preview'; import Button from 'component/button'; import path from 'path'; import type { Claim } from 'types/claim'; @@ -41,7 +41,7 @@ const FileDetails = (props: Props) => {
About
- +
)} diff --git a/src/renderer/component/markdownPreview/index.js b/src/renderer/component/markdownPreview/index.js deleted file mode 100644 index b84658fb3..000000000 --- a/src/renderer/component/markdownPreview/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import MarkdownPreview from './view'; - -const select = () => ({}); -const perform = () => ({}); - -export default connect(select, perform)(MarkdownPreview); diff --git a/yarn.lock b/yarn.lock index d6936ae81..e6474aebb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -183,7 +183,7 @@ acorn@^4.0.3: version "4.0.13" resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787" -acorn@^5.0.0, acorn@^5.2.1, acorn@^5.5.0: +acorn@^5.0.0, acorn@^5.5.0: version "5.6.1" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.6.1.tgz#c9e50c3e3717cf897f1b071ceadbb543bbc0a8d4" @@ -1219,10 +1219,6 @@ balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" -base62@^1.1.0: - version "1.2.8" - resolved "https://registry.yarnpkg.com/base62/-/base62-1.2.8.tgz#1264cb0fb848d875792877479dbe8bae6bae3428" - base64-js@0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-0.0.8.tgz#1101e9544f4a76b1bc3b26d452ca96d7a35e7978" @@ -2034,7 +2030,7 @@ comma-separated-tokens@^1.0.0: dependencies: trim "0.0.1" -commander@2.15.x, commander@^2.11.0, commander@^2.13.0, commander@^2.14.1, commander@^2.5.0, commander@^2.9.0, commander@~2.15.0: +commander@2.15.x, commander@^2.11.0, commander@^2.13.0, commander@^2.14.1, commander@^2.9.0, commander@~2.15.0: version "2.15.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" @@ -2052,37 +2048,6 @@ commondir@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" -commoner@^0.10.1: - version "0.10.8" - resolved "https://registry.yarnpkg.com/commoner/-/commoner-0.10.8.tgz#34fc3672cd24393e8bb47e70caa0293811f4f2c5" - dependencies: - commander "^2.5.0" - detective "^4.3.1" - glob "^5.0.15" - graceful-fs "^4.1.2" - iconv-lite "^0.4.5" - mkdirp "^0.5.0" - private "^0.1.6" - q "^1.1.2" - recast "^0.11.17" - -commonmark-react-renderer@^4.3.4: - version "4.3.4" - resolved "https://registry.yarnpkg.com/commonmark-react-renderer/-/commonmark-react-renderer-4.3.4.tgz#29f345357951ab36eb386d45ea6bc08006f3ff9b" - dependencies: - lodash.assign "^4.2.0" - lodash.isplainobject "^4.0.6" - pascalcase "^0.1.1" - xss-filters "^1.2.6" - -commonmark@^0.24.0: - version "0.24.0" - resolved "https://registry.yarnpkg.com/commonmark/-/commonmark-0.24.0.tgz#b80de0182c546355643aa15db12bfb282368278f" - dependencies: - entities "~ 1.1.1" - mdurl "~ 1.0.1" - string.prototype.repeat "^0.2.0" - compare-version@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/compare-version/-/compare-version-0.1.2.tgz#0162ec2d9351f5ddd59a9202cba935366a725080" @@ -2710,13 +2675,6 @@ detect-node@^2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.0.3.tgz#a2033c09cc8e158d37748fbde7507832bd6ce127" -detective@^4.3.1: - version "4.7.1" - resolved "https://registry.yarnpkg.com/detective/-/detective-4.7.1.tgz#0eca7314338442febb6d65da54c10bb1c82b246e" - dependencies: - acorn "^5.2.1" - defined "^1.0.0" - devtron@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/devtron/-/devtron-1.4.0.tgz#b5e748bd6e95bbe70bfcc68aae6fe696119441e1" @@ -3219,7 +3177,7 @@ entities@1.0: version "1.0.0" resolved "https://registry.yarnpkg.com/entities/-/entities-1.0.0.tgz#b2987aa3821347fcde642b24fdfc9e4fb712bf26" -entities@^1.1.1, "entities@~ 1.1.1", entities@~1.1.1: +entities@^1.1.1, entities@~1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0" @@ -3227,13 +3185,6 @@ env-paths@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-1.0.0.tgz#4168133b42bb05c38a35b1ae4397c8298ab369e0" -envify@^3.0.0: - version "3.4.1" - resolved "https://registry.yarnpkg.com/envify/-/envify-3.4.1.tgz#d7122329e8df1688ba771b12501917c9ce5cbce8" - dependencies: - jstransform "^11.0.3" - through "~2.3.4" - errno@^0.1.3, errno@~0.1.7: version "0.1.7" resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.7.tgz#4684d71779ad39af177e3f007996f7c67c852618" @@ -3540,10 +3491,6 @@ espree@^3.5.4: acorn "^5.5.0" acorn-jsx "^3.0.0" -esprima-fb@^15001.1.0-dev-harmony-fb: - version "15001.1.0-dev-harmony-fb" - resolved "https://registry.yarnpkg.com/esprima-fb/-/esprima-fb-15001.1.0-dev-harmony-fb.tgz#30a947303c6b8d5e955bee2b99b1d233206a6901" - esprima@^2.6.0: version "2.7.3" resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581" @@ -3840,16 +3787,6 @@ faye-websocket@~0.11.0: dependencies: websocket-driver ">=0.5.1" -fbjs@^0.6.1: - version "0.6.1" - resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.6.1.tgz#9636b7705f5ba9684d44b72f78321254afc860f7" - dependencies: - core-js "^1.0.0" - loose-envify "^1.0.0" - promise "^7.0.3" - ua-parser-js "^0.7.9" - whatwg-fetch "^0.9.0" - fbjs@^0.8.16: version "0.8.16" resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db" @@ -4336,16 +4273,6 @@ glob-parent@^3.1.0: is-glob "^3.1.0" path-dirname "^1.0.0" -glob@^5.0.15: - version "5.0.15" - resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1" - dependencies: - inflight "^1.0.4" - inherits "2" - minimatch "2 || 3" - once "^1.3.0" - path-is-absolute "^1.0.0" - glob@^6.0.4: version "6.0.4" resolved "https://registry.yarnpkg.com/glob/-/glob-6.0.4.tgz#0f08860f6a155127b2fadd4f9ce24b1aab6e4d22" @@ -4836,7 +4763,7 @@ iconv-lite@0.4.19: version "0.4.19" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b" -iconv-lite@^0.4.17, iconv-lite@^0.4.23, iconv-lite@^0.4.4, iconv-lite@^0.4.5, iconv-lite@~0.4.13: +iconv-lite@^0.4.17, iconv-lite@^0.4.23, iconv-lite@^0.4.4, iconv-lite@~0.4.13: version "0.4.23" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.23.tgz#297871f63be507adcfbfca715d0cd0eed84e9a63" dependencies: @@ -5561,16 +5488,6 @@ jsprim@^1.2.2: json-schema "0.2.3" verror "1.10.0" -jstransform@^11.0.3: - version "11.0.3" - resolved "https://registry.yarnpkg.com/jstransform/-/jstransform-11.0.3.tgz#09a78993e0ae4d4ef4487f6155a91f6190cb4223" - dependencies: - base62 "^1.1.0" - commoner "^0.10.1" - esprima-fb "^15001.1.0-dev-harmony-fb" - object-assign "^2.0.0" - source-map "^0.4.2" - jsx-ast-utils@^2.0.0, jsx-ast-utils@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz#e801b1b39985e20fffc87b40e3748080e2dcac7f" @@ -6119,7 +6036,7 @@ mdast-util-to-hast@^3.0.0: unist-util-visit "^1.1.0" xtend "^4.0.1" -mdurl@^1.0.1, "mdurl@~ 1.0.1": +mdurl@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e" @@ -6700,10 +6617,6 @@ oauth-sign@~0.8.1, oauth-sign@~0.8.2: version "0.8.2" resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43" -object-assign@^2.0.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-2.1.1.tgz#43c36e5d569ff8e4816c4efa8be02d26967c18aa" - object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" @@ -7482,13 +7395,13 @@ promise-inflight@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3" -promise@^7.0.3, promise@^7.1.1: +promise@^7.1.1: version "7.3.1" resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf" dependencies: asap "~2.0.3" -prop-types@^15.5.1, prop-types@^15.5.10, prop-types@^15.5.6, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1: +prop-types@^15.5.10, prop-types@^15.5.6, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1: version "15.6.1" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.1.tgz#36644453564255ddda391191fb3a125cbdf654ca" dependencies: @@ -7687,14 +7600,6 @@ react-lifecycles-compat@^3.0.0: version "3.0.4" resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" -react-markdown@^2.5.0: - version "2.5.1" - resolved "https://registry.yarnpkg.com/react-markdown/-/react-markdown-2.5.1.tgz#f7a6c26a3a5faf5d4c2098155d9775e826fd56ee" - dependencies: - commonmark "^0.24.0" - commonmark-react-renderer "^4.3.4" - prop-types "^15.5.1" - react-modal@^3.1.7: version "3.4.5" resolved "https://registry.yarnpkg.com/react-modal/-/react-modal-3.4.5.tgz#75a7eefb8f4c8247278d5ce1c41249d7785d9f69" @@ -7721,11 +7626,10 @@ react-redux@^5.0.3: loose-envify "^1.1.0" prop-types "^15.6.0" -react-simplemde-editor@3.6.11: - version "3.6.11" - resolved "https://registry.yarnpkg.com/react-simplemde-editor/-/react-simplemde-editor-3.6.11.tgz#4b9e136f6d4d00218e8ece3d87949e23b14e21dc" +react-simplemde-editor@^3.6.15: + version "3.6.15" + resolved "https://registry.yarnpkg.com/react-simplemde-editor/-/react-simplemde-editor-3.6.15.tgz#b4991304c7e1cac79258bb225579d008c13b5991" dependencies: - react "^0.14.2" simplemde "^1.11.2" react-transition-group@1.x: @@ -7738,13 +7642,6 @@ react-transition-group@1.x: prop-types "^15.5.6" warning "^3.0.0" -react@^0.14.2: - version "0.14.9" - resolved "https://registry.yarnpkg.com/react/-/react-0.14.9.tgz#9110a6497c49d44ba1c0edd317aec29c2e0d91d1" - dependencies: - envify "^3.0.0" - fbjs "^0.6.1" - react@^16.3.0: version "16.4.0" resolved "https://registry.yarnpkg.com/react/-/react-16.4.0.tgz#402c2db83335336fba1962c08b98c6272617d585" @@ -7862,7 +7759,7 @@ readline-sync@^1.4.9: version "1.4.9" resolved "https://registry.yarnpkg.com/readline-sync/-/readline-sync-1.4.9.tgz#3eda8e65f23cd2a17e61301b1f0003396af5ecda" -recast@^0.11.17, recast@~0.11.12: +recast@~0.11.12: version "0.11.23" resolved "https://registry.yarnpkg.com/recast/-/recast-0.11.23.tgz#451fd3004ab1e4df9b4e4b66376b2a21912462d3" dependencies: @@ -8852,10 +8749,6 @@ string-width@^1.0.1, string-width@^1.0.2: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" -string.prototype.repeat@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/string.prototype.repeat/-/string.prototype.repeat-0.2.0.tgz#aba36de08dcee6a5a337d49b2ea1da1b28fc0ecf" - string_decoder@^1.0.0, string_decoder@~1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8" @@ -9114,7 +9007,7 @@ through2@~0.2.3: readable-stream "~1.1.9" xtend "~2.1.1" -through@^2.3.6, through@^2.3.8, through@~2.3.4, through@~2.3.6: +through@^2.3.6, through@^2.3.8, through@~2.3.6: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" @@ -9803,10 +9696,6 @@ whatwg-fetch@>=0.10.0: version "2.0.4" resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f" -whatwg-fetch@^0.9.0: - version "0.9.0" - resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-0.9.0.tgz#0e3684c6cb9995b43efc9df03e4c365d95fd9cc0" - whatwg-url-compat@~0.6.5: version "0.6.5" resolved "https://registry.yarnpkg.com/whatwg-url-compat/-/whatwg-url-compat-0.6.5.tgz#00898111af689bb097541cd5a45ca6c8798445bf" @@ -9944,10 +9833,6 @@ xpipe@*: version "1.0.5" resolved "https://registry.yarnpkg.com/xpipe/-/xpipe-1.0.5.tgz#8dd8bf45fc3f7f55f0e054b878f43a62614dafdf" -xss-filters@^1.2.6: - version "1.2.7" - resolved "https://registry.yarnpkg.com/xss-filters/-/xss-filters-1.2.7.tgz#59fa1de201f36f2f3470dcac5f58ccc2830b0a9a" - xtend@^4.0.0, xtend@^4.0.1, xtend@~4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"