Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

API

Rust library for programmatic citation generation.

Installation

[dependencies]
url2ref = { git = "https://github.com/url2ref/url2ref" }

Quick Start

#![allow(unused)]
fn main() {
use url2ref::{generate, GenerationOptions};

let options = GenerationOptions::default();
let reference = generate("https://example.com/article", &options)?;

println!("{}", reference.wiki());
println!("{}", reference.bibtex());
println!("{}", reference.harvard());
}

Configuration

#![allow(unused)]
fn main() {
use url2ref::{GenerationOptions, GenerationOptionsBuilder};
use url2ref::generator::{TranslationOptions, TranslationProvider, ArchiveOptions, AiExtractionOptions};

let options = GenerationOptions {
    attribute_config: AttributeConfig::default(),
    translation_options: TranslationOptions {
        provider: TranslationProvider::DeepL,
        target: Some("EN".to_string()),
        deepl_key: std::env::var("DEEPL_API_KEY").ok(),
        ..Default::default()
    },
    archive_options: ArchiveOptions {
        include_archived: true,
        perform_archival: false,
    },
    ai_options: AiExtractionOptions::default(),
};
}

Functions

FunctionDescription
generate(url, options)Generate reference from URL
generate_from_file(path, options)Generate from local HTML
parse_all_metadata(url)Extract all metadata without generating
fetch_parse_info(url, options)Fetch and parse for reuse

Types

TypeDescription
ReferenceEnum with NewsArticle, ScholarlyArticle, GenericReference
AttributeEnum for Title, Authors, Date, Url, etc.
GenerationOptionsConfiguration for generation

Error Handling

#![allow(unused)]
fn main() {
match generate(url, &options) {
    Ok(reference) => println!("{}", reference.wiki()),
    Err(ReferenceGenerationError::CurlError(e)) => eprintln!("Network: {}", e),
    Err(ReferenceGenerationError::ParseFailure) => eprintln!("No metadata found"),
    Err(e) => eprintln!("Error: {}", e),
}
}

Generate Docs

cargo doc --no-deps --open