Earl Chase <[email protected]> writes:

>> When a line in a source block starts with a '*' character (and no
>> whitespace or other characters before it) it is interpreted as a
>> headline and the recognition of the source block breaks. Adding a space
>> or ',' character before the '*' character fixes source block parsing.
>> This is very unintuitive and, to me, feels more like a bug. I can't
>> think of any good reason a headline should be able to exist inside a
>> source block. If that is the intended behavior and adding a ','
>> character is the correct workaround then this report can be ignored.
>
> I've noticed this too. This is certainly unintuitive. However, this
> behavior could technically be useful as you are allowed to create org src
> blocks, e.g.
>
> #+begin_src org
> * Headline
> #+end_src.
>
> Ihor, would a patch that disabled this behavior outside of org src-blocks
> be accepted? Is it even possible to implement that feature?

This is by design in Org markup.
Headings are context-free and anything that looks like
* Heading
*always* creates a heading.

We could do differently, but that would have other downsides like when
one accidentally writes

#+begin_src
foo bar
<not closed>

* heading

<lots of text>

#+begin_src

#+end_src

Everything between the first begin_src and the last #+end_src would then
be slurped into a source block.

Org mode design prioritized headings.
Not intuitive in the scenario described by you, but we would run into
the above edge case if we did otherwise.
Alas, there is no silver bullet to avoid edge cases.

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to