@apify/ui-library 0.81.2-fixsimplemarkdownmargin-d4806f.2 → 0.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/code/code_block/code_block.js +1 -1
- package/dist/src/components/code/code_block/code_block.js.map +1 -1
- package/dist/src/components/code/prism_highlighter.d.ts.map +1 -1
- package/dist/src/components/code/prism_highlighter.js +36 -3
- package/dist/src/components/code/prism_highlighter.js.map +1 -1
- package/dist/src/components/simple_markdown/simple_markdown.d.ts.map +1 -1
- package/dist/src/components/simple_markdown/simple_markdown.js +15 -13
- package/dist/src/components/simple_markdown/simple_markdown.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/code/code_block/code_block.tsx +1 -1
- package/src/components/code/prism_highlighter.tsx +38 -3
- package/src/components/simple_markdown/simple_markdown.tsx +15 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apify/ui-library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.82.0",
|
|
4
4
|
"description": "React UI library used by apify.com",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@types/react": "^18.2.74",
|
|
59
59
|
"@types/styled-components": "^5.1.34",
|
|
60
60
|
"eslint-plugin-react": "^7.32.2",
|
|
61
|
-
"eslint-plugin-react-hooks": "^
|
|
61
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
62
62
|
"eslint-plugin-sonarjs": "^1.0.3",
|
|
63
63
|
"recast": "^0.23.9",
|
|
64
64
|
"style-dictionary": "^4.4.0",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"src",
|
|
70
70
|
"style"
|
|
71
71
|
],
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "785557421fddb4de7a2dfcc66d0bfa1018d1327e"
|
|
73
73
|
}
|
|
@@ -202,7 +202,7 @@ export const CodeBlock = ({
|
|
|
202
202
|
code={currentCode}
|
|
203
203
|
linePrefixes={linePrefixes}
|
|
204
204
|
highlightLines={currentHighlightLines}
|
|
205
|
-
language={currentLanguage
|
|
205
|
+
language={currentLanguage}
|
|
206
206
|
size={size}
|
|
207
207
|
ref={syntaxHighlighterRef}
|
|
208
208
|
isSingleLine={false}
|
|
@@ -3,7 +3,7 @@ import _ from 'lodash';
|
|
|
3
3
|
import type { HighlightProps } from 'prism-react-renderer';
|
|
4
4
|
import { Highlight, Prism, themes } from 'prism-react-renderer';
|
|
5
5
|
import type { ReactNode } from 'react';
|
|
6
|
-
import { forwardRef, useRef } from 'react';
|
|
6
|
+
import { forwardRef, useMemo, useRef } from 'react';
|
|
7
7
|
import styled, { css } from 'styled-components';
|
|
8
8
|
|
|
9
9
|
import { theme } from '../../design_system/theme.js';
|
|
@@ -46,6 +46,39 @@ const loadLanguages = async () => {
|
|
|
46
46
|
|
|
47
47
|
void loadLanguages();
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Detects the language of the code based on common keywords. We need it for user-generated content
|
|
51
|
+
* @param code The code to analyze.
|
|
52
|
+
*/
|
|
53
|
+
const useDetectedLanguage = (code: string, passedLanguage?: string) => useMemo(() => {
|
|
54
|
+
if (passedLanguage) return passedLanguage;
|
|
55
|
+
const tests = [
|
|
56
|
+
{ lang: 'rust', keywords: ['fn main()', 'let mut', 'println!', 'pub struct', 'use std::'] },
|
|
57
|
+
{ lang: 'http', keywords: ['GET /', 'POST /', 'HTTP/1.1', 'Host:', 'Content-Type:'] },
|
|
58
|
+
{ lang: 'bash', keywords: ['#!/bin/bash', 'echo ', 'cd ', 'ls'] },
|
|
59
|
+
{ lang: 'markup', keywords: ['<div', '<span', '<html', '<!DOCTYPE', '</'] },
|
|
60
|
+
{ lang: 'xml-doc', keywords: ['<?xml', '<doc', '<summary', '</doc>'] },
|
|
61
|
+
{ lang: 'yaml', keywords: ['version:', 'services:', 'name:'] },
|
|
62
|
+
{ lang: 'docker', keywords: ['FROM ', 'RUN ', 'CMD ', 'ENTRYPOINT', 'EXPOSE'] },
|
|
63
|
+
{ lang: 'python', keywords: ['def ', 'import ', 'print(', 'self', 'None'] },
|
|
64
|
+
{ lang: 'javascript', keywords: ['function', 'const', 'let', '=>', 'console.log', 'var'] },
|
|
65
|
+
{ lang: 'typescript', keywords: ['interface ', 'type ', ': string', ': number', 'as const'] },
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const scored = tests.map((test) => {
|
|
69
|
+
let score = 0;
|
|
70
|
+
for (const kw of test.keywords) {
|
|
71
|
+
if (code.includes(kw)) score += 1;
|
|
72
|
+
}
|
|
73
|
+
return { lang: test.lang, score };
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const max = _.maxBy(scored, 'score');
|
|
77
|
+
|
|
78
|
+
if (max?.score && max.score > 0) return max.lang;
|
|
79
|
+
return undefined;
|
|
80
|
+
}, [code, passedLanguage]);
|
|
81
|
+
|
|
49
82
|
type PreWrapperProps = {
|
|
50
83
|
$hasLinePrefixes: boolean,
|
|
51
84
|
$isSingleLine: boolean
|
|
@@ -146,7 +179,7 @@ export const PrismSyntaxHighlighter = forwardRef<HTMLPreElement, SyntaxHighlight
|
|
|
146
179
|
size = 'regular',
|
|
147
180
|
linePrefixes = {},
|
|
148
181
|
highlightLines = [],
|
|
149
|
-
language
|
|
182
|
+
language,
|
|
150
183
|
className,
|
|
151
184
|
isSingleLine,
|
|
152
185
|
...rest
|
|
@@ -155,10 +188,12 @@ export const PrismSyntaxHighlighter = forwardRef<HTMLPreElement, SyntaxHighlight
|
|
|
155
188
|
const hasLinePrefixes = !_.isEmpty(linePrefixes);
|
|
156
189
|
const highlightedLinesObject = useRef<Record<number, boolean>>(Object.fromEntries(highlightLines.map((e) => [e, true])));
|
|
157
190
|
|
|
191
|
+
const effectiveLanguage = useDetectedLanguage(rest.code || '', language) ?? 'javascript';
|
|
192
|
+
|
|
158
193
|
return (
|
|
159
194
|
<Highlight
|
|
160
195
|
theme={uiTheme === 'DARK' ? themes.nightOwl : themes.oneLight}
|
|
161
|
-
language={
|
|
196
|
+
language={effectiveLanguage}
|
|
162
197
|
{...rest}
|
|
163
198
|
>
|
|
164
199
|
{({ className: prismClassName, tokens, getLineProps, getTokenProps }) => (
|
|
@@ -15,7 +15,9 @@ import { useSharedUiDependencies } from '../../ui_dependency_provider.js';
|
|
|
15
15
|
import { Box } from '../box.js';
|
|
16
16
|
import { isUrlExternal } from '../link.js';
|
|
17
17
|
import { cleanMarkdown } from '../readme_renderer/utils.js';
|
|
18
|
-
import {
|
|
18
|
+
import { HeadingContent } from '../text/heading_content.js';
|
|
19
|
+
import { Heading, Text } from '../text/index.js';
|
|
20
|
+
import { TextContent } from '../text/text_content.js';
|
|
19
21
|
import {
|
|
20
22
|
MarkdownBlockQuote,
|
|
21
23
|
MarkdownCode,
|
|
@@ -110,12 +112,12 @@ export const defaultRemarkPlugins = [remarkGfm];
|
|
|
110
112
|
|
|
111
113
|
// TODO: Add Image component
|
|
112
114
|
const regularMarkdownSizeComponents: Components = {
|
|
113
|
-
h1: ({ children }) => <HeadingContent mb='space16' type='heading1'>{children}</HeadingContent>,
|
|
114
|
-
h2: ({ children }) => <HeadingContent mb='space16' type='heading2'>{children}</HeadingContent>,
|
|
115
|
-
h3: ({ children }) => <HeadingContent mb='space16' type='heading3'>{children}</HeadingContent>,
|
|
116
|
-
h4: ({ children }) => <HeadingContent mb='space16' type='heading4'>{children}</HeadingContent>,
|
|
117
|
-
h5: ({ children }) => <HeadingContent mb='space16' type='heading5'>{children}</HeadingContent>,
|
|
118
|
-
h6: ({ children }) => <HeadingContent mb='space16' type='heading6'>{children}</HeadingContent>,
|
|
115
|
+
h1: ({ children }) => <HeadingContent mt='space32' mb='space16' type='heading1'>{children}</HeadingContent>,
|
|
116
|
+
h2: ({ children }) => <HeadingContent mt='space32' mb='space16' type='heading2'>{children}</HeadingContent>,
|
|
117
|
+
h3: ({ children }) => <HeadingContent mt='space32' mb='space16' type='heading3'>{children}</HeadingContent>,
|
|
118
|
+
h4: ({ children }) => <HeadingContent mt='space32' mb='space16' type='heading4'>{children}</HeadingContent>,
|
|
119
|
+
h5: ({ children }) => <HeadingContent mt='space32' mb='space16' type='heading5'>{children}</HeadingContent>,
|
|
120
|
+
h6: ({ children }) => <HeadingContent mt='space32' mb='space16' type='heading6'>{children}</HeadingContent>,
|
|
119
121
|
p: ({ children }) => (<TextContent my='space16'>{children}</TextContent>),
|
|
120
122
|
strong: ({ children }) => <TextContent as='strong' weight='bold'>{children}</TextContent>,
|
|
121
123
|
b: ({ children }) => <TextContent as='b' weight='bold'>{children}</TextContent>,
|
|
@@ -130,12 +132,12 @@ const regularMarkdownSizeComponents: Components = {
|
|
|
130
132
|
};
|
|
131
133
|
|
|
132
134
|
const smallMarkdownSizeComponents: Components = {
|
|
133
|
-
h1: ({ children }) => <Heading mb='space16' type='title2xl'>{children}</Heading>,
|
|
134
|
-
h2: ({ children }) => <Heading mb='space16' type='titleXl'>{children}</Heading>,
|
|
135
|
-
h3: ({ children }) => <Heading mb='space16' type='titleL'>{children}</Heading>,
|
|
136
|
-
h4: ({ children }) => <Heading mb='space16' type='titleM'>{children}</Heading>,
|
|
137
|
-
h5: ({ children }) => <Heading mb='space16' type='titleS'>{children}</Heading>,
|
|
138
|
-
h6: ({ children }) => <Heading mb='space16' type='titleXs'>{children}</Heading>,
|
|
135
|
+
h1: ({ children }) => <Heading mt='space32' mb='space16' type='title2xl'>{children}</Heading>,
|
|
136
|
+
h2: ({ children }) => <Heading mt='space32' mb='space16' type='titleXl'>{children}</Heading>,
|
|
137
|
+
h3: ({ children }) => <Heading mt='space32' mb='space16' type='titleL'>{children}</Heading>,
|
|
138
|
+
h4: ({ children }) => <Heading mt='space32' mb='space16' type='titleM'>{children}</Heading>,
|
|
139
|
+
h5: ({ children }) => <Heading mt='space32' mb='space16' type='titleS'>{children}</Heading>,
|
|
140
|
+
h6: ({ children }) => <Heading mt='space32' mb='space16' type='titleXs'>{children}</Heading>,
|
|
139
141
|
p: ({ children }) => (<Text my='space16'>{children}</Text>),
|
|
140
142
|
strong: ({ children }) => <Text as='strong' weight='bold'>{children}</Text>,
|
|
141
143
|
b: ({ children }) => <Text as='b' weight='bold'>{children}</Text>,
|