Skip to content

Commit a92750e

Browse files
Merge pull request #234 from virdesai/markdown-rule-customization
markdown rule customization
2 parents fc07b17 + a32feea commit a92750e

File tree

9 files changed

+52
-29
lines changed

9 files changed

+52
-29
lines changed

native-package/yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6266,10 +6266,10 @@ stream-browserify@^2.0.1:
62666266
inherits "~2.0.1"
62676267
readable-stream "^2.0.2"
62686268

6269-
6270-
version "0.12.3"
6271-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-0.12.3.tgz#d180d51a1661d578dbb6253791fa59dc23f71b6e"
6272-
integrity sha512-/uE95FKsct9jghHw29JVLVZxlq/IodQOjES29aIJh3XfqKyOS9MPtu/wKJpBPDGpxrr2Xc+H8XU0Ocs3UgjMZA==
6269+
6270+
version "0.12.4"
6271+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-0.12.4.tgz#8cf1e01fe3b178eb12932e6a88b4c4a8106d363d"
6272+
integrity sha512-YEWJ333pHrXXFE7MLwMfyk6zXDVTmqEEKrUubQ9rwkPICx3WpVT/dwsVV2xDun9UZpTyAOIitFLdv7Mdn6SJiQ==
62736273
dependencies:
62746274
"@babel/runtime" "^7.1.2"
62756275
"@stream-io/react-native-simple-markdown" "^1.1.3"
@@ -6289,13 +6289,13 @@ [email protected]:
62896289
react-native-actionsheet "^2.4.2"
62906290
react-native-image-zoom-viewer "^2.2.25"
62916291
seamless-immutable "^7.1.4"
6292-
stream-chat "^1.11.1"
6292+
stream-chat "^1.12.1"
62936293
uuid "^3.3.2"
62946294

6295-
stream-chat@^1.11.1:
6296-
version "1.11.3"
6297-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-1.11.3.tgz#b29fe3d410e203416de49109422acaee0a04a80f"
6298-
integrity sha512-QC8uKB1GQBfJE1wHswbAP4lgluR6+g2rP0GPRxJ2HSOh/EpTZFwWaFwRrl+1oDdzLHCOchcHsfFe2t70z9FC/A==
6295+
stream-chat@^1.12.1:
6296+
version "1.12.1"
6297+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-1.12.1.tgz#a4bc0ee973e28c5eaabd98be35f476980bff4fac"
6298+
integrity sha512-+FRk1Z9sR+mGTbXgC0RKAnDp+1IG8N6NAwrWI/GZhNQthR70PbQoG7KI4y28su8PMCpRN1+9bl/pkXDGG8ILiw==
62996299
dependencies:
63006300
"@babel/runtime" "^7.3.1"
63016301
"@types/seamless-immutable" "7.1.10"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
},
6969
"dependencies": {
7070
"@babel/runtime": "^7.1.2",
71-
"@stream-io/react-native-simple-markdown": "^1.1.3",
71+
"@stream-io/react-native-simple-markdown": "^1.2.0",
7272
"@stream-io/styled-components": "^4.2.1",
7373
"anchorme": "^1.1.2",
7474
"babel-plugin-macros": "^2.5.1",

src/components/MessageSimple/MessageContent.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ class MessageContent extends React.PureComponent {
372372
readOnly: PropTypes.bool,
373373
/** Disables the message UI. Which means, message actions, reactions won't work. */
374374
disabled: PropTypes.bool,
375+
/** Object specifying rules defined within simple-markdown https://github.com/Khan/simple-markdown#adding-a-simple-extension */
376+
markdownRules: PropTypes.object,
375377
};
376378

377379
static defaultProps = {
@@ -502,6 +504,7 @@ class MessageContent extends React.PureComponent {
502504
FileAttachmentGroup,
503505
t,
504506
tDateTimeParser,
507+
markdownRules,
505508
} = this.props;
506509

507510
const Attachment = this.props.Attachment;
@@ -702,6 +705,7 @@ class MessageContent extends React.PureComponent {
702705
Message={Message}
703706
openThread={this.openThread}
704707
handleReaction={handleReaction}
708+
markdownRules={markdownRules}
705709
/>
706710
</ContainerInner>
707711
{repliesEnabled ? (

src/components/MessageSimple/MessageTextContainer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const MessageTextContainer = withTheme((props) => {
5858
const markdownStyles = props.theme
5959
? props.theme.message.content.markdown
6060
: {};
61+
const markdownRules = props.markdownRules || {};
6162
return (
6263
<React.Fragment>
6364
<TextContainer
@@ -67,7 +68,7 @@ export const MessageTextContainer = withTheme((props) => {
6768
type={message.type}
6869
>
6970
{!MessageText ? (
70-
renderText(message, markdownStyles)
71+
renderText(message, markdownStyles, markdownRules)
7172
) : (
7273
<MessageText {...props} renderText={renderText} />
7374
)}
@@ -96,4 +97,6 @@ MessageTextContainer.propTypes = {
9697
MessageText: PropTypes.oneOfType([PropTypes.node, PropTypes.elementType]),
9798
/** Complete theme object. Its a [defaultTheme](https://github.com/GetStream/stream-chat-react-native/blob/master/src/styles/theme.js#L22) merged with customized theme provided as prop to Chat component */
9899
theme: PropTypes.object,
100+
/** Object specifying rules defined within simple-markdown https://github.com/Khan/simple-markdown#adding-a-simple-extension */
101+
markdownRules: PropTypes.object,
99102
};

src/components/MessageSimple/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ export const MessageSimple = themed(
316316
readOnly: PropTypes.bool,
317317
/** Disables the message UI. Which means, message actions, reactions won't work. */
318318
disabled: PropTypes.bool,
319+
/** Object specifying rules defined within simple-markdown https://github.com/Khan/simple-markdown#adding-a-simple-extension */
320+
markdownRules: PropTypes.object,
319321
};
320322

321323
static defaultProps = {

src/components/docs/renderText.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ It accepts following params:
88

99
- message { object } Message object
1010
- style { object } - https://github.com/GetStream/react-native-simple-markdown#styles-1
11+
- markdownRules { object } - https://github.com/GetStream/react-native-simple-markdown#rules

src/utils/renderText.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import React from 'react';
12
import Markdown from '@stream-io/react-native-simple-markdown';
2-
import { truncate } from 'lodash-es';
33
import anchorme from 'anchorme';
4-
import React from 'react';
4+
import { truncate } from 'lodash-es';
55

6-
export const renderText = (message, styles) => {
6+
export const renderText = (message, styles, markdownRules) => {
77
// take the @ mentions and turn them into markdown?
88
// translate links
99
let { text } = message;
@@ -40,7 +40,11 @@ export const renderText = (message, styles) => {
4040
...styles,
4141
};
4242

43-
return <Markdown styles={markdownStyles}>{newText}</Markdown>;
43+
return (
44+
<Markdown rules={markdownRules} styles={markdownStyles}>
45+
{newText}
46+
</Markdown>
47+
);
4448
};
4549

4650
const defaultMarkdownStyles = {
@@ -58,7 +62,6 @@ const defaultMarkdownStyles = {
5862
color: 'red',
5963
fontSize: 13,
6064
padding: 3,
61-
paddingLeft: 5,
62-
paddingRight: 5,
65+
paddingHorizontal: 5,
6366
},
6467
};

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ export interface MessageUIComponentProps
801801
AttachmentFileIcon?: React.ElementType<FileIconUIComponentProps>;
802802
formatDate(date: string): string;
803803
additionalTouchableProps?: object;
804+
markdownRules?: object; // TODO: typescript the markdown lib
804805
}
805806

806807
export interface MessageHeaderUIComponentProps

yarn.lock

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,14 +1165,13 @@
11651165
dependencies:
11661166
type-detect "4.0.8"
11671167

1168-
"@stream-io/react-native-simple-markdown@^1.1.3":
1169-
version "1.1.3"
1170-
resolved "https://registry.yarnpkg.com/@stream-io/react-native-simple-markdown/-/react-native-simple-markdown-1.1.3.tgz#690cac9236d28eab3b0e4b896714c81254258c2d"
1171-
integrity sha512-O0/v3mlTaD9+eAVxThreC0sX1eOgcJRR7N1FOZ9zpf3IFYVr4VU+S7tYZHqmNzyh1N3VUi4+Fao+ZxEb/YToXw==
1168+
"@stream-io/react-native-simple-markdown@^1.2.0":
1169+
version "1.2.0"
1170+
resolved "https://registry.yarnpkg.com/@stream-io/react-native-simple-markdown/-/react-native-simple-markdown-1.2.0.tgz#f1ea7db1e16712a3428b79fdd522464ae2caccdb"
1171+
integrity sha512-rqs625+3v+Nz4yUocmMr/Ar6Jb31HZWXDOqEi4MjU3IDLCRi9XaIeH7FlCD4GrabqUEYjq8EY709fxpVBjaSxw==
11721172
dependencies:
1173-
lodash "^4.15.0"
1174-
prop-types "^15.6.0"
1175-
simple-markdown "^0.4.4"
1173+
lodash "^4.17.15"
1174+
simple-markdown "^0.7.2"
11761175

11771176
"@stream-io/styled-components@^4.2.1":
11781177
version "4.2.1"
@@ -1321,6 +1320,14 @@
13211320
"@types/prop-types" "*"
13221321
csstype "^2.2.0"
13231322

1323+
"@types/react@>=16.0.0":
1324+
version "16.9.41"
1325+
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.41.tgz#925137ee4d2ff406a0ecf29e8e9237390844002e"
1326+
integrity sha512-6cFei7F7L4wwuM+IND/Q2cV1koQUvJ8iSV+Gwn0c3kvABZ691g7sp3hfEQHOUBJtccl1gPi+EyNjMIl9nGA0ug==
1327+
dependencies:
1328+
"@types/prop-types" "*"
1329+
csstype "^2.2.0"
1330+
13241331
13251332
version "7.1.10"
13261333
resolved "https://registry.yarnpkg.com/@types/seamless-immutable/-/seamless-immutable-7.1.10.tgz#4c4313ad5069c881f38a19c7df20b7b694bf0f57"
@@ -6334,7 +6341,7 @@ [email protected]:
63346341
resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c"
63356342
integrity sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=
63366343

6337-
lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.6.1:
6344+
lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.6.1:
63386345
version "4.17.15"
63396346
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
63406347
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
@@ -9085,10 +9092,12 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
90859092
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
90869093
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=
90879094

9088-
simple-markdown@^0.4.4:
9089-
version "0.4.4"
9090-
resolved "https://registry.yarnpkg.com/simple-markdown/-/simple-markdown-0.4.4.tgz#9bd597bdd5c2f5a789e56a4dbf06427d76c3834f"
9091-
integrity sha512-ZmlNUGR1KI12sPHeQ7dQY1qM5KfOgFqClNNVO8zQ9Pg6u7gHLCPFGD+VC7MCwpGDMd1uw3Bb2TfFfR8d6bB34A==
9095+
simple-markdown@^0.7.2:
9096+
version "0.7.2"
9097+
resolved "https://registry.yarnpkg.com/simple-markdown/-/simple-markdown-0.7.2.tgz#896cc3e3dd9acd068d30e696bce70b0b97655665"
9098+
integrity sha512-XfCvqqzMyzRj4L7eIxJgGaQ2Gaxr20GhTFMB+1yuY8q3xffjzmOg4Q5tC0kcaJPV42NNUHCQDaRK6jzi3/RhrA==
9099+
dependencies:
9100+
"@types/react" ">=16.0.0"
90929101

90939102
sisteransi@^1.0.4:
90949103
version "1.0.4"

0 commit comments

Comments
 (0)