1+ mod markdown;
2+
13use serde_json:: json;
24
5+ use self :: markdown:: DescriptionMarkdown ;
36use super :: text:: {
4- ProfanityKind , contains_description_spam, description_ends_with_header,
5- extract_description_blocks, extract_description_text,
6- find_banned_description_link, has_adjacent_same_level_headers,
7+ ProfanityKind , contains_description_spam, extract_description_blocks,
8+ extract_description_text, find_banned_description_link,
79 has_image_without_alt_text, has_sufficient_english_blocks,
8- js_string_length, long_header_count , non_standard_text_ratio ,
9- normalize_project_field_text , profanity_matches, project_requires_english,
10+ js_string_length, non_standard_text_ratio , normalize_project_field_text ,
11+ profanity_matches, project_requires_english,
1012} ;
1113use super :: { ProjectNag , ProjectNagKind , ProjectNagSeverity } ;
1214
@@ -19,11 +21,15 @@ const NON_STANDARD_TEXT_FAILURE_THRESHOLD: f64 = 0.05;
1921pub ( super ) fn validate ( project : & Project ) -> Vec < ProjectNag > {
2022 let mut nags = Vec :: new ( ) ;
2123 let description = project. description . as_str ( ) ;
24+ let markdown = DescriptionMarkdown :: parse ( description) ;
25+ let description_without_code = markdown. without_code ( ) ;
2226 let normalized_description = normalize_project_field_text ( description) ;
23- let text = extract_description_text ( description) ;
24- let has_spam = has_description_spam ( description) ;
25- let normalized_text = extract_description_text ( & normalized_description) ;
26- let blocks = extract_description_blocks ( description) ;
27+ let text = extract_description_text ( & description_without_code) ;
28+ let has_spam = has_description_spam ( & description_without_code) ;
29+ let normalized_text =
30+ normalize_project_field_text ( & description_without_code) ;
31+ let normalized_text = extract_description_text ( & normalized_text) ;
32+ let blocks = extract_description_blocks ( & description_without_code) ;
2733 let profanity = profanity_matches ( description) ;
2834
2935 if let Some ( matched) = profanity
@@ -51,7 +57,7 @@ pub(super) fn validate(project: &Project) -> Vec<ProjectNag> {
5157 . with_details ( json ! ( { "value" : matched. raw_text } ) ) ,
5258 ) ;
5359 }
54- if non_standard_text_ratio ( description )
60+ if non_standard_text_ratio ( & description_without_code )
5561 >= NON_STANDARD_TEXT_FAILURE_THRESHOLD
5662 {
5763 nags. push ( ProjectNag :: new (
@@ -91,7 +97,7 @@ pub(super) fn validate(project: &Project) -> Vec<ProjectNag> {
9197 ProjectNagSeverity :: Required ,
9298 ) ) ;
9399 }
94- if let Some ( url) = find_banned_description_link ( description ) {
100+ if let Some ( url) = find_banned_description_link ( & description_without_code ) {
95101 nags. push (
96102 ProjectNag :: new (
97103 ProjectNagKind :: ProjectDescriptionBannedLink ,
@@ -100,7 +106,7 @@ pub(super) fn validate(project: &Project) -> Vec<ProjectNag> {
100106 . with_details ( json ! ( { "full_url" : url } ) ) ,
101107 ) ;
102108 }
103- let long_headers = long_header_count ( description ) ;
109+ let long_headers = markdown . long_header_count ( ) ;
104110 if long_headers > 0 {
105111 nags. push (
106112 ProjectNag :: new (
@@ -110,19 +116,19 @@ pub(super) fn validate(project: &Project) -> Vec<ProjectNag> {
110116 . with_details ( json ! ( { "count" : long_headers } ) ) ,
111117 ) ;
112118 }
113- if description_ends_with_header ( description ) {
119+ if markdown . ends_with_header ( ) {
114120 nags. push ( ProjectNag :: new (
115121 ProjectNagKind :: DescriptionEndsWithHeader ,
116122 ProjectNagSeverity :: Required ,
117123 ) ) ;
118124 }
119- if has_adjacent_same_level_headers ( description ) {
125+ if markdown . has_adjacent_same_level_headers ( ) {
120126 nags. push ( ProjectNag :: new (
121127 ProjectNagKind :: AdjacentHeaders ,
122128 ProjectNagSeverity :: Required ,
123129 ) ) ;
124130 }
125- if has_image_without_alt_text ( description ) {
131+ if has_image_without_alt_text ( & description_without_code ) {
126132 nags. push ( ProjectNag :: new (
127133 ProjectNagKind :: MissingAltText ,
128134 ProjectNagSeverity :: Warning ,
@@ -133,8 +139,10 @@ pub(super) fn validate(project: &Project) -> Vec<ProjectNag> {
133139}
134140
135141pub ( super ) fn is_non_english ( project : & Project ) -> bool {
136- let text = extract_description_text ( & project. description ) ;
137- let blocks = extract_description_blocks ( & project. description ) ;
142+ let markdown = DescriptionMarkdown :: parse ( & project. description ) ;
143+ let description_without_code = markdown. without_code ( ) ;
144+ let text = extract_description_text ( & description_without_code) ;
145+ let blocks = extract_description_blocks ( & description_without_code) ;
138146 is_non_english_text ( project, & text, & blocks)
139147}
140148
0 commit comments