From 8fbb6d29d83dae47db52cd3a2bb529e14aee22c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 13 Aug 2025 19:21:27 +0200 Subject: [PATCH] [docs/formatting] update / improve - add table of contents - use more links - reword & reformat general description text - use HTML entities for double curly braces to prevent Jekyll from interpreting them as template expressions --- docs/formatting.md | 51 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/docs/formatting.md b/docs/formatting.md index 503cb84d..8387a731 100644 --- a/docs/formatting.md +++ b/docs/formatting.md @@ -1,8 +1,38 @@ # String Formatting + +## Table of Contents + +* [Basics](#basics) +* [Field Names](#field-names) +* [Conversions](#conversions) +* [Format Specifiers](#format-specifiers) +* [Global Replacement Fields](#global-replacement-fields) +* [Special Type Format Strings](#special-type-format-strings) + + +## Basics + Format strings in gallery-dl follow the general rules of [`str.format()`](https://docs.python.org/3/library/string.html#format-string-syntax) ([PEP 3101](https://www.python.org/dev/peps/pep-3101/)) plus several extras. -The syntax for replacement fields is `{!:}`, where `!` and `:` are both optional and can be used to specify how the value selected by `` should be transformed. +The syntax for replacement fields is +``` +{!:} +``` +where +[``](#field-names) +selects a value +
+and the optional +[`!`](#conversions) +& +[`:`](#format-specifiers) +specify how to transform it. + +Examples: +* `{title}` +* `{content!W}` +* `{date:Olocal/%Y%m%d %H%M}` ## Field Names @@ -62,7 +92,8 @@ While simple names are usually enough, more complex forms like accessing values -All of these methods can be combined as needed. +All of these methods can be combined. +
For example `{title[24]|empty|extractor.url[15:-1]}` would result in `.org`. @@ -178,19 +209,19 @@ Conversion specifiers allow to *convert* the value to a different form or type. S - Convert value to str while providing a human-readable representation for lists + Convert value to str while providing a human-readable representation for lists {tags!S} sun, tree, water r - Convert value to str using repr() + Convert value to str using repr() a - Convert value to str using ascii() + Convert value to str using ascii() @@ -309,11 +340,15 @@ Format specifiers can be used for advanced formatting by using the options provi 2010-01-01 00:00:00 - O<offset>/ - Apply <offset> to a datetime object, either as ±HH:MM or local for local UTC offset + O<offset>/ + Apply <offset> to a datetime object, either as ±HH:MM or local for local UTC offset {date:O-06:30/} 2009-12-31 17:30:00 + + {date:Olocal/} + 2010-01-01 01:00:00 + @@ -400,7 +435,7 @@ Starting a format string with `\f ` allows to set a different format strin J A Jinja template - \fJ '{{title | trim}}' by {{artist | capitalize}} + \fJ '{{title | trim}}' by {{artist | capitalize}} T