# Client Message Formatting Spec

## BBCode transport layer

A message may contain formatting to allow fun text shenanegans. The text will follow a BBCode format, using tags in square brackets. When a message is sent or recieved, it must either be in BBCode format or plain text format.

If a message begins with `[bb]` and ends with `[/bb]`, those tags should be removed from the ends, and the remaining message should be given to a BBCode parser. The BBCode Parser should support all normal tags (italic, bold, colors, etc.), as well as some custom ones defined below.

If a message does not begin with `[bb]` and end with `[/bb]`, the message is assumed to be plaintext, and is desplayed in its raw form.


### Custom Tags

- The `LaTeX` tag formats its contents using a TeX or LaTeX parser.  
  Parameters: The one parameter this tag accepts is the mode of the LaTeX.  
  This can be inline or block. You may shorten these to `i` and `b` if you'd like.
  If neither is specified, the client will choose one, assuming that LaTeX means block and all aliases mean inline.  
  Examples:
  - `[LaTeX=i]e^{i\pi}[/LaTeX]` -> The contents formatted as inline LaTeX
  - `[LaTeX]\frac{\biggr B^{lo}}{ck}[/LaTeX]` -> The contents formatted as a block of LaTeX

  Aliases: `TeX`, `math`
- The `sp` tag makes text spoilered (hidden till interacted with).  
  Example: `[sp]hidden[/sp]` -> a box you can interact with --(interaction)--> "hidden"  
  Aliases: `sp`, `h`, `hidden`, `spoiler`
- The `icode` tag is equivalent to the `code` tag, except for being displayed inline. Essentially, this is the equivalent of Markdown's single and double backtick formatters.  
  Parameters: The one parameter this tag accepts is optionally the language the code is in.  
  Example: `[code=ruby]puts "Hello, world!"[/code]`

### Other BBCode implementation notes

- All `img` and other file-related tags should point to server files, and instead of specifying a filename, should instead specify the file to fetch from the server (i.e. `[img]server.example.com:TXlJbWFnZUlELnBuZwo[/img]`)
- Please be sure to escape any square brackets (`[` and `]`) that are not tags. The most important places to do so are within the `LaTeX` tag and the `code`/`icode` tags.

## Client message writing

When a user writes a message within the client, the client may be configured to accept whichever markup or formatting language it chooses from the user (i.e. plaintext, HTML, (La)TeX, markdown, etc.). Whatever is chosen, however, must be translated into either plaintext or BBCode within the client's codebase before being sent as a message. Clients that send messages in other formats will be marked as noncomplient.

It is reccomended to allow the user to write messages in both markdown and bbcode, though neither are required.

