mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore(html): revert baded72 and use existing linkifyText (#36328)
This commit is contained in:
parent
90c6921318
commit
114c9c0452
@ -20,9 +20,10 @@ import './colors.css';
|
||||
import './common.css';
|
||||
import './headerView.css';
|
||||
import * as icons from './icons';
|
||||
import { Link, LinkifyText, navigate, SearchParamsContext } from './links';
|
||||
import { Link, navigate, SearchParamsContext } from './links';
|
||||
import { statusIcon } from './statusIcon';
|
||||
import { filterWithToken } from './filter';
|
||||
import { linkifyText } from '@web/renderUtils';
|
||||
|
||||
export const HeaderView: React.FC<{
|
||||
title: string | undefined,
|
||||
@ -35,7 +36,7 @@ export const HeaderView: React.FC<{
|
||||
<div style={{ flex: 'auto' }}></div>
|
||||
{rightSuperHeader}
|
||||
</div>
|
||||
{title && <div className='header-title'><LinkifyText text={title} /></div>}
|
||||
{title && <div className='header-title'>{linkifyText(title)}</div>}
|
||||
</div>;
|
||||
};
|
||||
|
||||
|
@ -114,41 +114,6 @@ export const SearchParamsProvider: React.FunctionComponent<React.PropsWithChildr
|
||||
return <SearchParamsContext.Provider value={searchParams}>{children}</SearchParamsContext.Provider>;
|
||||
};
|
||||
|
||||
const LINKIFY_REGEX = /https?:\/\/[^\s]+/g;
|
||||
|
||||
export const LinkifyText: React.FunctionComponent<{ text: string }> = ({ text }) => {
|
||||
const parts = React.useMemo(() => {
|
||||
const matches = [...text.matchAll(LINKIFY_REGEX)];
|
||||
if (matches.length === 0)
|
||||
return [text];
|
||||
const result: Array<React.ReactElement | string> = [];
|
||||
let lastIndex = 0;
|
||||
|
||||
for (const match of matches) {
|
||||
const url = match[0];
|
||||
const startIndex = match.index!;
|
||||
|
||||
// Add text before the URL
|
||||
if (startIndex > lastIndex)
|
||||
result.push(text.slice(lastIndex, startIndex));
|
||||
result.push(
|
||||
<a key={startIndex} href={url} target='_blank' rel='noopener noreferrer'>
|
||||
{url}
|
||||
</a>
|
||||
);
|
||||
|
||||
lastIndex = startIndex + url.length;
|
||||
}
|
||||
|
||||
// Add any text after the last URL
|
||||
if (lastIndex < text.length)
|
||||
result.push(text.slice(lastIndex));
|
||||
return result;
|
||||
}, [text]);
|
||||
|
||||
return <>{parts}</>;
|
||||
};
|
||||
|
||||
function downloadFileNameForAttachment(attachment: TestAttachment): string {
|
||||
if (attachment.name.includes('.') || !attachment.path)
|
||||
return attachment.name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user