# `Kotoba.CodeLanguages`
[🔗](https://github.com/hattoriai/kotoba/blob/v0.5.0/lib/kotoba/code_languages.ex#L1)

The code languages of the editor: the ones that it highlights and that its
language picker offers.

| Id | Label | Aliases |
| -- | ----- | ------- |
| `bash` | Bash | `sh`, `shell`, `zsh` |
| `c` | C |  |
| `cpp` | C++ | `c++` |
| `css` | CSS |  |
| `diff` | Diff | `patch` |
| `dockerfile` | Dockerfile | `docker` |
| `elixir` | Elixir | `ex`, `exs` |
| `erlang` | Erlang | `erl` |
| `go` | Go | `golang` |
| `graphql` | GraphQL | `gql` |
| `html` | HTML | `htm`, `markup` |
| `java` | Java |  |
| `javascript` | JavaScript | `js`, `mjs`, `cjs` |
| `json` | JSON |  |
| `kotlin` | Kotlin | `kt`, `kts` |
| `markdown` | Markdown | `md` |
| `objectivec` | Objective-C | `objc` |
| `php` | PHP |  |
| `powershell` | PowerShell | `ps1`, `pwsh` |
| `python` | Python | `py` |
| `ruby` | Ruby | `rb` |
| `rust` | Rust | `rs` |
| `sql` | SQL |  |
| `swift` | Swift |  |
| `toml` | TOML |  |
| `typescript` | TypeScript | `ts` |
| `xml` | XML | `svg` |
| `yaml` | YAML | `yml` |

A code block stores the name of its language: an id, an alias (a block
pasted or imported with `yml` keeps `yml`), or any other name. The
editor highlights the ids and the aliases; the picker shows the language
of an alias, and writes the id when the person picks a language. A block
with no language, or with `plain` (`text`, `txt`, `plaintext`), is plain
text. A name that is not a language is kept, and it is not highlighted:
the picker shows it as "(not highlighted)". Prism knows the names in lower
case: a block with `Elixir` is kept and shown as Elixir, but not
highlighted.

`Kotoba.Components.kotoba/1` takes a `code_languages` list of ids, the
languages of its picker. The editor's `assets/src/code_languages.ts` has
the same table; a test compares the two.

# `language`

```elixir
@type language() :: %{id: String.t(), label: String.t(), aliases: [String.t()]}
```

A code language: its id, its label and its aliases.

# `all`

```elixir
@spec all() :: [language()]
```

Returns the languages, in the order of the picker.

## Examples

    iex> length(Kotoba.CodeLanguages.all()) >= 20
    true

# `find`

```elixir
@spec find(String.t() | nil) :: language() | nil
```

Returns the language of a name, an id or an alias in any case, or `nil`
for a name that is not a language (plain text included).

## Examples

    iex> Kotoba.CodeLanguages.find("yml").id
    "yaml"

    iex> Kotoba.CodeLanguages.find("Elixir").label
    "Elixir"

    iex> Kotoba.CodeLanguages.find("cobol")
    nil

# `ids`

```elixir
@spec ids() :: [String.t()]
```

Returns the ids of the languages, in the order of the picker.

## Examples

    iex> "elixir" in Kotoba.CodeLanguages.ids()
    true

# `ids!`

```elixir
@spec ids!([String.t() | atom()]) :: [String.t()]
```

Returns the ids for a list of ids or aliases, in order and once each, for
the `code_languages` attribute of `Kotoba.Components.kotoba/1`.

Raises `ArgumentError` for a name that is not a language.

## Examples

    iex> Kotoba.CodeLanguages.ids!(["elixir", "js", "ex"])
    ["elixir", "javascript"]

---

*Consult [api-reference.md](api-reference.md) for complete listing*
