Strange org mode source code blocks effect

I have been using Org as the format for blog posts, and I have a question about the way source code blocks are handled. If I use the following:

#+BEGIN_SRC python
  def main():
      pass
#+END_SRC

when looking at the page source, I see the following:

<pre><code class="language-python">
  def main():
      pass
</code></pre>

When I use what I would use in a markdown file, I get the correct result, with source:

<div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span></span><span style="color: #66d9ef">def</span> <span style="color: #a6e22e">main</span><span style="color: #f8f8f2">():</span>
    <span style="color: #66d9ef">pass</span>
</pre></div>

And I can even do things like:

{{< highlight python "linenos=inline,hl_lines=2 3" >}}
def main():
    i = 2
    j = 3
    pass
{{< / highlight >}}

with source:

<p><div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span></span><span style="background-color: #f0f0f0; padding: 0 5px 0 5px">1 </span><span style="color: #66d9ef">def</span> <span style="color: #a6e22e">main</span><span style="color: #f8f8f2">():</span>
<span style="background-color: #f0f0f0; padding: 0 5px 0 5px">2 </span><span style="background-color: #49483e">    <span style="color: #f8f8f2">i</span> <span style="color: #f92672">=</span> <span style="color: #ae81ff">2</span>
</span><span style="background-color: #f0f0f0; padding: 0 5px 0 5px">3 </span><span style="background-color: #49483e">    <span style="color: #f8f8f2">j</span> <span style="color: #f92672">=</span> <span style="color: #ae81ff">3</span>
</span><span style="background-color: #f0f0f0; padding: 0 5px 0 5px">4 </span>    <span style="color: #66d9ef">pass</span>
</pre></div>
</p>

Here is an image of the three effect, in order:

I wanted to ask if anyone had managed to fix the code block’s export so that it gives the correct effect (i.e. no spacing before the code, no extra space in the first line, etc.). I think that it should produce the same output as the markdown code. Secondarily, I wanted to ask if there was some way to give the same information about line numbers and highlighted lines as in the markdown example in the org mode code block.

Just to give some information, I don’t think that it is a problem with Hugo, but rather an issue with how client side syntax highlighting with highlight.js handles the newline after the “code” opening tag (https://github.com/jekyll/jekyll-help/issues/191). A possible temporary solution could be this (https://stackoverflow.com/questions/14946908/how-can-i-ignore-leading-and-trailing-linebreaks-within-an-html-code-block-usi).