Text Proto Formatter - Configuration
April 20, 2026 ยท View on GitHub
txtpbfmt provides several configuration options that customize the specifics
of the output format. These are configured by adding a comment line to top of
the proto file (before the first non-empty non-comment line) of the form:
# txtpbfmt: [config-option]
This doc describes each of these options.
AllowTripleQuotedStrings
# txtpbfmt: allow_triple_quoted_strings
Permit usage of Python-style """ or ''' delimited strings.
AllowUnnamedNodesEverywhere
# txtpbfmt: allow_unnamed_nodes_everywhere
Allow unnamed nodes everywhere. Default is to allow only top-level nodes to be unnamed.
ExpandAllChildren
# txtpbfmt: expand_all_children
Expand all children irrespective of the initial state.
Before formatting
After formatting
PreserveAngleBrackets
# txtpbfmt: preserve_angle_brackets
Whether angle brackets used instead of curly braces should be preserved when outputting a formatted textproto.
Before formatting
After formatting
RemoveDuplicateValuesForRepeatedFields
# txtpbfmt: remove_duplicate_values_for_repeated_fields
Remove lines that have the same field name and scalar value as another.
Before formatting
After formatting
SkipAllColons
# txtpbfmt: skip_all_colons
Skip colons whenever possible.
Before formatting
After formatting
SmartQuotes
# txtpbfmt: smartquotes
Use single quotes around strings that contain double but not single quotes.
Before formatting
After formatting
SortFieldsByFieldName
# txtpbfmt: sort_fields_by_field_name
Sort fields by field name.
Before formatting
After formatting
SortRepeatedFieldsByContent
# txtpbfmt: sort_repeated_fields_by_content
Sort adjacent scalar fields of the same field name by their contents.
Before formatting
After formatting
SortRepeatedFieldsBySubfield
# txtpbfmt: sort_repeated_fields_by_subfield=[subfieldSpec]
Sort adjacent message fields of the given field name by the contents of the given subfield path.
subfieldSpec is of one of two forms:
-
fieldName.subfieldName1.subfieldName2...subfieldNameN, which will sort fields namedfieldNameby the value of the final subfield namedsubfieldNameN. -
subfieldName, which will sort any field by its subfield namedsubfieldName
Before formatting
After formatting
FieldSortOrder
# txtpbfmt: field_sort_order=[NodeName]:[field1] [field2] ...
Specify a custom sort order for fields within a specific node type. NodeName
is the name of the message node. Use __ROOT__ to specify the sort order for
top-level fields in the file. Fields not listed will bubble to the top (unless
require_field_sort_order_to_match_all_fields_in_node is set).
Example
# txtpbfmt: field_sort_order=MyNode:foo bar baz
MyNode {
bar: 1
foo: 2
baz: 3
}
After formatting:
# txtpbfmt: field_sort_order=MyNode:foo bar baz
MyNode {
foo: 2
bar: 1
baz: 3
}
RequireFieldSortOrderToMatchAllFieldsInNode
# txtpbfmt: require_field_sort_order_to_match_all_fields_in_node
Enforce that all fields present in a node must be specified in the
field_sort_order for that node. If a field is found that is not in the sort
order, formatting will fail with an error.
ReverseSort
# txtpbfmt: reverse_sort
Sorts all sort_* fields in descending order instead of the default ascending
order. Does nothing if not used with at least 1 other sort_* field.
Before formatting
After formatting
DNSSortOrder
# txtpbfmt: dns_sort_order
When sorting field contents, sorts in a way intended for DNS names. It splits
the contents on '.' characters, reverses the substrings, and sorts on their
concatenation. This puts, e.g., a.com and c.com next to each other even if
b.au is in the list.
Before formatting
After formatting
WrapHTMLStrings
# txtpbfmt: wrap_html_strings
Whether strings that appear to contain HTML tags should be wrapped (requires WrapStringsAtColumn to be set).
Before formatting
After formatting
WrapStringsAtColumn
# txtpbfmt: wrap_strings_at_column=[column]
Max columns for string field values. If zero, no string wrapping will occur.
Strings that may contain HTML tags will not be wrapped unless
wrap_html_strings is also specified.