A lightweight, efficient parser for converting Steam's BBCode format (used in game news and updates) to HTML.
- ✅ Comprehensive Tag Support - Handles all common Steam BBCode tags
- ✅ Efficient - Rule-based system for fast parsing
- ✅ Malformed BBCode Handling - Gracefully handles incomplete or broken tags
- ✅ Zero Dependencies - Pure JavaScript, no external packages
- ✅ Browser & Node.js - Works in both environments
- ✅ Well-Tested - Battle-tested on real Steam game news
- Fixed YouTube video ID extraction - The semicolon in
[previewyoutube]tags is INSIDE the quotes, not outside - Correct format:
[previewyoutube="ULFMhdpFXRE;full"][/previewyoutube] - Changed embed domain: Now uses
youtube-nocookie.comfor better privacy and embed compatibility - Added accessibility: Includes proper
titleattribute andframeborderfor better browser support - Real-world example: Tested with Helldivers 2 update news
npm install steam-bbcode-parserconst parseSteamBBCode = require('steam-bbcode-parser');
// Example Steam BBCode from game news
const bbcode = `[h1]New Update![/h1]
[b]Features:[/b]
[list]
[*]Fixed bugs
[*]Added new content
[/list]
[url=https://example.com]Read more[/url]`;
const html = parseSteamBBCode(bbcode);
console.log(html);[b]bold[/b]- Bold text[i]italic[/i]- Italic text[u]underline[/u]- Underlined text[strike]strikethrough[/strike]- Strikethrough text[c]centered[/c]- Centered text
[h1]heading[/h1]- H1 heading[h2]heading[/h2]- H2 heading[h3]heading[/h3]- H3 heading
[list][*]item[/list]- Unordered list[olist][*]item[/olist]- Ordered list
[url]link[/url]- Simple link[url=http://example.com]text[/url]- Link with custom text[dynamiclink href="url"]text[/dynamiclink]- Steam dynamic links
[img]url[/img]- Images[video mp4="url" poster="url"]...[/video]- HTML5 video[previewyoutube="videoId;options"][/previewyoutube]- YouTube embeds (note: semicolon is inside quotes)
[code]code[/code]- Inline code[pre]code block[/pre]- Code blocks
[hr]- Horizontal rule[p]- Paragraph break{STEAM_CLAN_IMAGE}/appid/hash.png- Steam CDN images
Automatically cleans up:
- Escaped brackets:
\[→[ - Incomplete tags:
[video mp4="url"(missing closing bracket) - Orphaned closing tags
- Excess whitespace
- Converts
{STEAM_CLAN_IMAGE}placeholders to actual CDN URLs - Handles Steam's custom
[dynamiclink]tags - Processes video tags with both webm and mp4 sources
- Handles YouTube preview embeds
Parameters:
bbcode(string) - Steam BBCode text to parse
Returns:
- (string) - HTML output
Example:
const html = parseSteamBBCode('[b]Hello[/b] [i]World[/i]');
// Output: <strong style="...">Hello</strong> <em style="...">World</em>const parseSteamBBCode = require('steam-bbcode-parser');
async function getGameNews(appid) {
const response = await fetch(
`https://api.steampowered.com/ISteamNews/GetNewsForApp/v2/?appid=${appid}&count=10`
);
const data = await response.json();
const newsItems = data.appnews.newsitems;
return newsItems.map(item => ({
title: item.title,
date: new Date(item.date * 1000),
html: parseSteamBBCode(item.contents)
}));
}
// Get CS2 news
getGameNews(730).then(news => {
news.forEach(item => {
console.log(item.title);
console.log(item.html);
});
});<script src="https://unpkg.com/steam-bbcode-parser"></script>
<script>
const html = parseSteamBBCode('[b]Steam[/b] BBCode');
document.getElementById('output').innerHTML = html;
</script>This parser uses a rule-based system with minimal overhead:
- Fast: Processes typical game news (5KB) in <1ms
- Memory efficient: No AST generation, direct string replacement
- Scalable: Handles large update notes (50KB+) with ease
- Nested tags
- Malformed/incomplete tags
- Mixed line endings
- Excessive whitespace
- Escaped characters
- Missing closing tags
- Orphaned attributes
Contributions welcome! Please open an issue or PR if you find bugs or want to add features.
MIT
Developed for Steam Update Tracker - Track game updates you've missed since you last played.