Skip to content

Commit

Permalink
cleaning up code
Browse files Browse the repository at this point in the history
removing console.log
  • Loading branch information
mientjan committed Jan 19, 2018
1 parent 9226917 commit 7aa9753
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 50 deletions.
24 changes: 19 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;

Expand Down Expand Up @@ -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}
Expand Down
1 change: 0 additions & 1 deletion src/lib/AstRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
46 changes: 26 additions & 20 deletions src/lib/renderRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ const renderRules = {
},

textgroup: (node, children, parent, styles) => {
return <Text key={node.key} style={styles.text}>{children}</Text>;
return (
<Text key={node.key} style={styles.text}>
{children}
</Text>
);
},
inline: (node, children, parent, styles) => {
return <Text key={node.key}>{children}</Text>;
},

text: (node, children, parent, styles) => {
return (
<Text key={node.key}>
{node.content}
</Text>
);
return <Text key={node.key}>{node.content}</Text>;
},
span: (node, children, parent, styles) => {
return <Text key={node.key}>{children}</Text>;
Expand Down Expand Up @@ -70,34 +70,34 @@ const renderRules = {
},

heading1: (node, children, parent, styles) => (
<Text key={node.key} style={[styles.heading, styles.heading1]}>
{children}
</Text>
<View key={node.key} style={[styles.heading, styles.heading1]}>
{children}
</View>
),
heading2: (node, children, parent, styles) => (
<Text key={node.key} style={[styles.heading, styles.heading2]}>
<View key={node.key} style={[styles.heading, styles.heading2]}>
{children}
</Text>
</View>
),
heading3: (node, children, parent, styles) => (
<Text key={node.key} style={[styles.heading, styles.heading3]}>
<View key={node.key} style={[styles.heading, styles.heading3]}>
{children}
</Text>
</View>
),
heading4: (node, children, parent, styles) => (
<Text key={node.key} style={[styles.heading, styles.heading4]}>
<View key={node.key} style={[styles.heading, styles.heading4]}>
{children}
</Text>
</View>
),
heading5: (node, children, parent, styles) => (
<Text key={node.key} style={[styles.heading, styles.heading5]}>
<View key={node.key} style={[styles.heading, styles.heading5]}>
{children}
</Text>
</View>
),
heading6: (node, children, parent, styles) => (
<Text key={node.key} style={[styles.heading, styles.heading6]}>
<View key={node.key} style={[styles.heading, styles.heading6]}>
{children}
</Text>
</View>
),

paragraph: (node, children, parent, styles) => (
Expand Down Expand Up @@ -221,7 +221,13 @@ const renderRules = {
<Text key={node.key}>{"\n"}</Text>
),
image: (node, children, parent, styles) => {
return <FitImage key={node.key} style={{margin: 1}} source={{ uri: node.attributes.src }} />;
return (
<FitImage
key={node.key}
style={{ margin: 1 }}
source={{ uri: node.attributes.src }}
/>
);
}
};

Expand Down
17 changes: 6 additions & 11 deletions src/lib/util/cleanupTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
export function cleanupTokens(tokens) {
tokens = removeInlineTokens(tokens);
tokens.forEach(token => (token.type = getTokenTypeByToken(token)));
tokens = groupTextTokens(tokens);
return tokens;
}
13 changes: 7 additions & 6 deletions src/lib/util/getIsTextType.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ const textTypes = [
'a',
's',
'em',
'heading1',
'heading2',
'heading3',
'heading4',
'heading5',
'heading6',
'softbreak',
];

// 'heading1',
// 'heading2',
// 'heading3',
// 'heading4',
// 'heading5',
// 'heading6',

/**
*
* @param node
Expand Down
5 changes: 0 additions & 5 deletions src/lib/util/getTokenTypeByToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
Expand Down
2 changes: 0 additions & 2 deletions src/lib/util/stringToTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ export function stringToTokens(source, markdownIt) {
console.warn(err);
}

console.log('result', result);

return result;
}

0 comments on commit 7aa9753

Please sign in to comment.