@bscotch/steam-bbcode
v0.3.0
Published
Generate Steam-compatible BBCode from Markdown.
Downloads
33
Readme
Steam BBCode Generator
Steam has been around for a while, and many parts of its content management system still use legacy BBCode formats. This tool helps generate Steam-compatible BBCode from Markdown.
Note: currently only supports pure Markdown (embedded HTML is left as-is).
Features
- Supports most of Steam's BBCode format
- Leaves YouTube and Steam links as-is, allowing Steam to convert them into widgets.
Missing Features
- Only the BBCode markup documented by Steam is supported
- Only supports pure Markdown input, with the exception of
<img>
tags. HTML is left as-is. - Does not support tags that have no equivalent in Markdown
- ❌
[spoiler]
- ❌
[noparse]
- ❌
[u]
- ❌
- Does not support tag options that don't have standard support in Markdown
- ❌
[quote=author]
([quote]
is supported, but there isn't a way to provide an author)
- ❌
Usage
For a typical use case:
import { md2bbcode } from '@bscotch/steam-bbcode';
const converted = md2bbcode('# Hello, world!');
const bbcode = converted.bbcode;
This package uses marked for rendering. If you want to use your own version of the marked dependency, or want to further modify rendering with your own marked extensions, you can import the BBCode marked extension from this package to use directly:
import { markedBbcodeExtension } from '@bscotch/steam-bbcode/lib';
import { Marked } from 'marked';
const marked = new Marked(
markedBbcodeExtension /* ... optional other extensions */,
);
function toBbcode(md: string): string {
// (Marked replaces single-quotes with ', which Steam doesn't know what to do with.)
return (marked.parse(source) as string).replaceAll(''', "'");
}
const converted = toBbcode('# Hello, world!');
Example
The following Markdown input:
# H1 Heading
## H2 Heading
### H3 Heading
Steam only supports h1-h3, the rest should just be bold.
#### H4 Heading
##### H5 Heading
###### H6 Heading
Some **Bold text**
Some _Italic text_
A [Link](https://example.com 'With a title')
Some ~~Strikethrough text~~
- Unordered list item 1
- Unordered list item 2
1. **Ordered** list item 1
1. Ordered list item 2
> Blockquote
Some `Inline Code!`!
\`\`\`
Block Code!
\`\`\`
![Image](https://example.com/image.jpg)
[![Image](https://example.com/image.jpg)](https://example.com)
---
Plain steam (store.steampowered.com, steamcommunity.com) and youtube links on their own lines should be left as-is since they'll create widgets
https://store.steampowered.com/app/1401730/Crashlands_2/
https://www.youtube.com/watch?v=yR_Opccn1n4
<!-- Image HTML should get converted even though HTML isn't fully supported by this tool -->
<img src="https://example.com/image.jpg" alt="Image" />
Yields the following BBCode output:
[h1]H1 Heading[/h1]
[h2]H2 Heading[/h2]
[h3]H3 Heading[/h3]
Steam only supports h1-h3, the rest should just be bold.
[b]H4 Heading[/b]
[b]H5 Heading[/b]
[b]H6 Heading[/b]
Some [b]Bold text[/b]
Some [i]Italic text[/i]
A [url=https://example.com]Link[/url]
Some [strike]Strikethrough text[/strike]
[list]
[*] Unordered list item 1
[*] Unordered list item 2
[/list]
[olist]
[*] [b]Ordered[/b] list item 1
[*] Ordered list item 2
[/olist]
[quote]Blockquote[/quote]
Some [code]Inline Code![/code]!
[code]
Block Code!
[/code]
[img alt="Image"]https://example.com/image.jpg[/img]
[url=https://example.com][img alt="Image"]https://example.com/image.jpg[/img][/url]
[hr][/hr]
Plain steam (store.steampowered.com, steamcommunity.com) and youtube links on their own lines should be left as-is since they'll create widgets
https://store.steampowered.com/app/1401730/Crashlands_2/
https://www.youtube.com/watch?v=yR_Opccn1n4
[img alt="Image"]https://example.com/image.jpg[/img]