1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
pub mod parser;

use crate::parser::Parser;

/// Extract html 'a' tag from page
/// # Examples
/// ```
///     use ahref::get_a_tags;
///
///     let html = "<p>Test</p><a>without link</a><a href='https://github.com/tenqz/'>Test Link 1</a><p>Another Text</p><a href='https://github.com/tenqz/'>Test Link 2</a><p>Another Text</p><a class='test' href='https://github.com/tenqz/'>Test Link 3</a><p>Another Text</p>".to_string();
///     let tags = get_a_tags(html);
///     assert_eq!(
///        vec![
///            "<a>without link</a>".to_string(),
///            "<a href='https://github.com/tenqz/'>Test Link 1</a>".to_string(),
///            "<a href='https://github.com/tenqz/'>Test Link 2</a>".to_string(),
///            "<a class='test' href='https://github.com/tenqz/'>Test Link 3</a>".to_string()
///        ],
///        tags
///    );
///
/// ```
pub fn get_a_tags(html: String) -> Vec<String> {
    let mut parser = Parser::new(html);
    parser.parse_tags()
}

/// Extract links from array 'a' tags
/// # Examples
/// ```
///     use ahref::get_url_from_tags;
///     let html = "<p>Test</p><a>without link</a><a href='https://github.com/tenqz/'>Test Link 1</a><p>Another Text</p><a href='https://github.com/tenqz/'>Test Link 2</a><p>Another Text</p><a class='test' href='https://github.com/tenqz/'>Test Link 3</a><p>Another Text</p><a href=\"/\" class=\"nav-link px-2 text-muted\">Main Page</a><a href=\"/blog\" class=\"nav-link px-2 text-muted\">Blog</a><a href=\"/vacancies/developer\" class=\"nav-link px-2 text-muted\">Vacancies</a><a href=\'/policy\' class='nav-link px-2 text-muted'>Policy</a>".to_string();
///     let links = get_url_from_tags(html);
///     assert_eq!(
///         vec![
///             "https://github.com/tenqz/",
///             "https://github.com/tenqz/",
///             "https://github.com/tenqz/",
///             "/",
///             "/blog",
///             "/vacancies/developer",
///             "/policy"
///             ],
///         links
///     );
/// ```

pub fn get_url_from_tags(html: String) -> Vec<String> {
    let mut parser = Parser::new(html);
    parser.parse_links()
}