Blocs de code
Rouge fournit de nombreux "indices" de blocs de code différents. Si vous omettez l'indice, il essaie de deviner et se trompe parfois. Ce ne sont que quelques indices que nous utilisons souvent.
Variables
Si votre exemple contient une valeur de remplacement susceptible de changer,
utilisez le format <[A-Z_]+>
pour la valeur de remplacement : <MA_VARIABLE>
export name=<MON_NOM>
Cette syntaxe est réservée aux noms de variables et entraînera le rendu de la variable dans une couleur et un style de police spéciaux.
Surligner des lignes
incoming := map[string]interface{}{
"asdf": 1,
"qwer": []interface{}{},
"zxcv": []interface{}{
map[string]interface{}{},
true,
int(1e9),
"tyui",
},
}
```go {hl_lines=[7,8]}
incoming := map[string]interface{}{
"asdf": 1,
"qwer": []interface{}{},
"zxcv": []interface{}{
map[string]interface{}{},
true,
int(1e9),
"tyui",
},
}
```
Blocs de code réductibles
# syntax=docker/dockerfile:1
ARG GO_VERSION="1.21"
FROM golang:${GO_VERSION}-alpine AS base
ENV CGO_ENABLED=0
ENV GOPRIVATE="github.com/foo/*"
RUN apk add --no-cache file git rsync openssh-client
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
WORKDIR /src
FROM base AS vendor
# cette étape configure git et vérifie que la clé ssh est chargée
RUN --mount=type=ssh <<EOT
set -e
echo "Setting Git SSH protocol"
git config --global url."[email protected]:".insteadOf "https://github.com/"
(
set +e
ssh -T [email protected]
if [ ! "$?" = "1" ]; then
echo "No GitHub SSH key loaded exiting..."
exit 1
fi
)
EOT
# celle-ci télécharge les modules go
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=ssh \
go mod download -x
FROM vendor AS build
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache \
go build ...
Bash
Utilisez le bloc de code de langue bash
lorsque vous voulez montrer un script Bash :
#!/usr/bin/bash
echo "deb https://download.docker.com/linux/ubuntu noble stable" | sudo tee /etc/apt/sources.list.d/docker.list
Si vous voulez montrer un shell interactif, utilisez console
à la place.
Dans les cas où vous utilisez console
, assurez-vous d'ajouter un caractère dollar
pour le signe de l'utilisateur :
$ echo "deb https://download.docker.com/linux/ubuntu noble stable" | sudo tee /etc/apt/sources.list.d/docker.list
Go
incoming := map[string]interface{}{
"asdf": 1,
"qwer": []interface{}{},
"zxcv": []interface{}{
map[string]interface{}{},
true,
int(1e9),
"tyui",
},
}
PowerShell
Install-Module DockerMsftProvider -Force
Install-Package Docker -ProviderName DockerMsftProvider -Force
[System.Environment]::SetEnvironmentVariable("DOCKER_FIPS", "1", "Machine")
Expand-Archive docker-18.09.1.zip -DestinationPath $Env:ProgramFiles -Force
Python
return html.format(name=os.getenv('NAME', "world"), hostname=socket.gethostname(), visits=visits)
Ruby
docker_service 'default' do
action [:create, :start]
end
JSON
"server": {
"http_addr": ":4443",
"tls_key_file": "./fixtures/notary-server.key",
"tls_cert_file": "./fixtures/notary-server.crt"
}
HTML
<!DOCTYPE html>
<html>
<head>
<title>Bienvenue sur nginx !</title>
</head>
</html>
Markdown
# Bonjour
Si vous voulez inclure un bloc de code à triple barrière à l'intérieur de votre bloc de code, vous pouvez envelopper votre bloc dans un bloc de code à quadruple barrière :
````markdown
# Bonjour
```go
log.Println("did something")
```
````
ini
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
Dockerfile
# syntax=docker/dockerfile:1
FROM ubuntu
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
# Note : Les images officielles Debian et Ubuntu effectuent automatiquement un ``apt-get clean``
# après chaque ``apt-get``
USER postgres
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\
createdb -O docker docker
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
EXPOSE 5432
VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
YAML
authorizedkeys:
image: dockercloud/authorizedkeys
deployment_strategy: every_node
autodestroy: always
environment:
- AUTHORIZED_KEYS=ssh-rsa AAAAB3Nsomelongsshkeystringhereu9UzQbVKy9o00NqXa5jkmZ9Yd0BJBjFmb3WwUR8sJWZVTPFL
volumes:
/root:/user:rw