Random Words to Links Converter
Convert random words in HTML text to hyperlinks with configurable frequency, forced words, excluded elements, and custom link templates.
{t} as a placeholder for the word
About
Automated link insertion across large HTML documents is error-prone when done manually. Missing a keyword costs referral traffic. Linking inside a <button> or nested <a> breaks accessibility and violates HTML spec. This tool walks every text node in your markup, applies a configurable probability gate (f ∈ [0, 1]) to each eligible word, and wraps selections in anchor elements whose href is built from a URL template with a {t} token. It respects element exclusion lists so structural tags remain untouched, and forces links on priority keywords regardless of the random threshold. Leading and trailing punctuation is stripped from the link text and preserved outside the anchor, preventing malformed URLs.
The algorithm performs a depth-first traversal. Words split across inline tags (e.g., B<b>A</b>CON) are not matched as forced words because the text node boundary interrupts the token. This is intentional: partial-node wrapping would corrupt the DOM tree. The tool approximates the behavior of the OutText jQuery plugin but requires zero dependencies. Limitations: the frequency parameter is stochastic, so output varies between runs for the same input. For deterministic results, set frequency to 1 or rely solely on forced words.
Formulas
For each text node discovered by the tree walker, words are extracted via whitespace splitting. Each word w is tested against the link-generation rules in priority order:
The href is constructed as:
Where f = frequency (0 ≤ f ≤ 1), strip(w) removes leading/trailing non-word characters, and rand() returns a uniform random value in [0, 1). The expected number of random links E across N eligible words is:
Reference Data
| Parameter | Type | Default | Description |
|---|---|---|---|
| link_template | String | # | URL pattern. Use {t} as placeholder for the word text. |
| frequency | Float | 0.1 | Probability each eligible word becomes a link (0 - 1). |
| excluded_elements | Array | ["button", "a"] | Tag names inside which no links are generated. |
| forced_words | Array | [] | Words that always become links (case-insensitive, exact match). |
| {t} token | Token | - | Replaced with encodeURIComponent(word) in the final href. |
| Punctuation handling | Behavior | - | Leading/trailing punctuation stays outside the <a> tag. |
| Nested tag words | Behavior | - | Words split by inner HTML tags are not matched for forced linking. |
| Exclusion priority | Rule | Highest | Even forced words inside excluded elements produce no links. |
| Case sensitivity | Rule | Insensitive | Forced words match regardless of case ("Bacon" = "bacon"). |
| Empty {t} | Behavior | - | If no {t} in template, href is used as-is for every link. |
| frequency = 0 | Edge case | - | No random links. Only forced words generate links. |
| frequency = 1 | Edge case | - | Every eligible word becomes a link. |
| Script tags in input | Security | - | Parsed via DOMParser; scripts do not execute in output context. |
| Self-closing tags | Behavior | - | <br>, <img>, <hr> are preserved; no text nodes inside them. |
| Whitespace-only nodes | Behavior | - | Skipped. No empty links generated. |