mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 01:52:42 +03:00
Merge pull request #4886 from urbit/lf/graphdown-fixes
GraphContent: rendering fixes
This commit is contained in:
commit
faf643adaf
35
pkg/interface/package-lock.json
generated
35
pkg/interface/package-lock.json
generated
@ -9133,9 +9133,38 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"remark-breaks": {
|
"remark-breaks": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/remark-breaks/-/remark-breaks-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/remark-breaks/-/remark-breaks-2.0.2.tgz",
|
||||||
"integrity": "sha512-CZKI8xdPUnvMqPxYEIBBUg8C0B0kyn14lkW0abzhfh/P71YRIxCC3wvBh6AejQL602OxF6kNRl1x4HAZA07JyQ=="
|
"integrity": "sha512-LsQnPPQ7Fzp9RTjj4IwdEmjPOr9bxe9zYKWhs9ZQOg9hMg8rOfeeqQ410cvVdIK87Famqza1CKRxNkepp2EvUA==",
|
||||||
|
"requires": {
|
||||||
|
"unist-util-visit": "^2.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"unist-util-is": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-ZOQSsnce92GrxSqlnEEseX0gi7GH9zTJZ0p9dtu87WRb/37mMPO2Ilx1s/t9vBHrFhbgweUwb+t7cIn5dxPhZg=="
|
||||||
|
},
|
||||||
|
"unist-util-visit": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-iJ4/RczbJMkD0712mGktuGpm/U4By4FfDonL7N/9tATGIF4imikjOuagyMY53tnZq3NP6BcmlrHhEKAfGWjh7Q==",
|
||||||
|
"requires": {
|
||||||
|
"@types/unist": "^2.0.0",
|
||||||
|
"unist-util-is": "^4.0.0",
|
||||||
|
"unist-util-visit-parents": "^3.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"unist-util-visit-parents": {
|
||||||
|
"version": "3.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-3.1.1.tgz",
|
||||||
|
"integrity": "sha512-1KROIZWo6bcMrZEwiH2UrXDyalAa0uqzWCxCJj6lPOvTve2WkfgCytoDTPaMnodXh1WrXOq0haVYHj99ynJlsg==",
|
||||||
|
"requires": {
|
||||||
|
"@types/unist": "^2.0.0",
|
||||||
|
"unist-util-is": "^4.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"remark-disable-tokenizers": {
|
"remark-disable-tokenizers": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
"react-virtuoso": "^0.20.3",
|
"react-virtuoso": "^0.20.3",
|
||||||
"react-visibility-sensor": "^5.1.1",
|
"react-visibility-sensor": "^5.1.1",
|
||||||
"remark": "^12.0.0",
|
"remark": "^12.0.0",
|
||||||
"remark-breaks": "^2.0.1",
|
"remark-breaks": "^2.0.2",
|
||||||
"remark-disable-tokenizers": "1.1.0",
|
"remark-disable-tokenizers": "1.1.0",
|
||||||
"stacktrace-js": "^2.0.2",
|
"stacktrace-js": "^2.0.2",
|
||||||
"style-loader": "^1.3.0",
|
"style-loader": "^1.3.0",
|
||||||
|
@ -495,7 +495,8 @@ export const Message = React.memo(({
|
|||||||
width='36px'
|
width='36px'
|
||||||
textAlign='right'
|
textAlign='right'
|
||||||
left='0'
|
left='0'
|
||||||
top='3px'
|
top='2px'
|
||||||
|
lineHeight="tall"
|
||||||
fontSize={0}
|
fontSize={0}
|
||||||
gray
|
gray
|
||||||
>
|
>
|
||||||
|
@ -230,28 +230,24 @@ const header = ({ children, depth, ...rest }) => {
|
|||||||
const level = depth;
|
const level = depth;
|
||||||
const inner =
|
const inner =
|
||||||
level === 1 ? (
|
level === 1 ? (
|
||||||
<H1 display='block'>{children}</H1>
|
<H1 display="block">{children}</H1>
|
||||||
) : level === 2 ? (
|
) : level === 2 ? (
|
||||||
<H2 display='block'>{children}</H2>
|
<H2 display="block">{children}</H2>
|
||||||
) : level === 3 ? (
|
) : level === 3 ? (
|
||||||
<H3 display='block'>{children}</H3>
|
<H3 display="block">{children}</H3>
|
||||||
) : (
|
) : (
|
||||||
<H4 display='block'>{children}</H4>
|
<H4 display="block">{children}</H4>
|
||||||
);
|
|
||||||
return (
|
|
||||||
<Box {...rest}>
|
|
||||||
{inner}
|
|
||||||
</Box>
|
|
||||||
);
|
);
|
||||||
|
return <Box {...rest}>{inner}</Box>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderers = {
|
const renderers = {
|
||||||
heading: header,
|
heading: header,
|
||||||
break: () => {
|
break: () => {
|
||||||
return <Box display='block' width='100%' height={2}></Box>
|
return <Box display="block" width="100%" height={2}></Box>;
|
||||||
},
|
},
|
||||||
thematicBreak: () => {
|
thematicBreak: () => {
|
||||||
return <Box display='block' width='100%' height={2}></Box>
|
return <Box display="block" width="100%" height={2}></Box>;
|
||||||
},
|
},
|
||||||
inlineCode: ({ language, value }) => {
|
inlineCode: ({ language, value }) => {
|
||||||
return (
|
return (
|
||||||
@ -268,27 +264,30 @@ const renderers = {
|
|||||||
},
|
},
|
||||||
strong: ({ children }) => {
|
strong: ({ children }) => {
|
||||||
return (
|
return (
|
||||||
<Text fontWeight="bold" lineHeight='1'>
|
<Text fontWeight="bold" lineHeight="1">
|
||||||
{children}
|
{children}
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
emphasis: ({ children }) => {
|
emphasis: ({ children }) => {
|
||||||
return (
|
return (
|
||||||
<Text fontStyle="italic" fontSize="1" lineHeight={'20px'}>
|
<Text fontStyle="italic" fontSize="1" lineHeight="tall">
|
||||||
{children}
|
{children}
|
||||||
</Text>
|
</Text>
|
||||||
)
|
);
|
||||||
},
|
},
|
||||||
blockquote: ({ children, tall, ...rest }) => {
|
blockquote: ({ children, depth, tall, ...rest }) => {
|
||||||
|
if (depth > 1) {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
lineHeight="20px"
|
lineHeight="tall"
|
||||||
display="block"
|
display="block"
|
||||||
borderLeft="1px solid"
|
borderLeft="1px solid"
|
||||||
color="black"
|
color="black"
|
||||||
paddingLeft={2}
|
paddingLeft={2}
|
||||||
py="1"
|
|
||||||
mb="1"
|
mb="1"
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@ -297,7 +296,7 @@ const renderers = {
|
|||||||
},
|
},
|
||||||
paragraph: ({ children }) => {
|
paragraph: ({ children }) => {
|
||||||
return (
|
return (
|
||||||
<Text fontSize="1" lineHeight={'20px'}>
|
<Text fontSize="1" lineHeight="tall">
|
||||||
{children}
|
{children}
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
@ -339,7 +338,13 @@ const renderers = {
|
|||||||
},
|
},
|
||||||
link: (props) => {
|
link: (props) => {
|
||||||
return (
|
return (
|
||||||
<Anchor href={props.url} borderBottom="1" color="black" target="_blank">
|
<Anchor
|
||||||
|
display="inline"
|
||||||
|
href={props.url}
|
||||||
|
borderBottom="1"
|
||||||
|
color="black"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
</Anchor>
|
</Anchor>
|
||||||
);
|
);
|
||||||
@ -352,7 +357,7 @@ const renderers = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
'graph-mention': ({ ship }) => <Mention api={{} as any} ship={ship} />,
|
'graph-mention': ({ ship }) => <Mention api={{} as any} ship={ship} />,
|
||||||
'image': ({ url }) => (
|
image: ({ url }) => (
|
||||||
<Box mt="1" mb="2" flexShrink={0}>
|
<Box mt="1" mb="2" flexShrink={0}>
|
||||||
<RemoteContent key={url} url={url} />
|
<RemoteContent key={url} url={url} />
|
||||||
</Box>
|
</Box>
|
||||||
@ -376,15 +381,26 @@ const renderers = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
root: ({ tall, children }) =>
|
root: ({ tall, children }) =>
|
||||||
tall
|
tall ? (
|
||||||
? <Box
|
<Box
|
||||||
display='grid'
|
display="grid"
|
||||||
style={{ 'gridTemplateColumns': 'minmax(0,1fr)', 'rowGap': '1rem' }}
|
style={{ gridTemplateColumns: 'minmax(0,1fr)', rowGap: '1rem' }}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</Box>
|
</Box>
|
||||||
: <Box>{children}</Box>,
|
) : (
|
||||||
text: ({ value }) => value,
|
<Box>{children}</Box>
|
||||||
|
),
|
||||||
|
text: ({ value }) => (
|
||||||
|
<>
|
||||||
|
{value.split('\n').map((v, idx) => (
|
||||||
|
<React.Fragment key={idx}>
|
||||||
|
{idx !== 0 ? <br /> : null}
|
||||||
|
{v}
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
export function Graphdown<T extends {} = {}>(
|
export function Graphdown<T extends {} = {}>(
|
||||||
@ -400,7 +416,13 @@ export function Graphdown<T extends {} = {}>(
|
|||||||
const Renderer = renderers[ast.type] ?? (() => `unknown element: ${type}`);
|
const Renderer = renderers[ast.type] ?? (() => `unknown element: ${type}`);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Renderer transcluded={transcluded} depth={depth} {...rest} {...nodeRest} tall={tall}>
|
<Renderer
|
||||||
|
transcluded={transcluded}
|
||||||
|
depth={depth}
|
||||||
|
{...rest}
|
||||||
|
{...nodeRest}
|
||||||
|
tall={tall}
|
||||||
|
>
|
||||||
{children.map((c) => (
|
{children.map((c) => (
|
||||||
<Graphdown
|
<Graphdown
|
||||||
transcluded={transcluded}
|
transcluded={transcluded}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import remark from 'remark';
|
import remark from 'remark';
|
||||||
import RemarkDisableTokenizers from 'remark-disable-tokenizers';
|
import RemarkDisableTokenizers from 'remark-disable-tokenizers';
|
||||||
|
import RemarkBreaks from 'remark-breaks';
|
||||||
|
|
||||||
const DISABLED_BLOCK_TOKENS = [
|
const DISABLED_BLOCK_TOKENS = [
|
||||||
'indentedCode',
|
'indentedCode',
|
||||||
@ -12,7 +13,7 @@ const DISABLED_BLOCK_TOKENS = [
|
|||||||
'table',
|
'table',
|
||||||
];
|
];
|
||||||
|
|
||||||
const DISABLED_INLINE_TOKENS = ['autoLink', 'url', 'email', 'reference'];
|
const DISABLED_INLINE_TOKENS = ['autoLink', 'url', 'email', 'reference', 'html'];
|
||||||
|
|
||||||
const tallParser = remark().freeze();
|
const tallParser = remark().freeze();
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ const wideParser = remark()
|
|||||||
inline: DISABLED_INLINE_TOKENS,
|
inline: DISABLED_INLINE_TOKENS,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
RemarkBreaks,
|
||||||
])
|
])
|
||||||
.freeze();
|
.freeze();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user