fix: update post_cell function to handle different newline characters in cell values#2972
fix: update post_cell function to handle different newline characters in cell values#2972
Conversation
… in cell values --bug=1054683 --user=刘瑞斌 【github#2831】知识库上传excel、应用编排文档内容提取节点中上传excel,单元格中有换行,导入后没有在一个单元格里显示 https://www.tapd.cn/57709429/s/1690232
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| return cell_value.replace('\r\n', '<br>').replace('\n', '<br>').replace('|', '|') | ||
|
|
||
|
|
||
| def row_to_md(row): |
There was a problem hiding this comment.
The provided code is mostly correct but has a small issue with handling line breaks (\t):
@@ -14,7 +14,7 @@
def post_cell(cell_value):
- return cell_value.replace('\n', '<br>').replace('|', '|')
+ return cell_value.replace('\r\n', '<br>').replace('\n', '<br>').replace('\t', ' ') # Add this line to replace tabs with spacesExplanation:
-
Replacement of
\n: Both\nand\r\nare used to denote line breaks in text. By replacing both\nand\r\n, you ensure consistency across different newline characters. -
Handling Tabs: The code currently replaces tabs (`\t
) with` (non-breaking space). This may be necessary if tabular data needs to preserve its original formatting, especially when converting it to HTML or Markdown where automatic indentation might cause problems. -
Potential Issues:
- If the input data contains only
\ts without any newlines,post_cellwill not work as intended because it relies on\n. - Ensuring that all relevant whitespace characters (including tabs) are handled appropriately can make the function more robust for various inputs.
- If the input data contains only
By adding the replacement for \t, you handle more edge cases and ensure that the converted markup preserves consistent spacing and structure.
fix: update post_cell function to handle different newline characters in cell values --bug=1054683 --user=刘瑞斌 【github#2831】知识库上传excel、应用编排文档内容提取节点中上传excel,单元格中有换行,导入后没有在一个单元格里显示 https://www.tapd.cn/57709429/s/1690232