Unwanted blank added when pasting code into code block

Steps to reproduce

  1. copy python code from other place.
  2. paste the code into a code block.

The procedure will inserting another blank line between any two original code. An example I just pasted a minute ago.

class Solution:

    def sortedArrayToBST(self, nums: List[int]) -> TreeNode:

        def helper(left, right):

            if left > right:

                return None

  

            # 总是选择中间位置左边的数字作为根节点

            mid = (left + right) // 2

  

            root = TreeNode()

            root.left = helper(left, mid - 1)

  

            root.right = helper(mid + 1, right)

            root.val = nums[mid]

            return root

  

        return helper(0, len(nums) - 1)

Expected result

It shoud not insert extra spaces. Just like this:

class Solution:
    def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
        def helper(left, right):
            if left > right:
                return None

            # 总是选择中间位置左边的数字作为根节点
            mid = (left + right) // 2

            root = TreeNode()
            root.left = helper(left, mid - 1)

            root.right = helper(mid + 1, right)
            root.val = nums[mid]
            return root

        return helper(0, len(nums) - 1)

Environment

  • Windows 11, Obisidian 0.15.8
1 Like

Yes, this is pretty irritating, isn’t it? I think this has been brought up before, and what you need to do is ‘paste without formatting’ (Ctrl+shift+v on Windows IIRC). I need to remember that more often myself.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.