mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-24 17:44:50 +03:00
refactor Typography to include Markdown processing
This commit is contained in:
parent
2576ef12b4
commit
01a6dd2f1a
@ -50,31 +50,18 @@ const onDeepLink = async (object) => {
|
||||
return window.open(slug);
|
||||
};
|
||||
|
||||
const ProcessedLink = ({href, children, dark}) => {
|
||||
|
||||
|
||||
}
|
||||
|
||||
const Link = ({href, children, dark}) => {
|
||||
return <a css={dark ? STYLES_LINK_DARK: STYLES_LINK} href={href} target="_blank" rel="nofollow">
|
||||
{children}
|
||||
</a>
|
||||
}
|
||||
|
||||
export const ProcessedText = ({ text, dark }) => {
|
||||
let replacedText;
|
||||
const remarkReactComponents = {
|
||||
a: (props) => dark ? <Link dark {...props} /> : <Link {...props} />,
|
||||
h1: function (props) {
|
||||
return React.createElement('h2', props)
|
||||
}
|
||||
};
|
||||
console.log('gekki', remarkReactComponents)
|
||||
|
||||
return <Markdown body={text} options={{remarkReactComponents}} />
|
||||
|
||||
|
||||
replacedText = StringReplace(text, /(https?:\/\/\S+)/g, (match, i) => (
|
||||
<a css={dark ? STYLES_LINK_DARK : STYLES_LINK} key={match + i} href={match} target="_blank">
|
||||
{match}
|
||||
</a>
|
||||
));
|
||||
|
||||
const LinkMention = () => {
|
||||
replacedText = StringReplace(
|
||||
replacedText,
|
||||
/@(\w*[0-9a-zA-Z-_]+\w*[0-9a-zA-Z-_])/g,
|
||||
@ -89,7 +76,9 @@ export const ProcessedText = ({ text, dark }) => {
|
||||
</a>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const LinkHash = () => {
|
||||
//NOTE(martina): previous regex: /#(\w*[0-9a-zA-Z-_]+\w*[0-9a-zA-Z-_])\/(\w*[0-9a-zA-Z-_]+\w*[0-9a-zA-Z-_])/g,
|
||||
replacedText = StringReplace(
|
||||
replacedText,
|
||||
@ -107,6 +96,21 @@ export const ProcessedText = ({ text, dark }) => {
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export const ProcessedText = ({ text, dark }) => {
|
||||
let replacedText;
|
||||
const remarkReactComponents = {
|
||||
a: (props) => dark ? <Link dark {...props} /> : <Link {...props} />,
|
||||
};
|
||||
|
||||
return <Markdown md={text} options={{remarkReactComponents}} />
|
||||
|
||||
// replacedText = StringReplace(text, /(https?:\/\/\S+)/g, (match, i) => (
|
||||
// <a css={dark ? STYLES_LINK_DARK : STYLES_LINK} key={match + i} href={match} target="_blank">
|
||||
// {match}
|
||||
// </a>
|
||||
// ));
|
||||
|
||||
return <React.Fragment>{replacedText}</React.Fragment>;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user