(state: StateBlock, startLine: int, endLine: int, silent: bool)
| 57 | |
| 58 | |
| 59 | def table(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool: |
| 60 | tbodyLines = None |
| 61 | |
| 62 | # should have at least two lines |
| 63 | if startLine + 2 > endLine: |
| 64 | return False |
| 65 | |
| 66 | nextLine = startLine + 1 |
| 67 | |
| 68 | if state.sCount[nextLine] < state.blkIndent: |
| 69 | return False |
| 70 | |
| 71 | if state.is_code_block(nextLine): |
| 72 | return False |
| 73 | |
| 74 | # first character of the second line should be '|', '-', ':', |
| 75 | # and no other characters are allowed but spaces; |
| 76 | # basically, this is the equivalent of /^[-:|][-:|\s]*$/ regexp |
| 77 | |
| 78 | pos = state.bMarks[nextLine] + state.tShift[nextLine] |
| 79 | if pos >= state.eMarks[nextLine]: |
| 80 | return False |
| 81 | first_ch = state.src[pos] |
| 82 | pos += 1 |
| 83 | if first_ch not in ("|", "-", ":"): |
| 84 | return False |
| 85 | |
| 86 | if pos >= state.eMarks[nextLine]: |
| 87 | return False |
| 88 | second_ch = state.src[pos] |
| 89 | pos += 1 |
| 90 | if second_ch not in ("|", "-", ":") and not isStrSpace(second_ch): |
| 91 | return False |
| 92 | |
| 93 | # if first character is '-', then second character must not be a space |
| 94 | # (due to parsing ambiguity with list) |
| 95 | if first_ch == "-" and isStrSpace(second_ch): |
| 96 | return False |
| 97 | |
| 98 | while pos < state.eMarks[nextLine]: |
| 99 | ch = state.src[pos] |
| 100 | |
| 101 | if ch not in ("|", "-", ":") and not isStrSpace(ch): |
| 102 | return False |
| 103 | |
| 104 | pos += 1 |
| 105 | |
| 106 | lineText = getLine(state, startLine + 1) |
| 107 | |
| 108 | columns = lineText.split("|") |
| 109 | aligns = [] |
| 110 | for i in range(len(columns)): |
| 111 | t = columns[i].strip() |
| 112 | if not t: |
| 113 | # allow empty columns before and after table, but not in between columns; |
| 114 | # e.g. allow ` |---| `, disallow ` ---||--- ` |
| 115 | if i == 0 or i == len(columns) - 1: |
| 116 | continue |
nothing calls this directly
no test coverage detected
searching dependent graphs…