diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-05-29 11:48:37 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-06-09 16:52:34 +0200 |
commit | 12369ddadf0d0d4fa1618f8fdde6866a3a10c203 (patch) | |
tree | af5d03f355bdd009d03732b7e2404fd8138915a4 /libimagentrymarkdown/src | |
parent | 107e62a4269c8c51930dcbfc8271255d388034b5 (diff) |
Add into_urllink() translater helper
Diffstat (limited to 'libimagentrymarkdown/src')
-rw-r--r-- | libimagentrymarkdown/src/error.rs | 3 | ||||
-rw-r--r-- | libimagentrymarkdown/src/link.rs | 21 |
2 files changed, 23 insertions, 1 deletions
diff --git a/libimagentrymarkdown/src/error.rs b/libimagentrymarkdown/src/error.rs index f3d81d1e..3e42e21b 100644 --- a/libimagentrymarkdown/src/error.rs +++ b/libimagentrymarkdown/src/error.rs @@ -1,6 +1,7 @@ generate_error_module!( generate_error_types!(MarkdownError, MarkdownErrorKind, - MarkdownRenderError => "Markdown render error" + MarkdownRenderError => "Markdown render error", + LinkParsingError => "Link parsing error" ); ); diff --git a/libimagentrymarkdown/src/link.rs b/libimagentrymarkdown/src/link.rs index 19914308..8ac3500c 100644 --- a/libimagentrymarkdown/src/link.rs +++ b/libimagentrymarkdown/src/link.rs @@ -1,8 +1,12 @@ +use error::MarkdownErrorKind as MEK; use result::Result; use hoedown::renderer::Render; use hoedown::Buffer; use hoedown::Markdown; +use url::Url; + +use libimagerror::into::IntoError; #[derive(Debug, Clone, PartialEq, Eq)] pub struct Link { @@ -10,6 +14,23 @@ pub struct Link { pub link: String, } +impl Link { + + /// Translate a `Link` into a `UrlLink` + fn into_urllink(self) -> Result<UrlLink> { + Url::parse(&self.link[..]) + .map(move |link| UrlLink { title: self.title, link: link, }) + .map_err(Box::new) + .map_err(|e| MEK::LinkParsingError.into_error_with_cause(e)) + } + +} + +pub struct UrlLink { + pub title: String, + pub link: Url, +} + struct LinkExtractor { links: Vec<Link>, } |