Returns the start/stop indices enclosing the paragraph that mark is in. Also returns the comment format string, if any, and paragraph of text between the start/stop indices.
(text, mark)
| 81 | FormatParagraph.reload() |
| 82 | |
| 83 | def find_paragraph(text, mark): |
| 84 | """Returns the start/stop indices enclosing the paragraph that mark is in. |
| 85 | |
| 86 | Also returns the comment format string, if any, and paragraph of text |
| 87 | between the start/stop indices. |
| 88 | """ |
| 89 | lineno, col = map(int, mark.split(".")) |
| 90 | line = text.get("%d.0" % lineno, "%d.end" % lineno) |
| 91 | |
| 92 | # Look for start of next paragraph if the index passed in is a blank line |
| 93 | while text.compare("%d.0" % lineno, "<", "end") and is_all_white(line): |
| 94 | lineno = lineno + 1 |
| 95 | line = text.get("%d.0" % lineno, "%d.end" % lineno) |
| 96 | first_lineno = lineno |
| 97 | comment_header = get_comment_header(line) |
| 98 | comment_header_len = len(comment_header) |
| 99 | |
| 100 | # Once start line found, search for end of paragraph (a blank line) |
| 101 | while get_comment_header(line)==comment_header and \ |
| 102 | not is_all_white(line[comment_header_len:]): |
| 103 | lineno = lineno + 1 |
| 104 | line = text.get("%d.0" % lineno, "%d.end" % lineno) |
| 105 | last = "%d.0" % lineno |
| 106 | |
| 107 | # Search back to beginning of paragraph (first blank line before) |
| 108 | lineno = first_lineno - 1 |
| 109 | line = text.get("%d.0" % lineno, "%d.end" % lineno) |
| 110 | while lineno > 0 and \ |
| 111 | get_comment_header(line)==comment_header and \ |
| 112 | not is_all_white(line[comment_header_len:]): |
| 113 | lineno = lineno - 1 |
| 114 | line = text.get("%d.0" % lineno, "%d.end" % lineno) |
| 115 | first = "%d.0" % (lineno+1) |
| 116 | |
| 117 | return first, last, comment_header, text.get(first, last) |
| 118 | |
| 119 | # This should perhaps be replaced with textwrap.wrap |
| 120 | def reformat_paragraph(data, limit): |
no test coverage detected
searching dependent graphs…