.txt files should not be interpreted as Markdown.

This commit is contained in:
Julien Palard 2023-04-25 22:12:48 +02:00
parent 1f6a43803e
commit ccfec0affc
Signed by: mdk
GPG Key ID: 0EFC1AC1006886F8
3 changed files with 17 additions and 4 deletions

View File

@ -30,6 +30,15 @@ other. So to create one for your instance, just paste something to it, like:
The `Authorization` allows you to update the paste by uploading it again.
### I want a robots.txt
Just past it:
$ printf "User-agent: *\nDisallow: /\n" | curl localhost:8000/robots.txt -XPUT -H "Authorization: Secret supersecret" --data-binary @-
It'll work as `.txt` files are not pretty printed.
### Where's the admin?
The admin is hosted as `/::/admin/`. As almost any URL can be used by pastes, we "burry" the admin here.

View File

@ -53,7 +53,9 @@ class PasteView(View):
paste = get_object_or_404(Paste, slug=path)
paste.incr_viewcount()
if "html" in request.headers.get("accept", "html"):
if "html" in request.headers.get(
"accept", "html"
) and not paste.filename.endswith(".txt"):
return HttpResponse(paste_to_html(paste.filename, paste.content))
else:
return HttpResponse(paste.content, content_type="text/plain")
@ -138,7 +140,7 @@ class ListView(View):
def paste_to_html(filename, filecontents):
data = {}
data["filename"] = filename
if filename.endswith(".md") or filename.endswith(".txt") or "." not in filename:
if filename.endswith(".md") or "." not in filename:
data["highlighted"] = markdown_to_html(filecontents)
return loader.render_to_string("paste/show-markdown.html", data)
else:

View File

@ -69,8 +69,10 @@ $ curl https://p.afpy.org/ -Fmanage.py=@manage.py -Frequirements.txt=@requiremen
Cest lextension dans le nom du fichier qui permet de choisir la
coloration syntaxique pour chaque fichier.
Les fichiers texte sont interprétés en Markdown lors de laffichage
dans un navigateur.
Les fichiers texte sont rendus en `plain/text`, donc sans coloration syntaxique.
Les fichiers `.md` et les fichiers sans extension sont interprétés en
Markdown lors de laffichage dans un navigateur.
Les fichiers sont toujours rendus tels quels lorsquils sont récupérés
hors dun navigateur, typiquement via `wget` ou `curl`.