From de6f40a27998c0b540ed1a41f10522a4692bae6c Mon Sep 17 00:00:00 2001 From: Le Long Date: Sat, 17 Jun 2017 23:56:38 +0200 Subject: [PATCH] addressing request change --- ui/js/component/common.js | 46 ++++++++--------------- ui/js/component/fileCard/view.jsx | 2 +- ui/js/component/form.js | 60 ++++++++++-------------------- ui/scss/component/_form-field.scss | 4 +- 4 files changed, 38 insertions(+), 74 deletions(-) diff --git a/ui/js/component/common.js b/ui/js/component/common.js index f31294a68..3f409c74a 100644 --- a/ui/js/component/common.js +++ b/ui/js/component/common.js @@ -1,5 +1,7 @@ import React from "react"; +import ReactDOMServer from "react-dom/server"; import lbry from "../lbry.js"; +import ReactMarkdown from "react-markdown"; //component/icon.js export class Icon extends React.PureComponent { @@ -51,45 +53,27 @@ export class TruncatedMarkdown extends React.PureComponent { lines: null, }; - truncateMarkdown(text) { - let output; - try { - output = text - // Remove HTML tags - .replace(/<(.*?)>/g, "$1") - // Remove setext-style headers - .replace(/^[=\-]{2,}\s*$/g, "") - // Remove footnotes? - .replace(/\[\^.+?\](\: .*?$)?/g, "") - .replace(/\s{0,2}\[.*?\]: .*?$/g, "") - // Remove images - .replace(/\!\[.*?\][\[\(].*?[\]\)]/g, "") - // Remove inline links - .replace(/\[(.*?)\][\[\(].*?[\]\)]/g, "$1") - // Remove Blockquotes - .replace(/>/g, "") - // Remove reference-style links? - .replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, "") - // Remove atx-style headers - .replace(/^\#{1,6}\s*([^#]*)\s*(\#{1,6})?/gm, "$1") - .replace(/([\*_]{1,3})(\S.*?\S)\1/g, "$2") - .replace(/(`{3,})(.*?)\1/gm, "$2") - .replace(/^-{3,}\s*$/g, "") - .replace(/`(.+?)`/g, "$1") - .replace(/\n{2,}/g, "\n\n"); - } catch (e) { - return text; - } - return output; + transformMarkdown(text) { + // render markdown to html string then trim html tag + let htmlString = ReactDOMServer.renderToStaticMarkup( + + ); + var txt = document.createElement("textarea"); + txt.innerHTML = htmlString; + return txt.value.replace(/<(?:.|\n)*?>/gm, ""); } render() { + let content = this.props.children && typeof this.props.children === "string" + ? this.transformMarkdown(this.props.children) + : this.props.children; + console.log(content); return ( - {this.truncateMarkdown(this.props.children)} + {content} ); } diff --git a/ui/js/component/fileCard/view.jsx b/ui/js/component/fileCard/view.jsx index 2eb7c8e55..094973d7e 100644 --- a/ui/js/component/fileCard/view.jsx +++ b/ui/js/component/fileCard/view.jsx @@ -91,7 +91,7 @@ class FileCard extends React.PureComponent { style={{ backgroundImage: "url('" + metadata.thumbnail + "')" }} />}
- {description} + {description}
{obscureNsfw && this.state.hovered diff --git a/ui/js/component/form.js b/ui/js/component/form.js index 3f9f1ffec..a05843f23 100644 --- a/ui/js/component/form.js +++ b/ui/js/component/form.js @@ -41,7 +41,7 @@ export class FormField extends React.PureComponent { this._element = "input"; this._type = "text"; } else if (this.props.type == "SimpleMDE") { - this._element = "SimpleMDE"; + this._element = SimpleMDE; this._type = "textarea"; } else if (formFieldFileSelectorTypes.includes(this.props.type)) { this._element = "input"; @@ -113,45 +113,25 @@ export class FormField extends React.PureComponent { delete otherProps.className; delete otherProps.postfix; delete otherProps.prefix; - const element = this._element === "SimpleMDE" - ? - {this.props.children} - - : - {this.props.children} - ; + const element = ( + + {this.props.children} + + ); return (
diff --git a/ui/scss/component/_form-field.scss b/ui/scss/component/_form-field.scss index 4b71c2bd9..59a72f721 100644 --- a/ui/scss/component/_form-field.scss +++ b/ui/scss/component/_form-field.scss @@ -165,6 +165,6 @@ input[type="text"].input-copyable { color: $color-help; } -.CodeMirror-scroll { - height: auto !important; +.form-field__input.form-field__input-SimpleMDE .CodeMirror-scroll { + height: auto; } \ No newline at end of file