Finish gemtext parsing implementation

[?]
Jan 13, 2021, 3:24 AM
Y55SCAUN3MQCMRGJQBBMICEO6ARTGICWGGZYA7VB6ZRPK6US4B5AC

Dependencies

  • [2] JBZGFYVO Add nom parsers for main types
  • [3] K37J3USB Add WIP gemtext parsers
  • [4] J4PKMKJX Add root doc comment, gemtext module
  • [5] FR4RRLIK Make comment more descriptive
  • [*] 5II6T7YE Add gemini library

Change contents

  • edit in gemini/src/lib.rs at line 70
    [2.3370]
    [2.3370]
    pub use gemtext::parse_gemtext;
  • replacement in gemini/src/gemtext.rs at line 38
    [4.1717][4.1717:1743]()
    Preformatted(String),
    [4.1717]
    [4.1743]
    Preformatted {
    /// Optional alt text following the opening "```".
    alt: Option<String>,
    /// Preformatted text to display to clients.
    text: String,
    },
  • replacement in gemini/src/gemtext.rs at line 151
    [4.4657][4.4657:4788]()
    pub fn preformatted(self, preformatted: impl Into<String>) -> Self {
    self.push(Doc::Preformatted(preformatted.into()))
    [4.4657]
    [4.4788]
    pub fn preformatted(self, alt: Option<impl Into<String>>, text: impl Into<String>) -> Self {
    let alt = alt.map(Into::into);
    let text = text.into();
    self.push(Doc::Preformatted { alt, text })
  • replacement in gemini/src/gemtext.rs at line 185
    [4.5657][4.5657:5742]()
    Doc::Preformatted(p) => {
    writeln!(f, "```\n{}\n```", p)
    [4.5657]
    [4.5742]
    Doc::Preformatted { alt, text } => {
    writeln!(
    f,
    "```{}\n{}\n```",
    alt.as_ref().unwrap_or(&String::new()),
    text
    )
  • replacement in gemini/src/gemtext.rs at line 204
    [4.5930][4.5930:5991]()
    .preformatted(" wooo\n/^^^^\\\n| |\n\\____/")
    [4.5930]
    [4.5991]
    .preformatted(Some("logo"), "wooo\n/^^^^\\\n| |\n\\____/")
  • replacement in gemini/src/gemtext.rs at line 216
    [4.6408][4.6408:6427]()
    r#"```
    [4.6408]
    [4.6427]
    r#"```logo
  • replacement in gemini/src/gemtext.rs at line 241
    [3.189][3.189:235]()
    bytes::complete::{is_not, tag, take},
    [3.189]
    [3.235]
    branch::alt,
    bytes::complete::{is_not, tag, take_until},
  • replacement in gemini/src/gemtext.rs at line 244
    [3.304][3.304:351]()
    combinator::{map, map_res, opt, peek},
    [3.304]
    [3.351]
    combinator::{map, opt, value},
    error::context,
    multi::many1,
  • replacement in gemini/src/gemtext.rs at line 257
    [3.556][3.556:790]()
    pub fn text(input: &str) -> IResult<&str, Doc> {
    map(line, |s: &str| {
    if s.is_empty() {
    Doc::Blank
    } else {
    Doc::Text(s.to_string())
    }
    })(input)
    [3.556]
    [3.790]
    fn text(input: &str) -> IResult<&str, Doc> {
    context(
    "gemtext text line",
    map(line, |s: &str| {
    if s.is_empty() {
    Doc::Blank
    } else {
    Doc::Text(s.to_string())
    }
    }),
    )(input)
  • replacement in gemini/src/gemtext.rs at line 270
    [3.797][3.797:850]()
    pub fn link(input: &str) -> IResult<&str, Doc> {
    [3.797]
    [3.850]
    fn link(input: &str) -> IResult<&str, Doc> {
  • replacement in gemini/src/gemtext.rs at line 272
    [3.936][3.936:1188]()
    map(
    preceded(pair(tag("=>"), space1), terminated(body, line_ending)),
    |(to, name): (&str, Option<&str>)| Doc::Link {
    to: to.to_string(),
    name: name.map(|s| s.to_string()),
    },
    [3.936]
    [3.1188]
    context(
    "gemtext link line",
    map(
    preceded(pair(tag("=>"), space1), terminated(body, line_ending)),
    |(to, name): (&str, Option<&str>)| Doc::Link {
    to: to.to_string(),
    name: name.map(|s| s.to_string()),
    },
    ),
  • replacement in gemini/src/gemtext.rs at line 285
    [3.1264][3.1264:1551]()
    map_res(peek(take(3usize)), |s| {
    Ok(match s {
    "###" => Level::Three,
    _ if s.starts_with("##") => Level::Two,
    _ if s.starts_with("#") => Level::One,
    _ => return Err(()),
    })
    })(input)
    [3.1264]
    [3.1551]
    alt((
    value(Level::One, tag("#")),
    value(Level::Two, tag("##")),
    value(Level::Three, tag("###")),
    ))(input)
  • replacement in gemini/src/gemtext.rs at line 292
    [3.1558][3.1558:1751]()
    pub fn heading(input: &str) -> IResult<&str, Doc> {
    map(
    terminated(pair(level, not_line_ending), line_ending),
    |(lvl, s)| Doc::Heading(lvl, s.to_string()),
    [3.1558]
    [3.1751]
    fn heading(input: &str) -> IResult<&str, Doc> {
    context(
    "gemtext heading line",
    map(
    terminated(pair(level, not_line_ending), line_ending),
    |(lvl, s)| Doc::Heading(lvl, s.to_string()),
    ),
  • replacement in gemini/src/gemtext.rs at line 302
    [3.1775][3.1775:1849]()
    pub fn list_item(input: &str) -> IResult<&str, Doc> {
    todo!()
    [3.1775]
    [3.1849]
    fn list_item(input: &str) -> IResult<&str, Doc> {
    context(
    "gemtex list item line",
    map(
    terminated(preceded(tag("*"), not_line_ending), line_ending),
    |s: &str| Doc::ListItem(s.to_string()),
    ),
    )(input)
  • replacement in gemini/src/gemtext.rs at line 312
    [3.1856][3.1856:1926]()
    pub fn quote(input: &str) -> IResult<&str, Doc> {
    todo!()
    [3.1856]
    [3.1926]
    fn quote(input: &str) -> IResult<&str, Doc> {
    context(
    "gemtext quote line",
    map(
    terminated(preceded(tag(">"), not_line_ending), line_ending),
    |s: &str| Doc::Quote(s.to_string()),
    ),
    )(input)
  • replacement in gemini/src/gemtext.rs at line 322
    [3.1933][3.1933:2010]()
    pub fn preformatted(input: &str) -> IResult<&str, Doc> {
    todo!()
    [3.1933]
    [3.2010]
    fn preformatted(input: &str) -> IResult<&str, Doc> {
    context(
    "gemtext preformatted block",
    map(
    terminated(
    pair(
    terminated(preceded(tag("```"), opt(not_line_ending)), line_ending),
    take_until("\n```"),
    ),
    pair(line_ending, tag("```")),
    ),
    |(alt, text): (Option<&str>, &str)| Doc::Preformatted {
    alt: alt.map(|s| s.to_string()),
    text: text.to_string(),
    },
    ),
    )(input)
  • edit in gemini/src/gemtext.rs at line 341
    [3.2017]
    [3.2017]
    /// Parse a utf-8 encoded gemtext document.
  • replacement in gemini/src/gemtext.rs at line 343
    [3.2078][3.2078:2094]()
    todo!()
    [3.2078]
    [3.2094]
    context(
    "gemtext document",
    map(
    many1(alt((text, link, heading, list_item, quote, preformatted))),
    Builder::from_docs,
    ),
    )(input)
  • edit in gemini/src/gemtext.rs at line 352
    [3.2102]
    pub use parse::document as parse_gemtext;