Skip to content

org source block header arguments break syntax highlighting #2269

Closed
jo-tham opened this Issue · 6 comments

3 participants

@jo-tham

Hi,

I searched and haven't seen this reported in other open/closed issues. Let me know if I missing something here.

I am running pandoc as follows

pandoc test.org --from=org --to=html5 --standalone --highlight-style=espresso > test.html

test.org contains:

#+begin_src python :noeval
a = [i for i in range(10)]
print(a) 
#+end_src

#+begin_src python
a = [i for i in range(10)]
print(a)
#+end_src

Code highlighting works only if no header arguments are specified after language identifier. Otherwise the result has syntax highlighting.

here's a veiw of the html conversion on similar test.org
example

Is this known? What is the cause?

@jgm
Owner
jgm commented

The code has:

  opts <- option [] $ enclosedByPair '[' ']' inlineBlockOption

So, it's expecting the options to be enclosed in square brackets. I don't know anything about Org-mode, so maybe this is wrong, but that's why this is happening. @tarleb may be able to help.

@jo-tham

Thank you for that info - this clears some things up. I should add
pandoc 1.14.0.4
Compiled with texmath 0.8.2, highlighting-kate 0.6.

Indeed with inline code blocks in org mode, the 'header' arguments are enclosed in square brackets

src_haskell[:exports both]{fac 5}

I have not seen it anywhere in the docs before, but arguments in code blocks can be enclosed in square brackets. I can evaluate the below example in org successfully.

#+begin_src sh [:results verbatim drawer replace output]
date
#+end_src

However, it doesn't seem to resolve this bug. E.g., the following code blocks, which include cases with and without [], do not get syntax highlighting

#+begin_src sh :noeval
echo "$HOME"
#+end_src

#+begin_src sh [:noeval]
echo "$HOME"
#+end_src

While these ones do convert with syntax highlighting

#+begin_src sh :var data1=1
echo "$data1"
#+end_src

#+NAME: test
#+HEADERS: :noeval
#+begin_src sh
echo "$HOME"
#+end_src

This is quite inconsistent.

Chances are, using the #+HEADERS option is the viable workaround and probably good practice for org users, but it would be nice to have this be more accurate in general.

I think I will try #+HEADERS for a while, and if I find it cumbersome, well... maybe there is a fix by then. Otherwise I can try to grok some haskell...

@jgm
Owner

I don't know anything about org mode.
But the current Org reader code assumes that an "org arg key" (like :var) will have some data after it.
That's why it runs aground on :noeval with nothing following.
@tarleb can you comment?

@tarleb

As @jgm pointed out, the code was written under the faulty assumption that each header argument is followed by a value. I'll patch things up (might need a week or two).

@jo-tham

Thanks, @tarleb!

@tarleb tarleb added a commit to tarleb/pandoc that referenced this issue
@tarleb tarleb Org reader: allow toggling header args
Org-mode allows to skip the argument of a code block header argument if
it's toggling a value.

This fixes #2269.
c377434
@tarleb tarleb added a commit to tarleb/pandoc that referenced this issue
@tarleb tarleb Org reader: allow toggling header args
Org-mode allows to skip the argument of a code block header argument if
it's toggling a value.

This fixes #2269.
9334e16
@tarleb tarleb added a commit to tarleb/pandoc that referenced this issue
@tarleb tarleb Org reader: allow toggling header args
Org-mode allows to skip the argument of a code block header argument if
it's toggling a value.

This fixes #2269.
2dfa14e
@tarleb tarleb added a commit to tarleb/pandoc that referenced this issue
@tarleb tarleb Org reader: allow toggling header args
Org-mode allows to skip the argument of a code block header argument if
it's toggling a value.

This fixes #2269.
2ab448b
@tarleb tarleb added a commit to tarleb/pandoc that referenced this issue
@tarleb tarleb Org reader: allow toggling header args
Org-mode allows to skip the argument of a code block header argument if
it's toggling a value.  Argument-less headers are now recognized,
avoiding weird parsing errors.

The fixes are not exactly pretty, but neither is the code that was
fixed.  So I guess it's about par for the course.  However, a rewrite of
the header parsing code wouldn't hurt in the long run.

This fixes #2269.
aa9f7c8
@tarleb tarleb added a commit to tarleb/pandoc that referenced this issue
@tarleb tarleb Org reader: allow toggling header args
Org-mode allows to skip the argument of a code block header argument if
it's toggling a value.  Argument-less headers are now recognized,
avoiding weird parsing errors.

The fixes are not exactly pretty, but neither is the code that was
fixed.  So I guess it's about par for the course.  However, a rewrite of
the header parsing code wouldn't hurt in the long run.

This fixes #2269.
1e7a7a4
@tarleb tarleb added a commit to tarleb/pandoc that referenced this issue
@tarleb tarleb Org reader: allow toggling header args
Org-mode allows to skip the argument of a code block header argument if
it's toggling a value.  Argument-less headers are now recognized,
avoiding weird parsing errors.

The fixes are not exactly pretty, but neither is the code that was
fixed.  So I guess it's about par for the course.  However, a rewrite of
the header parsing code wouldn't hurt in the long run.

Thanks to @jo-tham for filing the bug report.

This fixes #2269.
27a8603
@jgm jgm closed this in #2477
@jo-tham

:+1:

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.