Allow hashtags to be followed by colon or question mark
This commit is contained in:
parent
3f0b99de46
commit
0a988b5439
1 changed files with 8 additions and 4 deletions
|
@ -4,7 +4,7 @@ use crate::errors::ValidationError;
|
||||||
use crate::frontend::get_tag_page_url;
|
use crate::frontend::get_tag_page_url;
|
||||||
|
|
||||||
const HASHTAG_RE: &str = r"(?m)(?P<before>^|\s)#(?P<tag>\S+)";
|
const HASHTAG_RE: &str = r"(?m)(?P<before>^|\s)#(?P<tag>\S+)";
|
||||||
const HASHTAG_SECONDARY_RE: &str = r"^(?P<tag>[0-9A-Za-z]+)(?P<after>(\.|<br>|\.<br>)?)$";
|
const HASHTAG_SECONDARY_RE: &str = r"^(?P<tag>[0-9A-Za-z]+)(?P<after>[\.:?]?(<br>)?)$";
|
||||||
const HASHTAG_NAME_RE: &str = r"^\w+$";
|
const HASHTAG_NAME_RE: &str = r"^\w+$";
|
||||||
|
|
||||||
/// Finds anything that looks like a hashtag
|
/// Finds anything that looks like a hashtag
|
||||||
|
@ -69,7 +69,8 @@ mod tests {
|
||||||
let text = concat!(
|
let text = concat!(
|
||||||
"@user1@server1 some text #TestTag.\n",
|
"@user1@server1 some text #TestTag.\n",
|
||||||
"#TAG1 #tag1 #test_underscore #test*special ",
|
"#TAG1 #tag1 #test_underscore #test*special ",
|
||||||
"more text #tag2",
|
"more text #tag2:<br>\n",
|
||||||
|
"end with #tag3",
|
||||||
);
|
);
|
||||||
let tags = find_tags(text);
|
let tags = find_tags(text);
|
||||||
|
|
||||||
|
@ -77,6 +78,7 @@ mod tests {
|
||||||
"testtag",
|
"testtag",
|
||||||
"tag1",
|
"tag1",
|
||||||
"tag2",
|
"tag2",
|
||||||
|
"tag3",
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +87,8 @@ mod tests {
|
||||||
let text = concat!(
|
let text = concat!(
|
||||||
"@user1@server1 some text #TestTag.\n",
|
"@user1@server1 some text #TestTag.\n",
|
||||||
"#TAG1 #tag1 #test_underscore #test*special ",
|
"#TAG1 #tag1 #test_underscore #test*special ",
|
||||||
"more text #tag2",
|
"more text #tag2:<br>\n",
|
||||||
|
"end with #tag3",
|
||||||
);
|
);
|
||||||
let tags = find_tags(text);
|
let tags = find_tags(text);
|
||||||
let output = replace_tags(INSTANCE_URL, &text, &tags);
|
let output = replace_tags(INSTANCE_URL, &text, &tags);
|
||||||
|
@ -94,7 +97,8 @@ mod tests {
|
||||||
r#"@user1@server1 some text <a class="hashtag" href="https://example.com/tag/testtag">#TestTag</a>."#, "\n",
|
r#"@user1@server1 some text <a class="hashtag" href="https://example.com/tag/testtag">#TestTag</a>."#, "\n",
|
||||||
r#"<a class="hashtag" href="https://example.com/tag/tag1">#TAG1</a> <a class="hashtag" href="https://example.com/tag/tag1">#tag1</a> "#,
|
r#"<a class="hashtag" href="https://example.com/tag/tag1">#TAG1</a> <a class="hashtag" href="https://example.com/tag/tag1">#tag1</a> "#,
|
||||||
r#"#test_underscore #test*special "#,
|
r#"#test_underscore #test*special "#,
|
||||||
r#"more text <a class="hashtag" href="https://example.com/tag/tag2">#tag2</a>"#,
|
r#"more text <a class="hashtag" href="https://example.com/tag/tag2">#tag2</a>:<br>"#, "\n",
|
||||||
|
r#"end with <a class="hashtag" href="https://example.com/tag/tag3">#tag3</a>"#,
|
||||||
);
|
);
|
||||||
assert_eq!(output, expected_output);
|
assert_eq!(output, expected_output);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue