Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add markdown overrides #404

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions packages/desktop/src/markdown/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Children, FC} from 'react'
import MarkdownComponent from 'markdown-to-jsx'
import MarkdownComponent, {MarkdownOptions} from 'markdown-to-jsx'
import {Paragraph, Heading, Text} from '../typography'
import {Link} from '../link'
import {List} from '../list'
Expand All @@ -8,6 +8,7 @@ import {styled, Box, Image} from '@qiwi/pijma-core'
export interface MarkdownProps {
size?: 's' | 'm' | 'l'
children: string
overrides?: Record<string, FC<any>>
}

const MarkdownBox = styled(Box)({
Expand Down Expand Up @@ -127,7 +128,7 @@ const ol: FC<NumericListProps> = ({size, start, children}) => (
</MarkdownBox>
)

const overrides: {[tag: string]: FC<any>} = {
const defaultOverrides: MarkdownProps['overrides'] = {
p,
h1,
h2,
Expand All @@ -143,21 +144,24 @@ const overrides: {[tag: string]: FC<any>} = {
img,
}

export const Markdown: FC<MarkdownProps> = ({size = 'm', children}) => (
<MarkdownComponent
children={children}
options={{
overrides: Object.keys(overrides).reduce((prev, tag) => ({
...prev,
...{
[tag]: {
component: overrides[tag],
props: {
size,
export const Markdown: FC<MarkdownProps> = ({size = 'm', children, overrides = {}}) => {
const allOverrides = {...defaultOverrides, ...overrides}
return (
<MarkdownComponent
children={children}
options={{
overrides: Object.keys(allOverrides).reduce<MarkdownOptions['overrides']>((prev, tag) => ({
...prev,
...{
[tag]: {
component: allOverrides[tag],
props: {
size,
},
},
},
},
}), {}),
}}
/>
)
}), {}),
}}
/>
)
}
40 changes: 22 additions & 18 deletions packages/mobile/src/markdown/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Children, FC} from 'react'
import MarkdownComponent from 'markdown-to-jsx'
import MarkdownComponent, {MarkdownOptions} from 'markdown-to-jsx'
import {Paragraph, Heading, Text} from '../typography'
import {Link} from '../link'
import {List} from '../list'
Expand All @@ -8,6 +8,7 @@ import {styled, Box, Image} from '@qiwi/pijma-core'
export interface MarkdownProps {
size?: 's' | 'm' | 'l'
children: string
overrides?: Record<string, FC<any>>
}

const MarkdownBox = styled(Box)({
Expand Down Expand Up @@ -121,7 +122,7 @@ const ol: FC<NumericListProps> = ({size, start, children}) => (
</MarkdownBox>
)

const overrides: {[tag: string]: FC<any>} = {
const defaultOverrides: MarkdownProps['overrides'] = {
p,
h1,
h2,
Expand All @@ -136,21 +137,24 @@ const overrides: {[tag: string]: FC<any>} = {
img,
}

export const Markdown: FC<MarkdownProps> = ({size = 'm', children}) => (
<MarkdownComponent
children={children}
options={{
overrides: Object.keys(overrides).reduce((prev, tag) => ({
...prev,
...{
[tag]: {
component: overrides[tag],
props: {
size,
export const Markdown: FC<MarkdownProps> = ({size = 'm', children, overrides = {}}) => {
const allOverrides = {...defaultOverrides, ...overrides}
return (
<MarkdownComponent
children={children}
options={{
overrides: Object.keys(allOverrides).reduce<MarkdownOptions['overrides']>((prev, tag) => ({
...prev,
...{
[tag]: {
component: allOverrides[tag],
props: {
size,
},
},
},
},
}), {}),
}}
/>
)
}), {}),
}}
/>
)
}