Crates.io | parse-hyperlinks |
lib.rs | parse-hyperlinks |
version | 0.27.2 |
source | src |
created_at | 2020-11-25 14:50:33.904998 |
updated_at | 2023-10-19 16:26:43.011996 |
description | A Nom parser library for hyperlinks with markup. |
homepage | https://gitlab.com/getreu/parse-hyperlinks |
repository | https://gitlab.com/getreu/parse-hyperlinks |
max_upload_size | |
id | 316319 |
size | 259,559 |
Parse-hyperlinks, a parser library written with Nom to recognize hyperlinks and link reference definitions in Markdown, reStructuredText, Asciidoc and HTML formatted text input.
The library implements the CommonMark Specification 0.30, reStructuredText Markup Specification (revision 8571, date 2020-10-28), the specifications in Asciidoctor User Manual, chapter 26 (date 2020-12-03) and HTML 5.2: section 4.5.
To illustrate the usage and the API of the library, Parse-hyperlinks comes with a simple command line application: Atext2html
All input is UTF-8 encoded.
The input text is formatted according to one of the markup language specification above. As Parse-Hyperlinks ignores most of the markup, it relies solely on the hyperlink specification of the respective markup language.
The characters &<>"
in absolute URLs in HTML documents must be HTML-
escape-encoded: these characters are replaced with their entity names, e.g.
&
, <
, >
and "e
.
Relative URLs (local links) in UTF-8 encoded HTML document, do not need to be HTML-escape encoded. I recommend not to do so.
Relative URLs (local links) must not be preceded by a scheme, e.g. html:
.
In addition to HTML-escape-encoding, URLs can be percent encoded, e.g.
%20
or %26
. When both encoding appear in an HTML document, the HTML
escape decoding is applied first, then the percent encoding.
For example, the encoded string Ü ber%26amp;Über &
is decoded to
Ü ber&Über &
. In general, URLs in UTF-8 HTML documents can be
expressed without percent encoding, which is recommended.
The following section explains how Parse-Hyperlinks meets the above General HTML requirements. It refers to the items in the list above.
Only functions in the renderer
module, HTML-escape encode absolute URLs
in HTML documents: The characters &<>"
are replaced with their HTML escape
entity names, e.g.: &
, <
, >
and "e
. All other parsers
and iterators do not apply HTML-escape-encoding to absolute URLs.
No function, parser or iterator in Parse-Hyperlinks applies escape-encoding to relative URLs.
This property is not enforced by Parse-Hyperlinks. Compliance depend on the parser's input.
Percent-encoding in Parse-Hyperlinks:
No percent encoding at all is performed in Parse-Hyperlinks.
Percent decoding: In some cases, when the markup language specification requires the input URL to be percent encoded, the concerned consuming parser decodes the percent encoding automatically. Percent decoding is URL's is performed implicitly when consuming:
md_text2dest()
,adoc_label2dest()
, adoc_text2dest
wikitext_text2dest()
Rendered autolink markup:
The same Markdown input may result in different HTML according to
the renderer. For example: pulldown-cmark
renders
the Markdown autolink <http://getreu.net/Ü%20&>
into
<a href="http://getreu.net/%C3%9C%20&">http://getreu.net/Ü%20&</a>
.
http://getreu.net/%C3%9C%20&
) and the link text
(http://getreu.net/Ü%20&
) are slightly different, which has
to be taken into account when detecting autolinks based on the HTML
rendition.The Parse-Hyperlinks Markdown renderer gives for the same
input <http://getreu.net/Ü%20&>
a slightly different result:
<a href="http://getreu.net/Ü%20&">http://getreu.net/Ü &</a>
.
Explanation: first the parser md_text2dest()
(percent) decodes the
URL to http://getreu.net/Ü &
and the renderer function in the module
renderer
(HTML-escape) encodes the result into
http://getreu.net/Ü%20&