emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How does =org-md-item= produce the correct indentation for nested lists?
@ 2024-04-13  4:07 Rohit Patnaik
  2024-04-13 19:26 ` Ihor Radchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Rohit Patnaik @ 2024-04-13  4:07 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I was looking at the implementation for =org-md-item=, in ox-md.el, and I'm
wondering how indentation logic for nested lists works. Specifically, I was
looking at the following code:

#+BEGIN_SRC elisp
(concat bullet
        (make-string (- 4 (length bullet)) ? )
        (pcase (org-element-property :checkbox item)
          (`on "[X] ")
          (`trans "[-] ")
          (`off "[ ] "))
        (let ((tag (org-element-property :tag item)))
          (and tag (format "**%s:** "(org-export-data tag info))))
        (and contents
    	 (org-trim (replace-regexp-in-string "^" "    " contents))))
#+END_SRC

and I'm wondering why it's adding indentation in front of the bullet. Naively, I
would expect the result of this snippet, for an unordered list to be something
like:

=-        [item contents]=

That is, it concatenate the bullet, then three spaces (4 - length of bullet),
then another four spaces, then the contents of the item. Instead, what I see is
a four-space indent, followed by the bullet and its padding, followed by the
item contents:

=    -   [item contents]=

This is the correct result, but I don't see how the code from ox-md.el produces
that result.

The reason I'm asking is because I have similar logic in the org-mode exporter
I'm writing for PMWiki markup:

https://github.com/quanticle/ox-pmwiki/blob/master/ox-pmwiki.el#L214

and I would like to change the logic so that instead of indenting with spaces,
it repeats the list marker (** for a second level nested list, *** for 3 levels
of nesting, etc). 

Thanks,
Rohit Patnaik


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

* Re: How does =org-md-item= produce the correct indentation for nested lists?
  2024-04-13  4:07 How does =org-md-item= produce the correct indentation for nested lists? Rohit Patnaik
@ 2024-04-13 19:26 ` Ihor Radchenko
  2024-04-14  5:51   ` Rohit Patnaik
  0 siblings, 1 reply; 3+ messages in thread
From: Ihor Radchenko @ 2024-04-13 19:26 UTC (permalink / raw)
  To: Rohit Patnaik; +Cc: emacs-orgmode

"Rohit Patnaik" <quanticle@quanticle.net> writes:

> #+BEGIN_SRC elisp
> (concat bullet
> ...
>         (and contents
>     	 (org-trim (replace-regexp-in-string "^" "    " contents))))
> #+END_SRC
>
> and I'm wondering why it's adding indentation in front of the bullet. Naively, I
> would expect the result of this snippet, for an unordered list to be something
> like:
>
> =-        [item contents]=
>
> That is, it concatenate the bullet, then three spaces (4 - length of bullet),
> then another four spaces, then the contents of the item. Instead, what I see is
> a four-space indent, followed by the bullet and its padding, followed by the
> item contents:
>
> =    -   [item contents]=
>
> This is the correct result, but I don't see how the code from ox-md.el produces
> that result.

The code makes use of the CONTENTS.

If you have nested lists

- item
  - sub-item
    - sub-sub-item

"sub-sub-item" transcoder will receive CONTENTS="sub-sub-item" and return

-   sub-sub-item

then, "sub-item" transcoder will receive CONTENTS="sub-item" + output of
nested transcoder -

CONTENTS=

sub-item
-   sub-sub-item

and add 4 spaces to each line, except first:

-   sub-item
    -   sub-sub-item

then, item transcoder will receive the result of the two nested
transcoders:

CONTENTS=

item
-   sub-item
    -   sub-sub-item

yielding

-   item
    -   sub-item
        -   sub-sub-item

Hope, it clarifies things.

-- 
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] 3+ messages in thread

* Re: How does =org-md-item= produce the correct indentation for nested lists?
  2024-04-13 19:26 ` Ihor Radchenko
@ 2024-04-14  5:51   ` Rohit Patnaik
  0 siblings, 0 replies; 3+ messages in thread
From: Rohit Patnaik @ 2024-04-14  5:51 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Hello,

Yes, that clarifies things quite a bit. I thought that the contents of the list
item only included that specific item, when in reality it includes the item and
all sub-lists.

Thanks,
Rohit


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

end of thread, other threads:[~2024-04-14  5:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-13  4:07 How does =org-md-item= produce the correct indentation for nested lists? Rohit Patnaik
2024-04-13 19:26 ` Ihor Radchenko
2024-04-14  5:51   ` Rohit Patnaik

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).