HrefWizard is a simple .NET library that automatically adds HTML anchor tags (<a>) to specific keywords within a given text. Define your keywords and URLs, and let the wizard do the rest!
$ dotnet add package HrefWizardHrefWizard is a simple .NET library that automatically adds HTML anchor tags (<a>) to specific keywords within a given text. Define your keywords and URLs, and let the wizard do the rest!
<a> tags.target="_blank" and rel="nofollow" attributes.Install the package via NuGet Package Manager:
Install-Package HrefWizard
Or via the .NET CLI:
dotnet add package HrefWizard
using System;
using HrefWizard; // Add this using statement
public class Example
{
public static void Main(string[] args)
{
// 1. Create a wizard instance
var wizard = new HrefWizard();
// 2. Add link definitions
wizard.AddLink("google", "[https://www.google.com](https://www.google.com)");
wizard.AddLink("nuget", "[https://www.nuget.org](https://www.nuget.org)", targetBlank: true);
wizard.AddLink("Microsoft", "[https://www.microsoft.com](https://www.microsoft.com)", relNoFollow: true);
wizard.AddLink("OpenAI", "[https://openai.com](https://openai.com)", targetBlank: true, relNoFollow: true);
// 3. Process your text
string inputText = "Search on Google for the latest Microsoft products or find packages on NuGet. Check out OpenAI too.";
string linkedText = wizard.ProcessText(inputText);
// 4. Use the result
Console.WriteLine(linkedText);
// Output:
// Search on <a href="[https://www.google.com](https://www.google.com)">Google</a> for the latest <a href="[https://www.microsoft.com](https://www.microsoft.com)" rel="nofollow">Microsoft</a> products or find packages on <a href="[https://www.nuget.org](https://www.nuget.org)" target="_blank">NuGet</a>. Check out <a href="[https://openai.com](https://openai.com)" target="_blank" rel="nofollow">OpenAI</a> too.
}
}
When adding links using AddLink, you can specify:
targetBlank (bool): If true, adds target="_blank" to the link, making it open in a new tab. Defaults to false.relNoFollow (bool): If true, adds rel="nofollow" to the link. Defaults to false.(Note: Case sensitivity and whole word matching are currently handled by default logic but could become configurable options in future versions).
<a>, <img>, <pre>, <code> tags).Contributions, issues, and feature requests are welcome! Feel free to check issues page.
This project is licensed under the Apache-2.0 license.