export const metadata = {
title: 'ContentFormat',
description: 'Definition of the ContentFormat structure',
}
# ContentFormat
The `ContentFormat` structure is used to represent content with metadata. It supports multiple content types for the same file, such as a PNG image and a WebP image. {{ className: 'lead' }}
A `ContentFormat` structure is defined as follows:
```typescript
type ContentType = `${string}/${string}`;
type ContentFormat = {
[key: ContentType]: {
...
};
}
```
Each piece of data in the `ContentFormat` structure is meant to be a different representation of the same content. For example, a PNG image and its WebP version are different representations of the same image. Do not mix unrelated files or data in the same `ContentFormat` structure.
**Good:**
```json
{
"image/png": {
...
},
"image/webp": {
...
}
}
```
**Bad:**
```json
{
"image/png": {
...
},
"application/json": {
...
}
}
```
## Implementation Guidelines
### Text
Implementations should always process text content with the richest format available, such as HTML. However, they should also provide other formats like plain text and Markdown for compatibility with other systems.
HTML is the recommended content type for text content, and as such every text content should have an HTML representation. If the content is not HTML, it should be converted to HTML using appropriate conversion rules.
Rich formats include:
- `text/html`
- `text/markdown`
- `text/x.misskeymarkdown` (Misskey Flavoured Markdown, common on ActivityPub)
Clients should display the richest possible format available. If the client does not support the richest format, it should fall back to the next richest format.
### Images
It is a good idea to provide at least two versions of an image (if possible): one in the original format and another in a more efficient format like WebP/AVIF. This allows clients to choose the most suitable format based on their capabilities.
## Entity Definition
Structure data. If `Content-Type` is a binary format, this field should be a URI to the binary data. Otherwise, it should be the content itself. Refer to the `remote` property for more information.
If `true`, the content is hosted remotely and should be fetched by the client. If `false`, the content is embedded in the entity.
A human-readable description of the content. Also known as `alt` text.
Size of the content in bytes.
Hash of the content.
```typescript
type HashNames = "sha256" | "sha512" | "sha3-256" | "sha3-512" | "blake2b-256" | "blake2b-512" | "blake3-256" | "blake3-512" | "md5" | "sha1" | "sha224" | "sha384" | "sha3-224" | "sha3-384" | "blake2s-256" | "blake2s-512" | "blake3-224" | "blake3-384";
type Hash = {
[key in HashNames]: string;
}
```
Image in [BlurHash](https://blurha.sh/) format.
Width of the content in pixels. Only applicable to content types that have a width.
Height of the content in pixels. Only applicable to content types that have a height.
Frames per second. Only applicable to video content.
Duration of the content in seconds. Only applicable to content types that have a duration.
```jsonc {{ 'title': 'Images' }}
{
"image/png": {
"content": "https://cdn.example.com/attachments/ece2f9d9-27d7-457d-b657-4ce9172bdcf8.png",
"remote": true,
"description": "A jolly horse running through mountains",
"size": 453933,
"hash": {
"sha256": "91714fc336210d459d4f9d9233de663be2b87ffe923f1cfd76ece9d06f7c965d"
},
"blurhash": "UUKJ^v~q9G%L~qRj9GofRjofRjof",
"width": 1920,
"height": 1080
}
}
```
```jsonc {{ 'title': 'Text Formats' }}
{
"text/plain": {
"content": "The consequences of today are determined by the actions of the past. To change your future, alter your decisions today.",
"remote": false
},
"text/markdown": {
"content": "> The consequences of today are determined by the actions of the past.\n> To change your future, alter your decisions today.",
"remote": false
},
"text/html": {
"content": "
The consequences of today are determined by the actions of the past.
To change your future, alter your decisions today.