emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language)
  2022-12-14 21:40 [BUG] ox-html does not export captions of source blocks without language Johan Bolmsjö
@ 2022-12-15  9:31 ` Ihor Radchenko
  2022-12-15 10:32   ` Kaushal Modi
                     ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Ihor Radchenko @ 2022-12-15  9:31 UTC (permalink / raw)
  To: Johan Bolmsjö; +Cc: emacs-orgmode

Johan Bolmsjö <org-mode@johan.bitmaster.se> writes:

> #+caption: Caption 1
> #+begin_src
> foo bar baz
> #+end_src

There is an inconsistency here between Org parser and
https://orgmode.org/worg/org-syntax.html + manual.

The actual parser does allow empty lang in src blocks, setting :lang
element property to nil. Should we stop doing this and treat such src
blocks as paragraphs? Or should we allow empty lang and instead adapt
the exporters to treat empty lang correctly?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
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>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language)
  2022-12-15  9:31 ` [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language) Ihor Radchenko
@ 2022-12-15 10:32   ` Kaushal Modi
  2022-12-15 11:32   ` Max Nikulin
  2022-12-15 13:32   ` Timothy
  2 siblings, 0 replies; 10+ messages in thread
From: Kaushal Modi @ 2022-12-15 10:32 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Johan Bolmsjö, emacs-org list

[-- Attachment #1: Type: text/plain, Size: 904 bytes --]

On Thu, Dec 15, 2022, 4:32 AM Ihor Radchenko <yantar92@posteo.net> wrote:

> Johan Bolmsjö <org-mode@johan.bitmaster.se> writes:
>
> > #+caption: Caption 1
> > #+begin_src
> > foo bar baz
> > #+end_src
>
> There is an inconsistency here between Org parser and
> https://orgmode.org/worg/org-syntax.html + manual.
>
> The actual parser does allow empty lang in src blocks, setting :lang
> element property to nil.



Should we stop doing this and treat such src
> blocks as paragraphs?


I think that this would cause more of a surprise to the user when something
in a source block exports as a plain paragraph instead of in a <pre> block
(for HTML exports).

Or should we allow empty lang and instead adapt
> the exporters to treat empty lang correctly?
>

I vote for this one. Then

#+begin_src
foo
#+end_src

will be analogous to this in Markdown:

```
foo
```

[-- Attachment #2: Type: text/html, Size: 2327 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language)
  2022-12-15  9:31 ` [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language) Ihor Radchenko
  2022-12-15 10:32   ` Kaushal Modi
@ 2022-12-15 11:32   ` Max Nikulin
  2022-12-15 14:29     ` Tim Cross
  2022-12-17  9:56     ` Ihor Radchenko
  2022-12-15 13:32   ` Timothy
  2 siblings, 2 replies; 10+ messages in thread
From: Max Nikulin @ 2022-12-15 11:32 UTC (permalink / raw)
  To: emacs-orgmode

On 15/12/2022 16:31, Ihor Radchenko wrote:
> 
> The actual parser does allow empty lang in src blocks, setting :lang
> element property to nil. Should we stop doing this and treat such src
> blocks as paragraphs? Or should we allow empty lang and instead adapt
> the exporters to treat empty lang correctly?

Source blocks without language may be treated as #+begin_example blocks. 
I believe, a warning should be issued in such case.

I do not see a reason why caption is not allowed for examples.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language)
  2022-12-15  9:31 ` [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language) Ihor Radchenko
  2022-12-15 10:32   ` Kaushal Modi
  2022-12-15 11:32   ` Max Nikulin
@ 2022-12-15 13:32   ` Timothy
  2 siblings, 0 replies; 10+ messages in thread
From: Timothy @ 2022-12-15 13:32 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Johan Bolmsjö, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 715 bytes --]

Hi Ihor,

> There is an inconsistency here between Org parser and
> <https://orgmode.org/worg/org-syntax.html> + manual.
>
> The actual parser does allow empty lang in src blocks, setting :lang
> element property to nil. Should we stop doing this and treat such src
> blocks as paragraphs? Or should we allow empty lang and instead adapt
> the exporters to treat empty lang correctly?

My 2c: a nil lang seems like the “less wrong” option.

All the best,
Timothy

-- 
Timothy (‘tecosaur’/‘TEC’), Org mode contributor.
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/tec>.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language)
  2022-12-15 11:32   ` Max Nikulin
@ 2022-12-15 14:29     ` Tim Cross
  2022-12-15 15:07       ` Ihor Radchenko
  2022-12-17  9:56     ` Ihor Radchenko
  1 sibling, 1 reply; 10+ messages in thread
From: Tim Cross @ 2022-12-15 14:29 UTC (permalink / raw)
  To: emacs-orgmode


Max Nikulin <manikulin@gmail.com> writes:

> On 15/12/2022 16:31, Ihor Radchenko wrote:
>> The actual parser does allow empty lang in src blocks, setting :lang
>> element property to nil. Should we stop doing this and treat such src
>> blocks as paragraphs? Or should we allow empty lang and instead adapt
>> the exporters to treat empty lang correctly?
>
> Source blocks without language may be treated as #+begin_example blocks. I believe, a
> warning should be issued in such case.
>
> I do not see a reason why caption is not allowed for examples.

Yes, I think I agree. Semantically, a src block without a language is
really just an example block - it cannot be executed or evaluated and is
essentially reduced to a example block.

I think having a warning is also a good idea as it will alert users when
they have inadvertently forgotten to add the lang.

I don't see any reason not to allow captions for examples either.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language)
  2022-12-15 14:29     ` Tim Cross
@ 2022-12-15 15:07       ` Ihor Radchenko
  2022-12-17  5:17         ` Tom Gillespie
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2022-12-15 15:07 UTC (permalink / raw)
  To: Tim Cross; +Cc: emacs-orgmode

Tim Cross <theophilusx@gmail.com> writes:

> I don't see any reason not to allow captions for examples either.

In LaTeX, example blocks are exported as verbatim. I am not sure if we
can even put captions into verbatim.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
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>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language)
@ 2022-12-16  6:15 Pedro Andres Aranda Gutierrez
  0 siblings, 0 replies; 10+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2022-12-16  6:15 UTC (permalink / raw)
  To: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 385 bytes --]

No, please. For two reasons:

1.- In HTML, you have <code>
2.- This could trickle to other backends where it makes sense

Thanks, /PA
-- 
Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet

[-- Attachment #2: Type: text/html, Size: 694 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language)
  2022-12-15 15:07       ` Ihor Radchenko
@ 2022-12-17  5:17         ` Tom Gillespie
  2022-12-18  1:33           ` Tim Cross
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Gillespie @ 2022-12-17  5:17 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Tim Cross, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1963 bytes --]

Hi Ihor,
   Chiming in here with a slight variant on what
others have said. Best!
Tom

I don't think this should be handled at the syntactic
layer at all. The empty string block language should
be syntactically valid with any special behavior
needed being handled later.

Linters could treat it as a warning/error though,
but the parsing is made significantly easier if
the empty string is present allowing the grammar
to be fully closed and regular.

Thus, I don't think we need to make this a syntactic
error or pun a src block without a lang to another type.

I think we can add an implementation for when the
block language is the empty string. This keeps
the grammar regular by removing a special case.

I assume that internally the empty string block lang
would mostly call the example block codepaths,
except that it should probably issue a warning or fail
if someone tries to org-src-edit the block so that we
can alert them that they are missing the lang.

Treating src blocks missing a lang as paragraphs is
incorrect because according to the syntax spec they
are syntactically still blocks (greater or lesser depending
on your inclinations).

I think the general principle we want to follow here is
that a block (or any entity in general) should not lose
its type because some part of its syntax is malformed
(I have made similar arguments about property drawers).

That is, if something starts with #+begin_NAME stuff
and there is a corresponding #+end_NAME, then it
is a block.

The choice of how a src block without a lang should
behave is a bit more complex as there are multiple
consumers of src blocks that make different assumptions.

As mentioned above. I think that if a block is missing the lang
we could think of it instead as the null language. If we have the
:var language because someone has other contents on the line
they have a well formed src block, but will get a different error
because there is currently no known language ":var".

[-- Attachment #2: Type: text/html, Size: 2576 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language)
  2022-12-15 11:32   ` Max Nikulin
  2022-12-15 14:29     ` Tim Cross
@ 2022-12-17  9:56     ` Ihor Radchenko
  1 sibling, 0 replies; 10+ messages in thread
From: Ihor Radchenko @ 2022-12-17  9:56 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

> Source blocks without language may be treated as #+begin_example blocks. 
> I believe, a warning should be issued in such case.

M-x org-lint already does it.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
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>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language)
  2022-12-17  5:17         ` Tom Gillespie
@ 2022-12-18  1:33           ` Tim Cross
  0 siblings, 0 replies; 10+ messages in thread
From: Tim Cross @ 2022-12-18  1:33 UTC (permalink / raw)
  To: Tom Gillespie; +Cc: Ihor Radchenko, emacs-orgmode


Tom Gillespie <tgbugs@gmail.com> writes:

> Treating src blocks missing a lang as paragraphs is
> incorrect because according to the syntax spec they
> are syntactically still blocks (greater or lesser depending
> on your inclinations).
>
> I think the general principle we want to follow here is
> that a block (or any entity in general) should not lose
> its type because some part of its syntax is malformed
> (I have made similar arguments about property drawers).
>

I think you might be right here.

The big characteristic of source blocks and example blocks which make
them different from paragraphs is the line breaks and indentation. If
they are treated as paragraphs, won't this information be lost?


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-12-18  1:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-16  6:15 [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language) Pedro Andres Aranda Gutierrez
  -- strict thread matches above, loose matches on Subject: below --
2022-12-14 21:40 [BUG] ox-html does not export captions of source blocks without language Johan Bolmsjö
2022-12-15  9:31 ` [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language) Ihor Radchenko
2022-12-15 10:32   ` Kaushal Modi
2022-12-15 11:32   ` Max Nikulin
2022-12-15 14:29     ` Tim Cross
2022-12-15 15:07       ` Ihor Radchenko
2022-12-17  5:17         ` Tom Gillespie
2022-12-18  1:33           ` Tim Cross
2022-12-17  9:56     ` Ihor Radchenko
2022-12-15 13:32   ` Timothy

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).