MimeType

value class MimeType(mimeType: String)

Represents the language and dialect of a source snippet, as an RFC 2046 mime type.

For example, a Kotlin source file may have the mime type text/kotlin. However, if it corresponds to a build.gradle.kts file, we'll also attach the mime parameter role=gradle, resulting in mime type text/kotlin; role=gradle.

For XML resource files, we'll attach other attributes; for example role=manifest for Android manifest files and role=resource for XML resource files. For the latter we may also attach for example folderType=values, and for XML files in general, the root tag, such as text/xml; role=resource; folderType=layout; rootTag=LinearLayout.

This class does not implement all aspects of the RFC; in particular, we don't treat attributes as case-insensitive, and we only support value tokens, not value strings -- neither of these are needed for our purposes.

This is implemented using a value class, such that behind the scenes we're really just passing a String around. This also means we can't initialize related values such as the corresponding Markdown fenced block names, or IntelliJ language id's. Instead, these are looked up via when-tables. When adding a new language, update all lookup methods:

Constructors

Link copied to clipboard
constructor(mimeType: String)

Types

Link copied to clipboard
object Known

Functions

Link copied to clipboard
fun base(): MimeType

Returns just the language portion of the mime type.

Link copied to clipboard
Link copied to clipboard

Is this a Gradle file (which could be in Groovy, or, Kotlin)

Link copied to clipboard

Is the base language for this mime type Java?

Link copied to clipboard

Is the base language for this mime type Kotlin?

Link copied to clipboard

Is this an Android manifest file?

Link copied to clipboard

Is the base language for this mime type a protobuf?

Link copied to clipboard

Is the base language for this mime type a regular expression?

Link copied to clipboard

Is the base language for this mime type SQL?

Link copied to clipboard

Is this a version catalog file (which could be in TOML, or in Groovy)

Link copied to clipboard

Is the base language for this mime type XML?

Link copied to clipboard
open override fun toString(): String