From 7aa9753767dee499151592d91e65ecca1dc9942d Mon Sep 17 00:00:00 2001 From: Mient-jan Stelling Date: Fri, 19 Jan 2018 16:32:45 +0100 Subject: [PATCH] cleaning up code removing console.log --- src/index.js | 24 +++++++++++---- src/lib/AstRenderer.js | 1 - src/lib/renderRules.js | 46 ++++++++++++++++------------- src/lib/util/cleanupTokens.js | 17 ++++------- src/lib/util/getIsTextType.js | 13 ++++---- src/lib/util/getTokenTypeByToken.js | 5 ---- src/lib/util/stringToTokens.js | 2 -- 7 files changed, 58 insertions(+), 50 deletions(-) diff --git a/src/index.js b/src/index.js index 0f109ff..aac2e82 100644 --- a/src/index.js +++ b/src/index.js @@ -91,11 +91,11 @@ export default class Markdown extends Component { markdownParser = null; /** - * Only when the copy changes will the markdown render again. - * @param nextProps - * @param nextState - * @return {boolean} - */ + * Only when the copy changes will the markdown render again. + * @param nextProps + * @param nextState + * @return {boolean} + */ shouldComponentUpdate(nextProps, nextState) { const copy = this.getCopyFromChildren(nextProps.children); @@ -117,6 +117,10 @@ export default class Markdown extends Component { return false; } + /** + * + * @param props + */ updateSettings(props = this.props) { const { renderer, rules, style, plugins, markdownit } = props; @@ -192,14 +196,24 @@ export default class Markdown extends Component { this.updateSettings(this.props); } + /** + * + * @param nextProps + */ componentWillReceiveProps(nextProps) { this.updateSettings(nextProps); } + /** + * + * @param children + * @return {string} + */ getCopyFromChildren(children = this.props.children) { return children instanceof Array ? children.join('') : children; } + /** * * @return {View} diff --git a/src/lib/AstRenderer.js b/src/lib/AstRenderer.js index 37f30be..e6a528c 100644 --- a/src/lib/AstRenderer.js +++ b/src/lib/AstRenderer.js @@ -65,7 +65,6 @@ export default class AstRenderer { * @return {*} */ render = nodes => { - console.log(nodes); const children = nodes.map(value => this.renderNode(value, [])); return rootRenderRule(children); }; diff --git a/src/lib/renderRules.js b/src/lib/renderRules.js index 26ef61b..4652b6e 100644 --- a/src/lib/renderRules.js +++ b/src/lib/renderRules.js @@ -17,18 +17,18 @@ const renderRules = { }, textgroup: (node, children, parent, styles) => { - return {children}; + return ( + + {children} + + ); }, inline: (node, children, parent, styles) => { return {children}; }, text: (node, children, parent, styles) => { - return ( - - {node.content} - - ); + return {node.content}; }, span: (node, children, parent, styles) => { return {children}; @@ -70,34 +70,34 @@ const renderRules = { }, heading1: (node, children, parent, styles) => ( - - {children} - + + {children} + ), heading2: (node, children, parent, styles) => ( - + {children} - + ), heading3: (node, children, parent, styles) => ( - + {children} - + ), heading4: (node, children, parent, styles) => ( - + {children} - + ), heading5: (node, children, parent, styles) => ( - + {children} - + ), heading6: (node, children, parent, styles) => ( - + {children} - + ), paragraph: (node, children, parent, styles) => ( @@ -221,7 +221,13 @@ const renderRules = { {"\n"} ), image: (node, children, parent, styles) => { - return ; + return ( + + ); } }; diff --git a/src/lib/util/cleanupTokens.js b/src/lib/util/cleanupTokens.js index cae968d..5e892d3 100644 --- a/src/lib/util/cleanupTokens.js +++ b/src/lib/util/cleanupTokens.js @@ -2,14 +2,9 @@ import getTokenTypeByToken from "./getTokenTypeByToken"; import groupTextTokens from "./groupTextTokens"; import removeInlineTokens from "./removeInlineTokens"; -export function cleanupTokens(tokens){ - - tokens = removeInlineTokens(tokens); - tokens.forEach(token => token.type = getTokenTypeByToken(token)) - - tokens = groupTextTokens(tokens); - - console.log('tokens', tokens); - - return tokens; -} \ No newline at end of file +export function cleanupTokens(tokens) { + tokens = removeInlineTokens(tokens); + tokens.forEach(token => (token.type = getTokenTypeByToken(token))); + tokens = groupTextTokens(tokens); + return tokens; +} diff --git a/src/lib/util/getIsTextType.js b/src/lib/util/getIsTextType.js index 6e44a96..9933e0b 100644 --- a/src/lib/util/getIsTextType.js +++ b/src/lib/util/getIsTextType.js @@ -9,15 +9,16 @@ const textTypes = [ 'a', 's', 'em', - 'heading1', - 'heading2', - 'heading3', - 'heading4', - 'heading5', - 'heading6', 'softbreak', ]; +// 'heading1', +// 'heading2', +// 'heading3', +// 'heading4', +// 'heading5', +// 'heading6', + /** * * @param node diff --git a/src/lib/util/getTokenTypeByToken.js b/src/lib/util/getTokenTypeByToken.js index 02efec1..501267f 100644 --- a/src/lib/util/getTokenTypeByToken.js +++ b/src/lib/util/getTokenTypeByToken.js @@ -31,11 +31,6 @@ export default function getTokenTypeByToken(token) { cleanedType = token.type.replace(regSelectOpenClose, ""); } - if(cleanedType === 'unknown') - { - console.log(token); - } - switch (cleanedType) { case "heading": { cleanedType = `${cleanedType}${token.tag.substr(1)}`; diff --git a/src/lib/util/stringToTokens.js b/src/lib/util/stringToTokens.js index 898aa85..0c8b61b 100644 --- a/src/lib/util/stringToTokens.js +++ b/src/lib/util/stringToTokens.js @@ -6,7 +6,5 @@ export function stringToTokens(source, markdownIt) { console.warn(err); } - console.log('result', result); - return result; } \ No newline at end of file