aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2018-06-28 13:49:36 +0100
committerNerdyPepper <[email protected]>2018-06-28 13:49:36 +0100
commitd7f9120c121f8957edd1d6c4634e584ec145bbbc (patch)
treee7650521a5439c78a767ce9977bc0a48cd2c5a7b /src
parenta5bf6b5555c42a47e4d8892748fe4452977396fd (diff)
Start formatting article
Diffstat (limited to 'src')
-rw-r--r--src/content.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/content.rs b/src/content.rs
index 585f6b2..e31531b 100644
--- a/src/content.rs
+++ b/src/content.rs
@@ -1,11 +1,15 @@
1extern crate reqwest; 1extern crate reqwest;
2extern crate serde_json; 2extern crate serde_json;
3extern crate cursive; 3extern crate cursive;
4extern crate regex;
4 5
6use cursive::theme::{ BaseColor, Color, Effect, Style };
7use cursive::utils::markup::StyledString;
5use cursive::Cursive; 8use cursive::Cursive;
6use cursive::views::Dialog; 9use cursive::views::Dialog;
7use serde_json::Value; 10use serde_json::Value;
8use reqwest::Response; 11use reqwest::Response;
12use self::regex::Regex;
9 13
10pub fn query_url_gen(title: &str) -> String { 14pub fn query_url_gen(title: &str) -> String {
11 // query config 15 // query config
@@ -61,6 +65,33 @@ pub fn get_extract(mut res: Response) -> Result<String, reqwest::Error> {
61 } 65 }
62} 66}
63 67
68pub fn extract_formatter(extract: String) -> StyledString {
69 let mut formatted = StyledString::new();
70
71 let heading= Regex::new(r"^== (?P<d>.*) ==$").unwrap();
72 let subheading= Regex::new(r"^=== (?P<d>.*) ===$").unwrap();
73
74 for line in extract.lines() {
75 if heading.is_match(line) {
76 formatted.append(
77 StyledString::styled(
78 heading.replace(line, "$d"), Effect::Bold
79 )
80 );
81 } else if subheading.is_match(line) {
82 formatted.append(
83 StyledString::styled(
84 subheading.replace(line, "$d"), Effect::Italic
85 )
86 );
87 } else {
88 formatted.append(StyledString::plain(line));
89 }
90 }
91
92 formatted
93}
94
64pub fn get_search_results(search: &str) -> Result<Vec<String>, reqwest::Error> { 95pub fn get_search_results(search: &str) -> Result<Vec<String>, reqwest::Error> {
65 let url = search_url_gen(search); 96 let url = search_url_gen(search);
66 let mut res = reqwest::get(&url[..])?; 97 let mut res = reqwest::get(&url[..])?;