-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Feat: parse page title when paste a link #1344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| const { response } = req | ||
| if (typeof response === 'string') { | ||
| const match = response.match(/<title>(.*)<\/title>/) | ||
| return match[1] ? settle(match[1]) : settle('') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jocs I think we should escape the title using DOMPurify to prevent possible XSS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW we should check if the array contains at least one title (length >= 2). I don't know what JS does if the index is out of bounds due missing title.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW we should check if the array contains at least one title (length >= 2). I don't know what JS does if the index is out of bounds due missing title.
it will always have match[1] if the match is not null.
One html page will have more than one title ? as far as I can see, html will only has one title.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a missing match && match[1] or match && match.length >= 2 check. Otherwise an exception is thrown or segfault.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fxha I'll make a PR to solve later.
| const span = document.createElement('span') | ||
| span.innerHTML = text | ||
| link.replaceWith(span) | ||
| const title = await getPageTitle(href) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jocs Does this may cause problems when typing other stuff and getPageTitle take a long time or times out? Or is the editor block for this time?
E.g.
- Paste text with link in it
getPageTitlehttp request (async)- User: type random words
- http request (not) successful
- ???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does not be blocked, but it maybe take some time to request the page title, I set a timeout of 1.5 s, but it shouldn't be perfect. It's better to insert the link first, and then insert the anchor text (title content) after the title is obtained.
I will optimize before the 1.6 release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does not be blocked, but it maybe take some time to request the page title, I set a timeout of 1.5 s, but it shouldn't be perfect. It's better to insert the link first, and then insert the anchor text (title content) after the title is obtained.
I will optimize before the 1.6 release.
Description
Copy url link from browser address bar, and parse the page title as anchor text. for example:
Copy
https://element.eleme.cn/#/zh-CN/component/tabsfrom browser address bar, and paste to Mark Text, it will looks like this 组件|Element--
Please, don't submit
/distfiles with your PR!This change is