Skip to content

Bartomy-Labs/citeurl-dotnet

Repository files navigation

CiteUrl.NET

A .NET 9 library for parsing and hyperlinking legal citations. C# port of the Python citeurl library by Simon Raindrum Sherred.

NuGet Version NuGet Downloads CI Build GitHub Release License

Features

  • 130+ Citation Formats: US federal and state case law, statutes, regulations, constitutions, and rules
  • Thread-Safe: Fully immutable design with lazy singleton for concurrent use
  • Memory Efficient: Streaming enumeration (IEnumerable<T>) for processing large documents
  • HTML/Markdown Links: Insert hyperlinks directly into your text
  • Authority Grouping: Group multiple citations to the same legal source
  • Shortform Resolution: Automatically links "Id." and shortform citations to their parent
  • YAML-Based Templates: Extensible citation patterns via YAML configuration
  • DI-Friendly: Optional dependency injection extensions
  • ReDoS Protection: Built-in regex timeout protection

Installation

dotnet add package CiteUrl.Core

For dependency injection support:

dotnet add package CiteUrl.Extensions.DependencyInjection

Quick Start

Find a Single Citation

using CiteUrl.Core.Templates;

var citation = Citator.Cite("See 42 U.S.C. § 1983 for details.");

Console.WriteLine(citation?.Text);  // "42 U.S.C. § 1983"
Console.WriteLine(citation?.Url);   // "https://www.law.cornell.edu/uscode/text/42/1983"
Console.WriteLine(citation?.Name);  // "42 U.S.C. § 1983"

Find All Citations

var text = @"
    Federal law provides civil rights remedies under 42 U.S.C. § 1983,
    and attorney's fees may be awarded pursuant to § 1988.
    See also Fed. R. Civ. P. 12(b)(6).
";

foreach (var citation in Citator.ListCitations(text))
{
    Console.WriteLine($"{citation.Name} -> {citation.Url}");
}

// Output:
// 42 U.S.C. § 1983 -> https://www.law.cornell.edu/uscode/text/42/1983
// § 1988 -> https://www.law.cornell.edu/uscode/text/42/1988
// Fed. R. Civ. P. 12(b)(6) -> https://www.law.cornell.edu/rules/frcp/rule_12

Insert Hyperlinks

var text = "See 42 U.S.C. § 1983 and 29 C.F.R. § 1630.2 for details.";
var html = Citator.Default.InsertLinks(text);

Console.WriteLine(html);
// Output:
// See <a href="https://www.law.cornell.edu/uscode/text/42/1983" class="citation" title="42 U.S.C. § 1983">42 U.S.C. § 1983</a>
// and <a href="..." class="citation" title="29 C.F.R. § 1630.2">29 C.F.R. § 1630.2</a> for details.

Markdown Links

var markdown = Citator.Default.InsertLinks(text, markupFormat: "markdown");

Console.WriteLine(markdown);
// Output:
// See [42 U.S.C. § 1983](https://www.law.cornell.edu/uscode/text/42/1983)
// and [29 C.F.R. § 1630.2](...) for details.

Group Citations by Authority

var text = @"
    See 42 U.S.C. § 1983 and § 1985. Also 42 U.S.C. § 1983 again.
";

var authorities = Citator.ListAuthorities(text);

foreach (var authority in authorities)
{
    Console.WriteLine($"{authority.Name}: {authority.Citations.Count} citations");
}

// Output:
// 42 U.S.C. § 1983: 2 citations
// 42 U.S.C. § 1985: 1 citation

Supported Citation Types

  • U.S. Case Law: Supreme Court, Circuit Courts, District Courts, Bankruptcy
  • State Case Law: All 50 states + territories
  • Federal Statutes: U.S. Code (USC)
  • Federal Regulations: Code of Federal Regulations (CFR)
  • State Codes: California, New York, Texas, and 47 other states
  • Constitutions: U.S. Constitution, state constitutions
  • Federal Rules: FRCP, FRE, FRAP, FRCrP, etc.
  • Secondary Sources: Law reviews, restatements

See USAGE.md for detailed examples of each citation type.

Advanced Usage

Custom YAML Templates

var yaml = @"
My Custom Citation:
  tokens:
    volume: \d+
    page: \d+
  pattern: 'Vol. {volume}, p. {page}'
  URL builder:
    parts: ['https://example.com/vol/', '{volume}', '/page/', '{page}']
";

var citator = Citator.FromYaml(yaml);
var citation = citator.Cite("See Vol. 123, p. 456");

Console.WriteLine(citation?.Url); // https://example.com/vol/123/page/456

Dependency Injection

// In Startup.cs or Program.cs
services.AddCiteUrl();

// In your service
public class MyService
{
    private readonly ICitator _citator;

    public MyService(ICitator citator)
    {
        _citator = citator;
    }

    public void ProcessLegalText(string text)
    {
        var citations = _citator.ListCitations(text);
        // ...
    }
}

Documentation

  • USAGE.md - Detailed usage guide with examples
  • API Reference - Full XML documentation available via IntelliSense in your IDE
  • Python Original - Original Python library

Contributing

Contributions welcome! Please see CONTRIBUTING.md for guidelines.

Attribution

This is a C# port of the Python citeurl library created by Simon Raindrum Sherred. The original Python library is licensed under the MIT License.

License

MIT License - see LICENSE for details.

Original Python library by Simon Raindrum Sherred, MIT License.

Status

Released - v1.0.1 available on NuGet. Core functionality complete with 121+ passing tests.

About

C# port of the Python citeurl library for parsing and hyperlinking legal citations

Resources

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages