mirror of
https://github.com/youwen5/iamb.git
synced 2025-08-04 03:28:28 -07:00
Recognise URLs in plain text message bodies (#476)
This commit is contained in:
parent
34d3b844af
commit
ec88f4441e
5 changed files with 29 additions and 6 deletions
|
@ -524,11 +524,11 @@ impl StyleTree {
|
|||
}
|
||||
|
||||
pub struct TreeGenState {
|
||||
link_num: u8,
|
||||
pub link_num: u8,
|
||||
}
|
||||
|
||||
impl TreeGenState {
|
||||
fn next_link_char(&mut self) -> Option<char> {
|
||||
pub fn next_link_char(&mut self) -> Option<char> {
|
||||
let num = self.link_num;
|
||||
|
||||
if num < 62 {
|
||||
|
|
|
@ -72,6 +72,7 @@ mod state;
|
|||
|
||||
pub use self::compose::text_to_message;
|
||||
use self::state::{body_cow_state, html_state};
|
||||
pub use html::TreeGenState;
|
||||
|
||||
type ProtocolPreview<'a> = (&'a Protocol, u16, u16);
|
||||
|
||||
|
|
|
@ -86,7 +86,14 @@ use crate::base::{
|
|||
SendAction,
|
||||
};
|
||||
|
||||
use crate::message::{text_to_message, Message, MessageEvent, MessageKey, MessageTimeStamp};
|
||||
use crate::message::{
|
||||
text_to_message,
|
||||
Message,
|
||||
MessageEvent,
|
||||
MessageKey,
|
||||
MessageTimeStamp,
|
||||
TreeGenState,
|
||||
};
|
||||
use crate::worker::Requester;
|
||||
|
||||
use super::scrollback::{Scrollback, ScrollbackState};
|
||||
|
@ -226,10 +233,14 @@ impl ChatState {
|
|||
|
||||
let links = if let Some(html) = &msg.html {
|
||||
html.get_links()
|
||||
} else if let Ok(url) = Url::parse(&msg.event.body()) {
|
||||
vec![('0', url)]
|
||||
} else {
|
||||
vec![]
|
||||
linkify::LinkFinder::new()
|
||||
.links(&msg.event.body())
|
||||
.filter_map(|u| Url::parse(u.as_str()).ok())
|
||||
.scan(TreeGenState { link_num: 0 }, |state, u| {
|
||||
state.next_link_char().map(|c| (c, u))
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
|
||||
if links.is_empty() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue