all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* numbering src blocks in HTML export
@ 2022-07-19 15:00 Fraga, Eric
  2022-07-19 15:28 ` Juan Manuel Macías
  0 siblings, 1 reply; 8+ messages in thread
From: Fraga, Eric @ 2022-07-19 15:00 UTC (permalink / raw)
  To: Emacs Org mode mailing list

Hello,

a quick and hopefully easy question: how do I get lines in src blocks
numbered in HTML export?  I have looked at the code and the first thing
I did was set org-html-wrap-src-lines to t.  This wraps each line in
"<code>...</code>".

I know how to use CSS to add line numbers to lines with these tags but,
looking at the export code, I see it uses the following function:

,----[ C-h f org-export-get-loc RET ]
| org-export-get-loc is a native compiled Lisp function in ‘ox.el’.
| 
| (org-export-get-loc ELEMENT INFO)
| 
| Return count of lines of code before ELEMENT.
| 
| ELEMENT is an example-block or src-block element.  INFO is the
| plist used as a communication channel.
| 
| Count includes every line of code in example-block or src-block
| with a "+n" or "-n" switch before block.  Return nil if
| ELEMENT doesn’t allow line numbering.
| 
`----

I really do not understand the last paragraph although it implies that
org already supports adding the line numbers.  My elisp-fu is not up to
scratch to figure this out from the code unfortunately.  Would somebody
explain what to do?  Or should I simply add the CSS code that would do
it for me?

Thank you,
eric

-- 
: Eric S Fraga, with org release_9.5.4-643-g057df6 in Emacs 29.0.50

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

* Re: numbering src blocks in HTML export
  2022-07-19 15:00 numbering src blocks in HTML export Fraga, Eric
@ 2022-07-19 15:28 ` Juan Manuel Macías
  2022-07-19 16:15   ` Fraga, Eric
  2022-07-19 16:18   ` Fraga, Eric
  0 siblings, 2 replies; 8+ messages in thread
From: Juan Manuel Macías @ 2022-07-19 15:28 UTC (permalink / raw)
  To: Fraga, Eric; +Cc: orgmode

Fraga, Eric writes:

> I really do not understand the last paragraph although it implies that
> org already supports adding the line numbers.  My elisp-fu is not up to
> scratch to figure this out from the code unfortunately.  Would somebody
> explain what to do?  Or should I simply add the CSS code that would do
> it for me?

I usually do it this way:

#+begin_src sh -n :exports code
aa
bb
dd
ee
ff
#+end_src

And you can also indicate the number of the first line, ie -n 20

Best regards,

Juan Manuel 


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

* Re: numbering src blocks in HTML export
  2022-07-19 15:28 ` Juan Manuel Macías
@ 2022-07-19 16:15   ` Fraga, Eric
  2022-07-19 16:18   ` Fraga, Eric
  1 sibling, 0 replies; 8+ messages in thread
From: Fraga, Eric @ 2022-07-19 16:15 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: orgmode

On Tuesday, 19 Jul 2022 at 15:28, Juan Manuel Macías wrote:
> I usually do it this way:
>
> #+begin_src sh -n :exports code

Thank you.  Obvious (in hindsight).  <blush>

I now found the section in the info manual on this (under Markup for
Rich Contents, which is I guess not where I expected it... but did get
there by following link for switches in header arguments which I somehow
missed earlier.)

eric

-- 
: Eric S Fraga, with org release_9.5.4-643-g057df6 in Emacs 29.0.50

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

* Re: numbering src blocks in HTML export
  2022-07-19 15:28 ` Juan Manuel Macías
  2022-07-19 16:15   ` Fraga, Eric
@ 2022-07-19 16:18   ` Fraga, Eric
  2022-07-20  3:58     ` Ihor Radchenko
  1 sibling, 1 reply; 8+ messages in thread
From: Fraga, Eric @ 2022-07-19 16:18 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: orgmode

Followup question, if I may: how can I make -n be default behaviour for
export?  I have tried, for instance,

#+property: header-args:julia -n 1

to have all Julia src blocks show line numbers but it doesn't work.

Thanks again,
eric

-- 
: Eric S Fraga, with org release_9.5.4-643-g057df6 in Emacs 29.0.50

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

* Re: numbering src blocks in HTML export
  2022-07-19 16:18   ` Fraga, Eric
@ 2022-07-20  3:58     ` Ihor Radchenko
  2022-07-20  9:14       ` Fraga, Eric
                         ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Ihor Radchenko @ 2022-07-20  3:58 UTC (permalink / raw)
  To: Fraga, Eric; +Cc: Juan Manuel Macías, orgmode

"Fraga, Eric" <e.fraga@ucl.ac.uk> writes:

> Followup question, if I may: how can I make -n be default behaviour for
> export?  I have tried, for instance,
>
> #+property: header-args:julia -n 1
>
> to have all Julia src blocks show line numbers but it doesn't work.

AFAIU, source block switches are never inherited.

Dear All, may we should provide a normal header arg as an equivalent of
switches? Honestly, this whole switch syntax sounds unnecessary and only
over-complicates things.

Best,
Ihor


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

* Re: numbering src blocks in HTML export
  2022-07-20  3:58     ` Ihor Radchenko
@ 2022-07-20  9:14       ` Fraga, Eric
  2022-07-20 12:07       ` Juan Manuel Macías
  2022-07-22 14:42       ` Greg Minshall
  2 siblings, 0 replies; 8+ messages in thread
From: Fraga, Eric @ 2022-07-20  9:14 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Juan Manuel Macías, Emacs Org mode mailing list

On Wednesday, 20 Jul 2022 at 11:58, Ihor Radchenko wrote:
> AFAIU, source block switches are never inherited.

Thank you for confirming.  It's easy enough for me to change all of my
src blocks with a single Emacs command.  And that's why "it's all text"
is so important! :-)

> may we should provide a normal header arg as an equivalent of
> switches?

Sounds like a reasonable idea.  I think they are possibly a holdover
from text blocks for examples, pre-babel?

-- 
: Eric S Fraga, with org release_9.5.4-643-g057df6 in Emacs 29.0.50

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

* Re: numbering src blocks in HTML export
  2022-07-20  3:58     ` Ihor Radchenko
  2022-07-20  9:14       ` Fraga, Eric
@ 2022-07-20 12:07       ` Juan Manuel Macías
  2022-07-22 14:42       ` Greg Minshall
  2 siblings, 0 replies; 8+ messages in thread
From: Juan Manuel Macías @ 2022-07-20 12:07 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: orgmode, Fraga, Eric

Ihor Radchenko writes:

> AFAIU, source block switches are never inherited.
>
> Dear All, may we should provide a normal header arg as an equivalent of
> switches? Honestly, this whole switch syntax sounds unnecessary and only
> over-complicates things.

I think that web pages or documents that contain several code examples
(tutorials, documentation, etc.) tend to unify the style in this regard:
either all examples are line-numbered or all examples are unnumbered;
therefore, if the first option is chosen, it would be good to have some
global setting, when there are many blocks. But I also think this can be
easily achieved with some function locally hooked to
org-export-before-processing-hook. Or even within the document on the
fly.

A global 'factory setting' would also have the extra complication that
there would be two global numbering versions (at least): a) a separate
numbering for each block; b) each block continuing the numbering of the
previous block. And there could be a subtype of b) where it is necessary
to restart the numbering when starting a new section. Or a) and b) could
be arbitrarily mixed in the same document. All this seems complicated
to implement...

But one thing that could be nice is to give an option (perhaps with a
prefix argument) for org-babel-demarcate-block (C-c C-v C-d) to inherit
the switches:

before:

#+begin_src emacs-lisp -n
a
a
a
a
a
a
#+end_src

after C-c C-v C-d

#+begin_src emacs-lisp -n
a
a
a
#+end_src

#+begin_src emacs-lisp +n
b
b
b
#+end_src


Best regards,

Juan Manuel 





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

* Re: numbering src blocks in HTML export
  2022-07-20  3:58     ` Ihor Radchenko
  2022-07-20  9:14       ` Fraga, Eric
  2022-07-20 12:07       ` Juan Manuel Macías
@ 2022-07-22 14:42       ` Greg Minshall
  2 siblings, 0 replies; 8+ messages in thread
From: Greg Minshall @ 2022-07-22 14:42 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Fraga, Eric, Juan Manuel Macías, orgmode

Ihor,

> Dear All, may we should provide a normal header arg as an equivalent of
> switches? Honestly, this whole switch syntax sounds unnecessary and only
> over-complicates things.

i'm a fan.


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

end of thread, other threads:[~2022-07-22 14:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-19 15:00 numbering src blocks in HTML export Fraga, Eric
2022-07-19 15:28 ` Juan Manuel Macías
2022-07-19 16:15   ` Fraga, Eric
2022-07-19 16:18   ` Fraga, Eric
2022-07-20  3:58     ` Ihor Radchenko
2022-07-20  9:14       ` Fraga, Eric
2022-07-20 12:07       ` Juan Manuel Macías
2022-07-22 14:42       ` Greg Minshall

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.