Skip to main content

lower_block_string

Function lower_block_string 

Source
pub fn lower_block_string(s: &str) -> String
Expand description

Lower a """...""" block literal to its string value. Escapes and {{ }} pass through verbatim for runtime expand_string. Steps:

  1. Strip the delimiters, normalize \r\n and lone \r to \n.
  2. Leading newline: if the opening """ is followed only by spaces/tabs then a newline, drop through that newline (split_leading_newline). Otherwise the opening line holds inline text ("""text), kept verbatim at zero indent and excluded from prefix computation.
  3. Closing line: if the text holds a newline and the last line is whitespace-only, the closing """ sits on its own line. Pop that line (with its newline) and seat its whitespace as the indentation baseline among the prefix candidates.
  4. Common prefix: longest shared leading-whitespace run across all non-blank content lines. Blank lines never vote. No qualifying line means an empty value.
  5. Strip the prefix from every non-blank line. The inline first line and blank lines pass through untouched.
  6. Rejoin the lines with \n.