forked from realaravinth/libmedium
chore: linting
This commit is contained in:
parent
d4f73dd425
commit
3343b698aa
3 changed files with 19 additions and 31 deletions
2
build.rs
2
build.rs
|
@ -18,7 +18,7 @@ use std::process::Command;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let output = Command::new("git")
|
let output = Command::new("git")
|
||||||
.args(&["rev-parse", "HEAD"])
|
.args(["rev-parse", "HEAD"])
|
||||||
.output()
|
.output()
|
||||||
.expect("error in git command, is git installed?");
|
.expect("error in git command, is git installed?");
|
||||||
let git_hash = String::from_utf8(output.stdout).unwrap();
|
let git_hash = String::from_utf8(output.stdout).unwrap();
|
||||||
|
|
42
src/post.rs
42
src/post.rs
|
@ -14,7 +14,7 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
use std::{collections::HashMap, hash::Hash};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::data::*;
|
use crate::data::*;
|
||||||
use crate::proxy::StringUtils;
|
use crate::proxy::StringUtils;
|
||||||
|
@ -26,20 +26,12 @@ enum PostitionType {
|
||||||
End,
|
End,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Eq, PartialEq)]
|
||||||
struct ListState {
|
struct ListState {
|
||||||
in_uli: bool,
|
in_uli: bool,
|
||||||
in_oli: bool,
|
in_oli: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ListState {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
in_uli: false,
|
|
||||||
in_oli: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Markup<'a, 'b> {
|
struct Markup<'a, 'b> {
|
||||||
markup: &'a GetPostPostContentBodyModelParagraphsMarkups,
|
markup: &'a GetPostPostContentBodyModelParagraphsMarkups,
|
||||||
p: &'a GetPostPostContentBodyModelParagraphs,
|
p: &'a GetPostPostContentBodyModelParagraphs,
|
||||||
|
@ -233,22 +225,18 @@ impl<'a, 'b> Markup<'a, 'b> {
|
||||||
p: &GetPostPostContentBodyModelParagraphs,
|
p: &GetPostPostContentBodyModelParagraphs,
|
||||||
state: &mut ListState,
|
state: &mut ListState,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
if state.in_oli {
|
if state.in_oli && p.type_ != "OLI" {
|
||||||
if p.type_ != "OLI" {
|
|
||||||
state.in_oli = false;
|
state.in_oli = false;
|
||||||
return Some(format!("</ol>"));
|
return Some("</ol>".to_string());
|
||||||
}
|
|
||||||
};
|
};
|
||||||
if state.in_uli {
|
if state.in_uli && p.type_ != "ULI" {
|
||||||
if p.type_ != "ULI" {
|
|
||||||
state.in_uli = false;
|
state.in_uli = false;
|
||||||
return Some(format!("</ul>"));
|
return Some("</ul>".to_string());
|
||||||
}
|
|
||||||
};
|
};
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_markup(&self, pindex: usize) -> String {
|
fn apply_markup(&self, _pindex: usize) -> String {
|
||||||
if self.markup.type_ == "A" {
|
if self.markup.type_ == "A" {
|
||||||
if let Some(anchor_type) = &self.markup.anchor_type {
|
if let Some(anchor_type) = &self.markup.anchor_type {
|
||||||
if anchor_type == "LINK" {
|
if anchor_type == "LINK" {
|
||||||
|
@ -351,9 +339,9 @@ impl<'a, 'b> PositionMap<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_markup<'b>(
|
pub fn apply_markup(
|
||||||
data: &PostResp,
|
data: &PostResp,
|
||||||
gists: &'b Option<Vec<(String, crate::data::GistContent)>>,
|
gists: &Option<Vec<(String, crate::data::GistContent)>>,
|
||||||
) -> Vec<String> {
|
) -> Vec<String> {
|
||||||
let mut paragraphs: Vec<String> = Vec::with_capacity(data.content.body_model.paragraphs.len());
|
let mut paragraphs: Vec<String> = Vec::with_capacity(data.content.body_model.paragraphs.len());
|
||||||
let mut state = ListState::default();
|
let mut state = ListState::default();
|
||||||
|
@ -365,14 +353,14 @@ pub fn apply_markup<'b>(
|
||||||
}
|
}
|
||||||
for m in p.markups.iter() {
|
for m in p.markups.iter() {
|
||||||
let start_markup = Markup {
|
let start_markup = Markup {
|
||||||
markup: &m,
|
markup: m,
|
||||||
p,
|
p,
|
||||||
gists,
|
gists,
|
||||||
pos_type: PostitionType::Start,
|
pos_type: PostitionType::Start,
|
||||||
};
|
};
|
||||||
pos.insert_if_not_exists(m.start, start_markup);
|
pos.insert_if_not_exists(m.start, start_markup);
|
||||||
let end_markup = Markup {
|
let end_markup = Markup {
|
||||||
markup: &m,
|
markup: m,
|
||||||
p,
|
p,
|
||||||
gists,
|
gists,
|
||||||
pos_type: PostitionType::End,
|
pos_type: PostitionType::End,
|
||||||
|
@ -395,9 +383,9 @@ pub fn apply_markup<'b>(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut content = String::with_capacity(p.text.len());
|
let mut content = String::with_capacity(p.text.len());
|
||||||
content += &Markup::start(&p, &gists, pindex, &mut state);
|
content += &Markup::start(p, gists, pindex, &mut state);
|
||||||
pos.arr.sort();
|
pos.arr.sort();
|
||||||
if let Some(first) = pos.arr.get(0) {
|
if let Some(first) = pos.arr.first() {
|
||||||
//content += p.text.substring(cur, *first as usize);
|
//content += p.text.substring(cur, *first as usize);
|
||||||
content += p.text.slice(cur..*first as usize);
|
content += p.text.slice(cur..*first as usize);
|
||||||
cur = incr_cur(cur, *first);
|
cur = incr_cur(cur, *first);
|
||||||
|
@ -418,11 +406,11 @@ pub fn apply_markup<'b>(
|
||||||
}
|
}
|
||||||
log::debug!("LAST");
|
log::debug!("LAST");
|
||||||
content += p.text.slice(cur..);
|
content += p.text.slice(cur..);
|
||||||
content += &Markup::end(&p, pindex, &mut state);
|
content += &Markup::end(p, pindex, &mut state);
|
||||||
} else {
|
} else {
|
||||||
log::debug!("LAST WITH NO MARKUP");
|
log::debug!("LAST WITH NO MARKUP");
|
||||||
content += p.text.slice(cur..);
|
content += p.text.slice(cur..);
|
||||||
content += &Markup::end(&p, pindex, &mut state);
|
content += &Markup::end(p, pindex, &mut state);
|
||||||
}
|
}
|
||||||
paragraphs.push(content);
|
paragraphs.push(content);
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl Settings {
|
||||||
let cache_path = settings.cache.as_ref().unwrap();
|
let cache_path = settings.cache.as_ref().unwrap();
|
||||||
let cache_path = Path::new(&cache_path);
|
let cache_path = Path::new(&cache_path);
|
||||||
if !cache_path.exists() {
|
if !cache_path.exists() {
|
||||||
fs::create_dir(&cache_path).unwrap();
|
fs::create_dir(cache_path).unwrap();
|
||||||
}
|
}
|
||||||
if !cache_path.is_dir() {
|
if !cache_path.is_dir() {
|
||||||
panic!(
|
panic!(
|
||||||
|
|
Loading…
Reference in a new issue