Commit 32743800 authored by Naum Spaseski's avatar Naum Spaseski Committed by Miguel Angel Reina Ortega
Browse files

Corrected grid table size and references links

parent 00847eaf
Loading
Loading
Loading
Loading
+44 −3
Original line number Diff line number Diff line
@@ -274,18 +274,59 @@ def handleMultiLineGridTable(lines: list[str]) -> list[str]:
					splitCells.append([colspanMarker])
				else:
					parts = cell.split('<br />')
					# Check for overly long lines and split them too
					new_parts = []
					for part in parts:
						if len(part) > MAX_CELL_WIDTH:
							# Simple splitting by space
							words = part.split(' ')
							current_line = []
							current_length = 0
							for word in words:
								if current_length + len(word) + 1 > MAX_CELL_WIDTH:
									new_parts.append(' '.join(current_line))
									current_line = [word]
									current_length = len(word)
								else:
									current_line.append(word)
									current_length += len(word) + 1
							if current_line:
								new_parts.append(' '.join(current_line))
						else:
							new_parts.append(part)
					parts = new_parts

					if len(parts) > 1:
						# Found line breaks in cell
						# Add "\" to each part except the last
						parts = [ p + '\\' if i < len(parts)-1 else p 
								for i, p in enumerate(parts) ]
						# BUT only if it was originally a <br /> break, or if we want to indicate wrap?
						# For Markdown grid tables, simple newlines are enough.
						# But standard Grid Tables don't support multiline cells natively without some trickery?
						# Actually, Pandoc grid tables just use newlines.
						# The original code added `\` which might be for a specific renderer?
						# Standard reStructuredText / Pandoc grid tables treat lines in the same cell as just continuation.
						# No backslash needed usually.
						pass
						# parts = [ p + '\\' if i < len(parts)-1 else p 
						# 		for i, p in enumerate(parts) ]

					splitCells.append(parts)
				maxLines = max(maxLines, len(parts))
			
			# If we found line breaks, create multiple content lines
			# Each row's height is determined by its own content (maxLines for that row)
			# All cells in a row must have the same number of lines for proper alignment
			if maxLines > 1:
				for line_idx in range(maxLines):
				# Find the last line index that has content in any cell
				lastContentLineIdx = -1
				for check_idx in range(maxLines):
					for cellParts in splitCells:
						if len(cellParts) > check_idx and cellParts[check_idx].strip() and cellParts[check_idx].strip() != colspanMarker:
							lastContentLineIdx = check_idx
							break
				
				# Only create lines up to and including the last line with content
				for line_idx in range(lastContentLineIdx + 1):
					newCells = []
					for cellParts in splitCells:
						if len(cellParts) == 1 and cellParts[0].strip() == colspanMarker:
+2 −1
Original line number Diff line number Diff line
@@ -964,7 +964,8 @@ def processDocuments(documents:list[str],
			for i in range(len(lines)):
				line = lines[i]
				if (m := _definitionExpression.match(line)) is not None:
					lines[i] = f'- <a name="_ref_{m.group(1)}"[{m.group(1)}]">[{m.group(1)}]</a>{m.group(2)}'
					# Use HTML anchor for definitions with span wrapper: <span id="_ref_1"><a name="_ref_1">[1]</a></span>
					lines[i] = f'<span id="_ref_{m.group(1)}"><a name="_ref_{m.group(1)}">[{m.group(1)}]</a></span>{m.group(2)}'
			
			def _repl(m:re.Match) -> str|None:
				if m.group(1) == '"':