mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
add alternative bold tags
This commit is contained in:
parent
3bdabbe1b8
commit
416c0ac434
1 changed files with 12 additions and 6 deletions
|
|
@ -5,7 +5,7 @@ use gtk::{
|
||||||
};
|
};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
const REGEX_BOLD: &str = r"\*\*(?P<text>[^\*]*)\*\*";
|
const REGEX_BOLD: &str = r"(\*\*|__)(?P<text>[^\*_]*)(\*\*|__)";
|
||||||
|
|
||||||
pub struct Bold(TextTag);
|
pub struct Bold(TextTag);
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ pub fn strip_tags(value: &str) -> String {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_strip_tags() {
|
fn test_strip_tags() {
|
||||||
const VALUE: &str = r"Some **bold 1** and **bold 2** with ";
|
const VALUE: &str = "Some **bold 1** and **bold 2** and __bold 3__ and *italic 1* and _italic 2_ with ";
|
||||||
let mut result = String::from(VALUE);
|
let mut result = String::from(VALUE);
|
||||||
for cap in Regex::new(REGEX_BOLD).unwrap().captures_iter(VALUE) {
|
for cap in Regex::new(REGEX_BOLD).unwrap().captures_iter(VALUE) {
|
||||||
if let Some(m) = cap.get(0) {
|
if let Some(m) = cap.get(0) {
|
||||||
|
|
@ -81,7 +81,7 @@ fn test_strip_tags() {
|
||||||
}
|
}
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result,
|
result,
|
||||||
"Some bold 1 and bold 2 with "
|
"Some bold 1 and bold 2 and bold 3 and *italic 1* and _italic 2_ with "
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,9 +89,15 @@ fn test_strip_tags() {
|
||||||
fn test_regex() {
|
fn test_regex() {
|
||||||
let cap: Vec<_> = Regex::new(REGEX_BOLD)
|
let cap: Vec<_> = Regex::new(REGEX_BOLD)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.captures_iter(r"Some **bold 1** and **bold 2** with ")
|
.captures_iter(
|
||||||
|
"Some **bold 1** and **bold 2** and __bold 3__ and *italic 1* and _italic 2_ with "
|
||||||
|
)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
assert_eq!(&cap.first().unwrap()["text"], "bold 1");
|
assert_eq!(cap.len(), 3);
|
||||||
assert_eq!(&cap.get(1).unwrap()["text"], "bold 2");
|
|
||||||
|
let mut c = cap.into_iter();
|
||||||
|
assert_eq!(&c.next().unwrap()["text"], "bold 1");
|
||||||
|
assert_eq!(&c.next().unwrap()["text"], "bold 2");
|
||||||
|
assert_eq!(&c.next().unwrap()["text"], "bold 3");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue