emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* export and split orgmode headers into separate md files?
@ 2020-01-12  3:54 Xebar Saram
  2020-01-12 12:19 ` Diego Zamboni
  0 siblings, 1 reply; 4+ messages in thread
From: Xebar Saram @ 2020-01-12  3:54 UTC (permalink / raw)
  To: org mode

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

Hi all

For work specific needs at uni i have a need to take a comprehensive org
file with hundreds of headers and split each header into separate .md files
(with the header name as file name//first header in the md file).
Has anyone done anything remotely similar? Or if not can someone point
me in the right direction on how to even start dealing with this?

thx a lot in advance any tips would be very much appreciated

kind regards

Z

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

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

* Re: export and split orgmode headers into separate md files?
  2020-01-12  3:54 export and split orgmode headers into separate md files? Xebar Saram
@ 2020-01-12 12:19 ` Diego Zamboni
  2020-01-15 13:47   ` Xebar Saram
  0 siblings, 1 reply; 4+ messages in thread
From: Diego Zamboni @ 2020-01-12 12:19 UTC (permalink / raw)
  To: Xebar Saram; +Cc: org mode

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

Hi Z,

I do something similar in my ox-leanpub-book module [1], which exports each
top-level heading to a different file. The general idea is to use
=org-map-entries= to loop over the entire buffer [2]. The function you call
can then check whether the current entry is a header at the level you want
[3] and then export it to the corresponding file. The title can be used to
deduct the filename [4].

I found that I had to mark the entire subtree before calling the export
function [5], otherwise the headline was not getting included in the export.

I based my code originally on this blog post, which might be a simpler
starting point:
https://medium.com/@lakshminp/publishing-a-book-using-org-mode-9e817a56d144
- this code does not select the entire subtree before exporting, which
means only the contents of the section is exported, but not the headline
itself.

Hope this helps!
--Diego

[1] https://github.com/zzamboni/ox-leanpub/tree/book-and-markua
[2]
https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L185-L186
[3]
https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L125
[4]
https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L131-L135
[5]
https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L170-L174


On Sun, Jan 12, 2020 at 4:54 AM Xebar Saram <zeltakc@gmail.com> wrote:

> Hi all
>
> For work specific needs at uni i have a need to take a comprehensive org
> file with hundreds of headers and split each header into separate .md files
> (with the header name as file name//first header in the md file).
> Has anyone done anything remotely similar? Or if not can someone point
> me in the right direction on how to even start dealing with this?
>
> thx a lot in advance any tips would be very much appreciated
>
> kind regards
>
> Z
>

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

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

* Re: export and split orgmode headers into separate md files?
  2020-01-12 12:19 ` Diego Zamboni
@ 2020-01-15 13:47   ` Xebar Saram
  2020-01-20 21:03     ` Diego Zamboni
  0 siblings, 1 reply; 4+ messages in thread
From: Xebar Saram @ 2020-01-15 13:47 UTC (permalink / raw)
  To: Diego Zamboni; +Cc: org mode

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

Thx Deigo for the detailed answer! Really appreciate it!

i think though it’s a bit over my head as i have limited lisp knowledge :)

Does this export to standard markdown files or leanpub format? Honestly at
this stage im willing to export to any flavor of markdown but basic or MMD
would work best. Any tips on how i can adjust the code for that?
if not can i just run your code to get a different markdown format? What
the main function you run after evaluating the code in emacs?
i apologize in advance for the silly questions :)

thx again

Z

On Sun, Jan 12, 2020 at 7:20 AM Diego Zamboni <diego@zzamboni.org> wrote:

> Hi Z,
>
> I do something similar in my ox-leanpub-book module [1], which exports
> each top-level heading to a different file. The general idea is to use
> =org-map-entries= to loop over the entire buffer [2]. The function you call
> can then check whether the current entry is a header at the level you want
> [3] and then export it to the corresponding file. The title can be used to
> deduct the filename [4].
>
> I found that I had to mark the entire subtree before calling the export
> function [5], otherwise the headline was not getting included in the export.
>
> I based my code originally on this blog post, which might be a simpler
> starting point:
> https://medium.com/@lakshminp/publishing-a-book-using-org-mode-9e817a56d144
> - this code does not select the entire subtree before exporting, which
> means only the contents of the section is exported, but not the headline
> itself.
>
> Hope this helps!
> --Diego
>
> [1] https://github.com/zzamboni/ox-leanpub/tree/book-and-markua
> [2]
> https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L185-L186
> [3]
> https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L125
> [4]
> https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L131-L135
> [5]
> https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L170-L174
>
>
> On Sun, Jan 12, 2020 at 4:54 AM Xebar Saram <zeltakc@gmail.com> wrote:
>
>> Hi all
>>
>> For work specific needs at uni i have a need to take a comprehensive org
>> file with hundreds of headers and split each header into separate .md files
>> (with the header name as file name//first header in the md file).
>> Has anyone done anything remotely similar? Or if not can someone point
>> me in the right direction on how to even start dealing with this?
>>
>> thx a lot in advance any tips would be very much appreciated
>>
>> kind regards
>>
>> Z
>>
>

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

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

* Re: export and split orgmode headers into separate md files?
  2020-01-15 13:47   ` Xebar Saram
@ 2020-01-20 21:03     ` Diego Zamboni
  0 siblings, 0 replies; 4+ messages in thread
From: Diego Zamboni @ 2020-01-20 21:03 UTC (permalink / raw)
  To: Xebar Saram; +Cc: org mode

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

Hi Z,

(replying to the list)

I have put together a simplified function based on the code from
https://medium.com/@lakshminp/publishing-a-book-using-org-mode-9e817a56d144,
which simply exports each top-level header to a plain Markdown file. You
can find it here:
https://gist.github.com/zzamboni/2e6ac3c4f577249d98efb224d9d34488

I have added some commentary in the code about what it does. After
evaluating the code, you just need to call M-x org-multi-file-md-export in
the buffer you want to export.

I hope this helps in getting you started!

Cheers,
--Diego

On Wed, Jan 15, 2020 at 2:48 PM Xebar Saram <zeltakc@gmail.com> wrote:

> Thx Deigo for the detailed answer! Really appreciate it!
>
> i think though it’s a bit over my head as i have limited lisp knowledge :)
>
> Does this export to standard markdown files or leanpub format? Honestly at
> this stage im willing to export to any flavor of markdown but basic or MMD
> would work best. Any tips on how i can adjust the code for that?
> if not can i just run your code to get a different markdown format? What
> the main function you run after evaluating the code in emacs?
> i apologize in advance for the silly questions :)
>
> thx again
>
> Z
>
> On Sun, Jan 12, 2020 at 7:20 AM Diego Zamboni <diego@zzamboni.org> wrote:
>
>> Hi Z,
>>
>> I do something similar in my ox-leanpub-book module [1], which exports
>> each top-level heading to a different file. The general idea is to use
>> =org-map-entries= to loop over the entire buffer [2]. The function you call
>> can then check whether the current entry is a header at the level you want
>> [3] and then export it to the corresponding file. The title can be used to
>> deduct the filename [4].
>>
>> I found that I had to mark the entire subtree before calling the export
>> function [5], otherwise the headline was not getting included in the export.
>>
>> I based my code originally on this blog post, which might be a simpler
>> starting point:
>> https://medium.com/@lakshminp/publishing-a-book-using-org-mode-9e817a56d144
>> - this code does not select the entire subtree before exporting, which
>> means only the contents of the section is exported, but not the headline
>> itself.
>>
>> Hope this helps!
>> --Diego
>>
>> [1] https://github.com/zzamboni/ox-leanpub/tree/book-and-markua
>> [2]
>> https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L185-L186
>> [3]
>> https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L125
>> [4]
>> https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L131-L135
>> [5]
>> https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-book.el#L170-L174
>>
>>
>> On Sun, Jan 12, 2020 at 4:54 AM Xebar Saram <zeltakc@gmail.com> wrote:
>>
>>> Hi all
>>>
>>> For work specific needs at uni i have a need to take a comprehensive org
>>> file with hundreds of headers and split each header into separate .md files
>>> (with the header name as file name//first header in the md file).
>>> Has anyone done anything remotely similar? Or if not can someone point
>>> me in the right direction on how to even start dealing with this?
>>>
>>> thx a lot in advance any tips would be very much appreciated
>>>
>>> kind regards
>>>
>>> Z
>>>
>>

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

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

end of thread, other threads:[~2020-01-20 21:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-12  3:54 export and split orgmode headers into separate md files? Xebar Saram
2020-01-12 12:19 ` Diego Zamboni
2020-01-15 13:47   ` Xebar Saram
2020-01-20 21:03     ` Diego Zamboni

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