Remove annotations from YAML without changing a text block
Admin ·
The same hash sign can mark an annotation, introduce a color value inside a string or form part of a multi-line message. Its position in the parsed document determines how it is handled.
Keep a color and remove its annotation
Enter accent: "#336699" followed on the same line by a space and # button accent. After removal, the accent string is still #336699. A plain value such as item#2 also keeps its hash because the hash belongs to the scalar.
Check a multi-line message
Start a message with caption: | and indent the next line by two spaces before typing # visible text. That line is the message content. A separate annotation after the block can be removed while retaining the hash inside the message. The tool checks parsed values again before exposing the result.
Keep a URL fragment and a literal instruction
The # in the quoted URL and the one in the block of instructions are user data. Only the note following the quoted value is a YAML comment.
url: "https://example.org/ticket#history" # old route
instruction: |
enter # for a ticket- After removing comments, parse the result. The URL must retain #history and the instruction must retain enter # for a ticket. A line-based replacement starting at every hash would truncate both values.
Common questions
Does the remover reformat numbers?
It works on the comment spans in the original source. Numeric tokens and quoted scalar values retain their spelling.
Why can some blank lines disappear?
A removed annotation may separate a literal block from following blank lines. The tool can remove adjacent blank lines when needed to keep the decoded value of the block unchanged.