Kotoba.CodeLanguages (Kotoba v0.5.0)

Copy Markdown View Source

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

IdLabelAliases
bashBashsh, shell, zsh
cC
cppC++c++
cssCSS
diffDiffpatch
dockerfileDockerfiledocker
elixirElixirex, exs
erlangErlangerl
goGogolang
graphqlGraphQLgql
htmlHTMLhtm, markup
javaJava
javascriptJavaScriptjs, mjs, cjs
jsonJSON
kotlinKotlinkt, kts
markdownMarkdownmd
objectivecObjective-Cobjc
phpPHP
powershellPowerShellps1, pwsh
pythonPythonpy
rubyRubyrb
rustRustrs
sqlSQL
swiftSwift
tomlTOML
typescriptTypeScriptts
xmlXMLsvg
yamlYAMLyml

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.

Summary

Types

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

Functions

Returns the languages, in the order of the picker.

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).

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

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.

Types

language()

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

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

Functions

all()

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

Returns the languages, in the order of the picker.

Examples

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

find(name)

@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()

@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!(names)

@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"]