|
1 | 1 | //! Leetcode data modelsA |
2 | 2 | use colored::Colorize; |
3 | 3 | use serde::{Serialize, Deserialize}; |
4 | | -pub use self::question::*; |
5 | 4 | use super::schemas::problems; |
| 5 | +use crate::helper::HTML; |
| 6 | +pub use self::question::*; |
6 | 7 |
|
7 | 8 | /// Problem model |
8 | 9 | #[derive(AsChangeset, Clone, Identifiable, Insertable, Queryable, Serialize, Debug)] |
@@ -104,66 +105,9 @@ pub struct Question { |
104 | 105 | pub t_content: String, |
105 | 106 | } |
106 | 107 |
|
107 | | -/// ## Convert table |
108 | | -/// "<" -> "<" |
109 | | -/// ">" -> ">" |
110 | | -/// "&" -> "&" |
111 | | -/// """ -> "\"" |
112 | | -/// "©" -> © |
113 | 108 | impl std::fmt::Display for Question { |
114 | 109 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
115 | | - let mut content = (&self.content).replace(r#"\t"#, "").normal(); |
116 | | - |
117 | | - // empty characters |
118 | | - for i in vec![ |
119 | | - r#"\n"#, r#"\r"#, |
120 | | - r#"<p>"#, r#"</p>"#, |
121 | | - r#"<pre>"#, r#"</pre>"#, |
122 | | - r#"<div>"#, r#"</div>"#, |
123 | | - r#"</span>"#, |
124 | | - ] { |
125 | | - content = content.replace(i, "").normal(); |
126 | | - } |
127 | | - |
128 | | - // delete <span...> |
129 | | - { |
130 | | - let mut ptr = 0; |
131 | | - let mut output: Vec<&str> = vec![]; |
132 | | - let mut style = ""; |
133 | | - for (i, e) in content.chars().enumerate() { |
134 | | - match e { |
135 | | - '<' => { |
136 | | - output.push(&content[ptr..i]); |
137 | | - ptr = i; |
138 | | - }, |
139 | | - '>' => { |
140 | | - ptr = i + 1; |
141 | | - }, |
142 | | - _ => {}, |
143 | | - } |
144 | | - }; |
145 | | - output.push(&content[ptr..content.len()]); |
146 | | - content = output.join("").normal(); |
147 | | - } |
148 | | - |
149 | | - // converting symbols |
150 | | - content = content.replace(r#"<"#, "<").normal(); |
151 | | - content = content.replace(r#">"#, ">").normal(); |
152 | | - content = content.replace(r#"&"#, "&").normal(); |
153 | | - content = content.replace(r#"""#, "\"").normal(); |
154 | | - content = content.replace(r#" "#, " ").normal(); |
155 | | - |
156 | | - // decorates |
157 | | - // loop { |
158 | | - // let mut tmp = &mut content; |
159 | | - // if let Some(start) = tmp.find("<b>") { |
160 | | - // tmp.insert(start, ','); |
161 | | - // tmp = &mut tmp[(start + 4)..].to_string(); |
162 | | - // } else { |
163 | | - // break; |
164 | | - // } |
165 | | - // } |
166 | | - write!(f, "{}", &content) |
| 110 | + write!(f, "{}", &self.content.render()) |
167 | 111 | } |
168 | 112 | } |
169 | 113 |
|
|
0 commit comments