(out io.Writer, s textScanner, run commandRunner)
| 99 | type codeParser struct{ print bool } |
| 100 | |
| 101 | func (c codeParser) parse(out io.Writer, s textScanner, run commandRunner) (state, error) { |
| 102 | if c.print { |
| 103 | fmt.Fprintln(out, s.Text()) |
| 104 | } |
| 105 | if !s.Scan() { |
| 106 | return nil, fmt.Errorf("unbalanced code section") |
| 107 | } |
| 108 | if !strings.HasPrefix(s.Text(), "```") { |
| 109 | return c.parse, nil |
| 110 | } |
| 111 | |
| 112 | // print the end of the code section if needed and go back to parsing text. |
| 113 | if c.print { |
| 114 | fmt.Fprintln(out, s.Text()) |
| 115 | } |
| 116 | return parsingText, nil |
| 117 | } |