Apply transforms to a post body, skipping code blocks, tables, indented code, and lines that are entirely a shortcode.
(body, opts, counts)
| 100 | |
| 101 | |
| 102 | def transform_body(body, opts, counts): |
| 103 | """Apply transforms to a post body, skipping code blocks, tables, indented |
| 104 | code, and lines that are entirely a shortcode.""" |
| 105 | lines = body.split("\n") |
| 106 | in_fence = False |
| 107 | out = [] |
| 108 | for line in lines: |
| 109 | if _FENCE_RE.match(line): |
| 110 | in_fence = not in_fence |
| 111 | out.append(line) |
| 112 | continue |
| 113 | if in_fence: |
| 114 | out.append(line) |
| 115 | continue |
| 116 | # Indented code (4+ spaces) and table rows are left verbatim. |
| 117 | if re.match(r"^ {4,}\S", line) or line.lstrip().startswith("|"): |
| 118 | out.append(line) |
| 119 | continue |
| 120 | out.append(_transform_line(line, opts, counts)) |
| 121 | return "\n".join(out) |
| 122 | |
| 123 | |
| 124 | def _invariants(body): |
no test coverage detected