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.29, 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 also with a simple command line application.
Installation:
Usage examples
Markdown
-
Create a file
input.txt
with text and hyperlinks:abc[text10](destination10 "title10")abc abc[text11][label11]abc abc[text12](destination2 "title12") abc[text13]abc
-
Run
parse-hyperlinks
:$ ./parse-hyperlinks <input.txt >output.html
-
Inspect
output.html
:abc [text10](destination10 "title10") abc abc [text11][label11] abc abc [text12](destination2 "title12") [text13]: destination3 "title13" [label11]: destination1 "title11" abc [text13] abc
This is how it looks like in the web browser:
$ firefox output.html
reStructuredText
-
Create a file
input.txt
with text and hyperlinks: -
Run
parse-hyperlinks
:$ ./parse-hyperlinks <input.txt >output.html
-
Inspect
output.html
:<label21_>`_ abc abc text22_ abc abc text23__ abc abc text_label24_ abc abc text25__ abc .. _label21: destination21 .. _text22: destination22 .. __: destination23 __ destination25 abc `text21
This is how it looks like in the web browser:
$ firefox output.html
Asciidoc
-
Create a file
input.txt
with text and hyperlinks:abc abc https://destination30[text30]abc abc link:https://destination31[text31]abc abc {label32}[text32]abc abc {label33}abc :label32: https://destination32 :label33: https://destination33
-
Run
parse-hyperlinks
:$ ./parse-hyperlinks <input.txt >output.html
-
Inspect
output.html
:abc abc https://destination30[text30] abc abc link:https://destination31[text31] abc abc {label32}[text32] abc abc {label33} abc :label32: https://destination32 :label33: https://destination33
This is how it looks like in the web-browser:
$ firefox output.html
HTML
-
Create a file
input.txt
with text and hyperlinks:abc<a href="dest1" title="title1">text1</a>abc abc<a href="dest2" title="title2">text2</a>abc
-
Run
parse-hyperlinks
:$ ./parse-hyperlinks <input.txt >output.html
-
Inspect
output.html
:<a href="dest1" title="title1">text1</a> abc abc<a href="dest2" title="title2">text2</a> abc abc
This is how it looks like in the web-browser:
$ firefox output.html