CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-linkify-it

Links recognition library with FULL unicode support for detecting high-quality link patterns in plain text

Overall
score

97%

Overview
Eval results
Files

task.mdevals/scenario-1/

URL Highlighter

Create a utility that detects and highlights URLs in plain text content, even when they don't include a protocol prefix (like http:// or https://).

Requirements

Your utility should:

  1. Detect URLs in text that may or may not have a protocol prefix

    • Should detect standard URLs like https://example.com
    • Should detect URLs without protocol like example.com or www.subdomain.example.org
    • Should detect protocol-neutral URLs like //example.com
  2. For each detected URL in the text, return information about:

    • The position where it starts in the text
    • The position where it ends in the text
    • The original text of the URL
    • A normalized URL with protocol added if needed
  3. Support configuration to enable or disable detection of URLs without protocol prefixes

  4. Provide a quick check function to determine if text potentially contains any URLs before performing full detection

Test Cases

  • Given the text "Check out example.com for more info", it detects the URL example.com starting at index 10 @test

  • Given the text "Visit www.github.com/repo today", it detects www.github.com/repo and normalizes it to include a protocol @test

  • Given the text "The site //cdn.example.org is fast", it detects the protocol-neutral URL //cdn.example.org @test

  • When fuzzy link detection is disabled, the text "Go to example.com" should not detect any URLs @test

Implementation

@generates

API

/**
 * Creates a URL detector with optional configuration
 * @param {Object} options - Configuration options
 * @param {boolean} options.fuzzyLink - Enable detection of URLs without protocol (default: true)
 * @returns {Object} URL detector instance
 */
function createDetector(options) {
  // IMPLEMENTATION HERE
}

/**
 * Checks if text contains any potential URLs
 * @param {string} text - Text to check
 * @returns {boolean} True if text might contain URLs
 */
function hasUrls(text) {
  // IMPLEMENTATION HERE
}

/**
 * Finds all URLs in the given text
 * @param {string} text - Text to search
 * @returns {Array|null} Array of match objects with index, lastIndex, raw, text, url properties, or null if none found
 */
function findUrls(text) {
  // IMPLEMENTATION HERE
}

module.exports = {
  createDetector,
  hasUrls,
  findUrls,
};

Dependencies { .dependencies }

linkify-it { .dependency }

Provides link detection and recognition capabilities with full Unicode support.

Install with Tessl CLI

npx tessl i tessl/npm-linkify-it

tile.json