Files
mattermost-mobile/app/components/remove_markdown.js
Elias Nahum 52886e7631 MM-28602 Fix announcement banner crash if it includes a hashtag (#4808)
* MM-28602 Fix announcement banner with hashtag crash

* Fix expanded announcement banner layout

* Fix announcement banner animation
2020-09-15 10:03:40 -03:00

81 lines
2.3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Parser} from 'commonmark';
import Renderer from 'commonmark-react-renderer';
import PropTypes from 'prop-types';
import React from 'react';
import {Text} from 'react-native';
export default class RemoveMarkdown extends React.PureComponent {
static propTypes = {
value: PropTypes.string.isRequired,
};
constructor(props) {
super(props);
this.parser = this.createParser();
this.renderer = this.createRenderer();
}
createParser = () => {
return new Parser();
};
createRenderer = () => {
return new Renderer({
renderers: {
text: this.renderText,
emph: Renderer.forwardChildren,
strong: Renderer.forwardChildren,
del: Renderer.forwardChildren,
code: Renderer.forwardChildren,
link: Renderer.forwardChildren,
image: this.renderNull,
atMention: Renderer.forwardChildren,
channelLink: Renderer.forwardChildren,
emoji: this.renderNull,
hashtag: Renderer.forwardChildren,
paragraph: Renderer.forwardChildren,
heading: Renderer.forwardChildren,
codeBlock: this.renderNull,
blockQuote: this.renderNull,
list: this.renderNull,
item: this.renderNull,
hardBreak: this.renderNull,
thematicBreak: this.renderNull,
softBreak: this.renderNull,
htmlBlock: this.renderNull,
htmlInline: this.renderNull,
table: this.renderNull,
table_row: this.renderNull,
table_cell: this.renderNull,
mention_highlight: Renderer.forwardChildren,
editedIndicator: Renderer.forwardChildren,
},
});
};
renderText = ({literal}) => {
return <Text>{literal}</Text>;
};
renderNull = () => {
return null;
};
render() {
const ast = this.parser.parse(this.props.value);
return <Text>{this.renderer.render(ast)}</Text>;
}
}