Skip to content

Commit

Permalink
reactor: clean up markdown props code, tweak styles slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexogamer committed Aug 28, 2024
1 parent e881b6d commit 7d9bc21
Showing 1 changed file with 50 additions and 72 deletions.
122 changes: 50 additions & 72 deletions src/components/common/MarkdownView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Markdown {...newProps}>{newProps.children}</Markdown>;
} catch (e) {
Expand Down

0 comments on commit 7d9bc21

Please sign in to comment.