diff --git a/src/components/common/MarkdownView.tsx b/src/components/common/MarkdownView.tsx index 8f810ff..a54742d 100644 --- a/src/components/common/MarkdownView.tsx +++ b/src/components/common/MarkdownView.tsx @@ -98,90 +98,68 @@ const spoilerRule = { export const MarkdownView = (props: any) => { let newProps = {...props}; + if (!newProps.onLinkPress) { newProps = Object.assign({onLinkPress: openUrl}, newProps); } + if (!newProps.markdownit) { newProps = Object.assign({markdownit: defaultMarkdownIt}, newProps); } + if (!newProps.rules) { newProps = Object.assign({rules: spoilerRule}, newProps); } + if (!newProps.style) { newProps = Object.assign({style: {}}, newProps); } - if (!newProps.style.body) { - newProps.style = Object.assign({body: {}}, newProps.style); - } - newProps.style.body = Object.assign( - {color: currentTheme.foregroundPrimary}, - newProps.style.body, - ); - if (!newProps.style.paragraph) { - newProps.style = Object.assign({paragraph: {}}, newProps.style); - } - newProps.style.paragraph = Object.assign( - { - color: currentTheme.foregroundPrimary, - marginTop: -3, - marginBottom: 2, - fontSize: app.settings.get('ui.messaging.fontSize'), - }, - newProps.style.paragraph, - ); - if (!newProps.style.link) { - newProps.style = Object.assign({link: {}}, newProps.style); - } - newProps.style.link = Object.assign( - {color: currentTheme.accentColor}, - newProps.style.link, - ); - if (!newProps.style.code_inline) { - newProps.style = Object.assign({code_inline: {}}, newProps.style); - } - newProps.style.code_inline = Object.assign( - { - color: currentTheme.foregroundPrimary, - backgroundColor: currentTheme.backgroundSecondary, - }, - newProps.style.code_inline, - ); - if (!newProps.style.fence) { - newProps.style = Object.assign({fence: {}}, newProps.style); - } - newProps.style.fence = Object.assign( - { - color: currentTheme.foregroundPrimary, - backgroundColor: currentTheme.backgroundSecondary, - borderWidth: 0, - }, - newProps.style.fence, - ); - if (!newProps.style.code_block) { - newProps.style = Object.assign({code_block: {}}, newProps.style); - } - newProps.style.code_block = Object.assign( - { - borderColor: currentTheme.foregroundPrimary, - color: currentTheme.foregroundPrimary, - backgroundColor: currentTheme.backgroundSecondary, - }, - newProps.style.code_block, - ); - if (!newProps.style.blockquote) { - newProps.style = Object.assign({blockquote: {}}, newProps.style); - } - newProps.style.blockquote = Object.assign( - { - marginBottom: 2, - paddingVertical: 6, - borderRadius: 4, - borderColor: currentTheme.foregroundPrimary, - color: currentTheme.foregroundPrimary, - backgroundColor: currentTheme.blockQuoteBackground, - }, - newProps.style.block_quote, - ); + + newProps.style.body = { + color: currentTheme.foregroundPrimary, + ...newProps.style.body, + }; + + newProps.style.paragraph = { + marginTop: -3, + marginBottom: 2, + fontSize: app.settings.get('ui.messaging.fontSize'), + ...newProps.style.paragraph, + }; + + newProps.style.link = { + color: currentTheme.accentColor, + ...newProps.style.link, + }; + + newProps.style.code_inline = { + backgroundColor: currentTheme.backgroundSecondary, + ...newProps.style.code_inline, + }; + + newProps.style.fence = { + backgroundColor: currentTheme.backgroundSecondary, + borderWidth: 0, + borderRadius: 4, + marginBottom: 2, + ...newProps.style.fence, + }; + + newProps.style.code_block = { + borderColor: currentTheme.foregroundPrimary, + backgroundColor: currentTheme.backgroundSecondary, + ...newProps.style.code_block, + }; + + newProps.style.blockquote = { + marginBottom: 2, + paddingVertical: 6, + borderRadius: 4, + borderColor: currentTheme.foregroundPrimary, + backgroundColor: currentTheme.blockQuoteBackground, + ...newProps.style.blockquote, + }; + try { return {newProps.children}; } catch (e) {