Browse Source

Fix email links being checked by link checker

Closes #403
index-subcmd
Vincent Prouillet 5 years ago
parent
commit
b4158921dd
4 changed files with 35 additions and 7 deletions
  1. +2
    -2
      CHANGELOG.md
  2. +3
    -1
      components/rendering/src/markdown.rs
  3. +29
    -3
      components/rendering/tests/markdown.rs
  4. +1
    -1
      components/site/tests/site.rs

+ 2
- 2
CHANGELOG.md View File

@@ -4,9 +4,9 @@

- Gutenberg has changed name to REPLACE_ME!
- Update dependencies, fixing a few bugs with templates
- Make Gutenberg load only .html files in themes from the templates folder
- Load only .html files in themes from the templates folder
- Background colour is set fewer times when highlighting syntaxes
- Link checker will not try to validate email links anymore

## 0.4.2 (2018-09-03)



+ 3
- 1
components/rendering/src/markdown.rs View File

@@ -160,7 +160,9 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render
} else if is_colocated_asset_link(&link) {
format!("{}{}", context.current_page_permalink, link)
} else {
if context.config.check_external_links && !link.starts_with('#') {
if context.config.check_external_links
&& !link.starts_with('#')
&& !link.starts_with("mailto:") {
let res = check_url(&link);
if res.is_valid() {
link.to_string()


+ 29
- 3
components/rendering/tests/markdown.rs View File

@@ -48,7 +48,7 @@ fn can_highlight_code_block_no_lang() {
let res = render_content("```\n$ gutenberg server\n$ ping\n```", &context).unwrap();
assert_eq!(
res.body,
"<pre style=\"background-color:#2b303b\">\n<span style=\"background-color:#2b303b;color:#c0c5ce;\">$ gutenberg server\n</span><span style=\"background-color:#2b303b;color:#c0c5ce;\">$ ping\n</span></pre>"
"<pre style=\"background-color:#2b303b\">\n<span style=\"color:#c0c5ce;\">$ gutenberg server\n</span><span style=\"color:#c0c5ce;\">$ ping\n</span></pre>"
);
}

@@ -61,7 +61,7 @@ fn can_highlight_code_block_with_lang() {
let res = render_content("```python\nlist.append(1)\n```", &context).unwrap();
assert_eq!(
res.body,
"<pre style=\"background-color:#2b303b\">\n<span style=\"background-color:#2b303b;color:#c0c5ce;\">list.</span><span style=\"background-color:#2b303b;color:#bf616a;\">append</span><span style=\"background-color:#2b303b;color:#c0c5ce;\">(</span><span style=\"background-color:#2b303b;color:#d08770;\">1</span><span style=\"background-color:#2b303b;color:#c0c5ce;\">)\n</span></pre>"
"<pre style=\"background-color:#2b303b\">\n<span style=\"color:#c0c5ce;\">list.</span><span style=\"color:#bf616a;\">append</span><span style=\"color:#c0c5ce;\">(</span><span style=\"color:#d08770;\">1</span><span style=\"color:#c0c5ce;\">)\n</span></pre>"
);
}

@@ -75,7 +75,7 @@ fn can_higlight_code_block_with_unknown_lang() {
// defaults to plain text
assert_eq!(
res.body,
"<pre style=\"background-color:#2b303b\">\n<span style=\"background-color:#2b303b;color:#c0c5ce;\">list.append(1)\n</span></pre>"
"<pre style=\"background-color:#2b303b\">\n<span style=\"color:#c0c5ce;\">list.append(1)\n</span></pre>"
);
}

@@ -564,6 +564,32 @@ fn can_show_error_message_for_invalid_external_links() {
assert!(err.description().contains("Link http://google.comy is not valid"));
}

#[test]
fn doesnt_try_to_validate_email_links_mailto() {
let permalinks_ctx = HashMap::new();
let mut config = Config::default();
config.check_external_links = true;
let context = RenderContext::new(&GUTENBERG_TERA, &config, "https://vincent.is/about/", &permalinks_ctx, Path::new("something"), InsertAnchor::None);
let res = render_content("Email: [foo@bar.baz](mailto:foo@bar.baz)", &context).unwrap();
assert_eq!(
res.body,
"<p>Email: <a href=\"mailto:foo@bar.baz\">foo@bar.baz</a></p>\n"
);
}

#[test]
fn doesnt_try_to_validate_email_links_angled_brackets() {
let permalinks_ctx = HashMap::new();
let mut config = Config::default();
config.check_external_links = true;
let context = RenderContext::new(&GUTENBERG_TERA, &config, "https://vincent.is/about/", &permalinks_ctx, Path::new("something"), InsertAnchor::None);
let res = render_content("Email: <foo@bar.baz>", &context).unwrap();
assert_eq!(
res.body,
"<p>Email: <a href=\"mailto:foo@bar.baz\">foo@bar.baz</a></p>\n"
);
}

#[test]
fn can_handle_summaries() {
let tera_ctx = Tera::default();


+ 1
- 1
components/site/tests/site.rs View File

@@ -454,5 +454,5 @@ fn can_build_with_extra_syntaxes() {
assert!(&public.exists());
assert!(file_exists!(public, "posts/extra-syntax/index.html"));
assert!(file_contains!(public, "posts/extra-syntax/index.html",
r#"<span style="background-color:#2b303b;color:#d08770;">test</span>"#));
r#"<span style="color:#d08770;">test</span>"#));
}

Loading…
Cancel
Save