Skip to content

fix: update post_cell function to handle different newline characters in cell values#2972

Merged
liuruibin merged 1 commit intomainfrom
pr@main@fix_some_bugs
Apr 24, 2025
Merged

fix: update post_cell function to handle different newline characters in cell values#2972
liuruibin merged 1 commit intomainfrom
pr@main@fix_some_bugs

Conversation

@shaohuzhang1
Copy link
Copy Markdown
Contributor

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

… in cell values

--bug=1054683 --user=刘瑞斌 【github#2831】知识库上传excel、应用编排文档内容提取节点中上传excel,单元格中有换行,导入后没有在一个单元格里显示 https://www.tapd.cn/57709429/s/1690232
@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Apr 24, 2025

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.

Details

Instructions 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.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Apr 24, 2025

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

return cell_value.replace('\r\n', '<br>').replace('\n', '<br>').replace('|', '&#124;')


def row_to_md(row):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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('|', '&#124;')
+    return cell_value.replace('\r\n', '<br>').replace('\n', '<br>').replace('\t', '&nbsp;')  # Add this line to replace tabs with spaces

Explanation:

  1. Replacement of \n: Both \n and \r\n are used to denote line breaks in text. By replacing both \n and \r\n, you ensure consistency across different newline characters.

  2. 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.

  3. Potential Issues:

    • If the input data contains only \ts without any newlines, post_cell will 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.

By adding the replacement for \t, you handle more edge cases and ensure that the converted markup preserves consistent spacing and structure.

@liuruibin liuruibin merged commit 8d503c8 into main Apr 24, 2025
4 of 5 checks passed
@liuruibin liuruibin deleted the pr@main@fix_some_bugs branch April 24, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants