Skip to content

Latest commit

 

History

History
137 lines (111 loc) · 12.3 KB

examples.md

File metadata and controls

137 lines (111 loc) · 12.3 KB

Readme / Examples


Url highlight examples

Generic examples of Url highlight capabilities.

🔍 Feel free to inspect UrlHighlightTest and MatcherTest for more details.

Quick example

Input:
The main purpose of this library is to linkify urls in string input. The easiest case would be url with scheme like http://example.com. Without scheme example.com - also works fine, but not for example.txt. You want to know what about punctuation. If this highlighted properly: http://example.com? It is! Also, it takes care about brackets. So enclosed urls looks fine (http://example.com/path_with_(brackets)). Of course, it supports emails user@example.com. In real life there is urls like this one: http://elk.example.com:81/app/kibana#/discover?_g=()&_a=(columns:!(_source),index:'deve-',interval:auto,query:(query_string:(analyze_wildcard:!t,query:'')),sort:!('@timestamp',desc)) from ELK. As you see, it also works fine. Yes, it supports HTML and HTML encoded input. For example links <a href="http://example.com">example.com</a> won't be "double highlighted". See more details and examples bellow.

Result:
The main purpose of this library is to linkify urls in string input. The easiest case would be url with scheme like http://example.com. Without scheme example.com - also works fine, but not for example.txt. You want to know what about punctuation. If this highlighted properly: http://example.com? It is! Also, it takes care about brackets. So enclosed urls looks fine (http://example.com/path_with_(brackets)). Of course, it supports emails [email protected]. In real life there is urls like this one: http://elk.example.com:81/app/kibana#/discover?_g=()&_a=(columns:!(_source),index:'deve-*',interval:auto,query:(query_string:(analyze_wildcard:!t,query:'*')),sort:!('@timestamp',desc)) from ELK. As you see, it also works fine. Yes, it supports HTML and HTML encoded input. For example links example.com won't be "double highlighted". See more details and examples bellow.

Specific cases

Plain text

Simple

Value
Input: Text before http://example.com and after.
Output: Text before <a href="http://example.com">http://example.com</a> and after.
Rendered: Text before http://example.com and after.

No scheme

Value
Input: Text before example.com and after, but not example.txt.
Output: Text before <a href="http://example.com">example.com</a> and after, but not example.txt.
Rendered: Text before example.com and after, but not example.txt.

Punctuation

Value
Input: Did you visit http://example.com?
Output: Did you visit <a href="http://example.com">http://example.com</a>?
Rendered: Did you visit http://example.com?

Brackets

Value
Input: Text before (http://example.com/path_with_(brackets)) and after.
Output: Text before (<a href="http://example.com/path_with_(brackets)">http://example.com/path_with_(brackets)</a>) and after.
Rendered: Text before (http://example.com/path_with_(brackets)) and after.

Userinfo

Value
Input: Text before http://user:[email protected] and after.
Output: Text before <a href="http://user:[email protected]">http://user:[email protected]</a> and after.
Rendered: Text before http://user:[email protected] and after.

Unicode

Value
Input: Text before http://привіт.укр/★ and after.
Output: Text before <a href="http://привіт.укр/★">http://привіт.укр/★</a> and after.
Rendered: Text before http://привіт.укр/★ and after.

HTML

Simple

Value
Input: <p>Text before http://example.com and after.</p>
Output: <p>Text before <a href="http://example.com">http://example.com</a> and after.</p>
Rendered:

Text before http://example.com and after.

Link

Value
Input: Text before <a href="http://example.com">http://example.com</a> and after.
Output: Text before <a href="http://example.com">http://example.com</a> and after.
Rendered: Text before http://example.com and after.

Image

Value
Input: Text before <img src="https://github.githubassets.com/images/icons/emoji/unicode/1f369.png" height="14"> http://example.com and after.
Output: Text before <img src="https://github.githubassets.com/images/icons/emoji/unicode/1f369.png" height="14"> <a href="http://example.com">http://example.com</a> and after.
Rendered: Text before http://example.com and after.

Email

Simple

Value
Input: Text before [email protected] and after.
Output: Text before <a href="mailto:[email protected]">[email protected]</a> and after.
Rendered: Text before [email protected] and after.

With scheme

Value
Input: Text before mailto:[email protected] and after.
Output: Text before <a href="mailto:[email protected]">mailto:[email protected]</a> and after.
Rendered: Text before mailto:[email protected] and after.

Encoded

HTML special chars

Value
Input: Text before &lt;a href=&quot;http://example.com&quot;&gt;example.com&lt;/a&gt; and after.
Output: Text before &lt;a href=&quot;<a href="http://example.com">http://example.com</a>&quot;&gt;<a href="http://example.com">example.com</a>&lt;/a&gt; and after.
Rendered: Text before <a href="http://example.com">example.com</a> and after.

💡 Tip: HtmlSpecialcharsEncoder used here. See Encoder for more details.

HTML encoded

Value
Input: &#x54;&#x65;&#x78;&#x74;&#x20;&#x62;&#x65;&#x66;&#x6F;&#x72;&#x65;&#x20;&#x68;&#x74;&#x74;&#x70;&colon;&sol;&sol;&#x65;&#x78;&#x61;&#x6D;&#x70;&#x6C;&#x65;&period;&#x63;&#x6F;&#x6D;&#x20;&#x61;&#x6E;&#x64;&#x20;&#x61;&#x66;&#x74;&#x65;&#x72;&period;
Output: &#x54;&#x65;&#x78;&#x74;&#x20;&#x62;&#x65;&#x66;&#x6F;&#x72;&#x65;&#x20;<a href="http://example.com">&#x68;&#x74;&#x74;&#x70;&colon;&sol;&sol;&#x65;&#x78;&#x61;&#x6D;&#x70;&#x6C;&#x65;&period;&#x63;&#x6F;&#x6D;</a>&#x20;&#x61;&#x6E;&#x64;&#x20;&#x61;&#x66;&#x74;&#x65;&#x72;&period;
Rendered: Text before http://example.com and after.

💡 Tip: HtmlEntitiesEncoder used here. See Encoder for more details.