Messaging: Don't embed URLs in code.
This commit is contained in:
@@ -4,6 +4,7 @@ use crate::util::{
|
|||||||
};
|
};
|
||||||
use linkify::{LinkFinder, LinkKind};
|
use linkify::{LinkFinder, LinkKind};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub enum ImageSize {
|
pub enum ImageSize {
|
||||||
@@ -97,10 +98,17 @@ pub enum Embed {
|
|||||||
|
|
||||||
impl Embed {
|
impl Embed {
|
||||||
pub async fn generate(content: String) -> Result<Vec<Embed>> {
|
pub async fn generate(content: String) -> Result<Vec<Embed>> {
|
||||||
|
lazy_static! {
|
||||||
|
static ref RE_CODE: Regex = Regex::new("```(?:.|\n)+?```|`(?:.|\n)+?`").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore code blocks.
|
||||||
|
let content = RE_CODE.replace_all(&content, "");
|
||||||
|
|
||||||
let content = content
|
let content = content
|
||||||
|
// Ignore quoted lines.
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
// Ignore quoted lines.
|
|
||||||
if let Some(c) = v.chars().next() {
|
if let Some(c) = v.chars().next() {
|
||||||
if c == '>' {
|
if c == '>' {
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
Reference in New Issue
Block a user