2 unstable releases

0.2.0 Jun 26, 2023
0.1.0 Jun 26, 2023

#1359 in Text processing

Download history 21/week @ 2024-07-22 28/week @ 2024-07-29 23/week @ 2024-08-05 22/week @ 2024-08-12 15/week @ 2024-08-19 22/week @ 2024-08-26 11/week @ 2024-09-02 32/week @ 2024-09-09 16/week @ 2024-09-16 48/week @ 2024-09-23 23/week @ 2024-09-30 20/week @ 2024-10-07 1/week @ 2024-10-14 160/week @ 2024-10-21 90/week @ 2024-10-28 16/week @ 2024-11-04

268 downloads per month
Used in 2 crates (via markdown-it-autolink)

Apache-2.0

19KB
379 lines

gfm-autolinks

crates.io

A GitHub-flavored Markdown autolink matcher: https://github.github.com/gfm/#autolinks-extension-.

Usage

The match_start function matches from the start of the string, and returns None or the generated autolink, and the number of characters matched.

use gfm_autolinks::match_start;

match_start("foo")
// returns None

match_start("http://example.com more")
// returns Some(("http://example.com", 18))

match_start("www.example.com more")
// returns Some(("http://www.example.com", 15))

match_start("me@hotmail.com more")
// returns Some(("mailto:me@hotmail.com", 14))

The match_index function matches from a given index, and also returns None or the generated autolink, and the number of characters matched. If the index is not 0, it will also apply the rule, that the autolink must be preceded by a whitespace character or one of * _ ~ (. Invalid index will return None.

use gfm_autolinks::match_index;

match_index("foo", 10)
// returns None

match_index(" www.example.com", 1)
// returns Some(("http://www.example.com", 18))

match_index("]www.example.com", 1)
// returns None

Note, no HTML escaping is performed, e.g.

use gfm_autolinks::match_start;

match_start("http://example.com?foo=bar&baz=qux")
// returns Some(("http://example.com?foo=bar&baz=qux", 34))

Acknowledgements

Originally adapted from comrak.

Dependencies

~440KB