# BBCode Scoped Formatter (/formatters/bbcode)

Scope-based BBCode tags for forum posts and BBCode-based platforms.

## Options

| Runtime | Options |
| --- | --- |
| Rust | `language`, `highlight_lines` |
| Elixir | `language`, `highlight_lines` |
| JavaScript / TypeScript | `language`, `highlightLines` |
| Java | `withLang()`, `withFormatter(Formatter.BBCODE)` |
| CLI | `--highlight-lines` |

A highlighted line is wrapped in `[highlighted]...[/highlighted]`. See
[Line Highlighting](/recipes/line-highlighting).

## Example

### JavaScript / TypeScript

```js
import {highlight} from '@lumis-sh/lumis'
import {bbcodeScoped} from '@lumis-sh/lumis/formatters'
import javascript from '@lumis-sh/wasm-javascript'

const output = await highlight(
  'const x = "[url=x]"',
  bbcodeScoped({language: javascript})
)

console.log(output)
```

### Rust

```rust
use lumis::{
    highlight, languages::Language, BBCodeScopedBuilder,
};

let bbcode = highlight(
    "fn main() {}",
    BBCodeScopedBuilder::new()
        .language(Language::Rust)
        .build()
        .unwrap(),
);

println!("{}", bbcode);
```

### Elixir

```elixir
bbcode = Lumis.highlight!(
  ~s(const x = "[url=x]"),
  formatter: {:bbcode_scoped, language: "javascript"}
)

IO.puts(bbcode)
```

### Java

```java
import io.roastedroot.lumis4j.core.Formatter;
import io.roastedroot.lumis4j.core.Lang;
import io.roastedroot.lumis4j.core.Lumis;

var lumis = Lumis.builder().build();

var highlighter = lumis.highlighter()
    .withLang(Lang.JAVASCRIPT)
    .withFormatter(Formatter.BBCODE)
    .build();

var output =
    highlighter.highlight("const x = \"[url=x]\"").string();
System.out.println(output);

lumis.close();
```

### CLI

```bash
lumis highlight main.rs -f bbcode-scoped
```


## Output format

A tag is the scope name from the syntax tree and the language it was matched in, with the dots replaced by hyphens:

```
[keyword-function-rust]fn[/keyword-function-rust] [function-rust]main[/function-rust]
```

`bbcodeScoped()` / `:bbcode_scoped` / `bbcode-scoped` emit highlight scope names as tags. They do not try to generate standard forum-style BBCode such as `[b]`, `[color]`, or `[code]`.

## When to use it

- Forum posts and BBCode-based platforms
- Custom rendering pipelines that consume scope-tagged text
- Lightweight markup without HTML overhead