public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Sort Markdown file by headings
@ 2016-12-30 11:10 Guido Milanese
       [not found] ` <d85df17b-0a35-4504-9ce0-e9875d64996b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Guido Milanese @ 2016-12-30 11:10 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1377 bytes --]

I was wondering if it is possible to sort a whole markdown file using 
headings as keys for sorting, and I found two onle-line scripts, the former 
in Perl and the latter in (g)awk (see 
http://stackoverflow.com/questions/25351917/sort-markdown-file-by-heading).

They are easy to manage (the Perl script seems to me to be a little better) 
but limited to the first heading level. For my person use I wrote a script 
that supports 2 levels (could be easily adapted to a 3rd level, however). I 
would like to know if the script looks useful to others: if so, I will 
clean the code, write a short documentation and publish it. The script 
assumes a markdown headings syntax using '#' , not  '====='  , but can be 
adapted if requested.

Thanks for this great group, I am learning a lot.

guido (italy)





-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/d85df17b-0a35-4504-9ce0-e9875d64996b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1924 bytes --]

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

* Re: Sort Markdown file by headings
       [not found] ` <d85df17b-0a35-4504-9ce0-e9875d64996b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2016-12-31 22:45   ` BP Jonsson
  2021-01-31 12:43   ` Eric F.
  1 sibling, 0 replies; 5+ messages in thread
From: BP Jonsson @ 2016-12-31 22:45 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

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

It certainly sounds useful but it is hard to tell without looking at the
code or some documentation. I'm happy to have a look at the code if you
post it to a pastebin like gist for example.

/bpj -- waiting for the European midnight. Happy New Year, everyone!

Den 30 dec 2016 12:10 skrev "Guido Milanese" <guido.milanese-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:

> I was wondering if it is possible to sort a whole markdown file using
> headings as keys for sorting, and I found two onle-line scripts, the former
> in Perl and the latter in (g)awk (see http://stackoverflow.com/
> questions/25351917/sort-markdown-file-by-heading).
>
> They are easy to manage (the Perl script seems to me to be a little
> better) but limited to the first heading level. For my person use I wrote a
> script that supports 2 levels (could be easily adapted to a 3rd level,
> however). I would like to know if the script looks useful to others: if so,
> I will clean the code, write a short documentation and publish it. The
> script assumes a markdown headings syntax using '#' , not  '====='  , but
> can be adapted if requested.
>
> Thanks for this great group, I am learning a lot.
>
> guido (italy)
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/pandoc-discuss/d85df17b-0a35-4504-9ce0-e9875d64996b%
> 40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/d85df17b-0a35-4504-9ce0-e9875d64996b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAFC_yuScj--%2BspvmMMdfBA4K4smWNjCFmg8nXCTX%2Bavdup9ySw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: Sort Markdown file by headings
       [not found] ` <d85df17b-0a35-4504-9ce0-e9875d64996b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2016-12-31 22:45   ` BP Jonsson
@ 2021-01-31 12:43   ` Eric F.
       [not found]     ` <2d3fac82-38e7-4220-82e0-85840f4e28adn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  1 sibling, 1 reply; 5+ messages in thread
From: Eric F. @ 2021-01-31 12:43 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1471 bytes --]

it's been a long time, but anyway...

this script would surely be useful, please share it! :)


Le vendredi 30 décembre 2016 à 12:10:55 UTC+1, guido.m...@gmail.com a 
écrit :

> I was wondering if it is possible to sort a whole markdown file using 
> headings as keys for sorting, and I found two onle-line scripts, the former 
> in Perl and the latter in (g)awk (see 
> http://stackoverflow.com/questions/25351917/sort-markdown-file-by-heading
> ).
>
> They are easy to manage (the Perl script seems to me to be a little 
> better) but limited to the first heading level. For my person use I wrote a 
> script that supports 2 levels (could be easily adapted to a 3rd level, 
> however). I would like to know if the script looks useful to others: if so, 
> I will clean the code, write a short documentation and publish it. The 
> script assumes a markdown headings syntax using '#' , not  '====='  , but 
> can be adapted if requested.
>
> Thanks for this great group, I am learning a lot.
>
> guido (italy)
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/2d3fac82-38e7-4220-82e0-85840f4e28adn%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 2381 bytes --]

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

* Re: Sort Markdown file by headings
       [not found]     ` <2d3fac82-38e7-4220-82e0-85840f4e28adn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2021-01-31 13:17       ` BPJ
       [not found]         ` <CADAJKhAXuSZexp5q3iaEb=vNrPihBK4bs6Rz0YG-y_aqq8bwgg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: BPJ @ 2021-01-31 13:17 UTC (permalink / raw)
  To: pandoc-discuss

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

One way might be to use the Voom outliner plugin for Vim, which understands
Markdown and sort the headings manually in the outline pane if there are
not too many. Too bad that sorting non-ASCII letters correctly using Lua
probably is a pain if possible at all, or one could sort the output of the
`make_sections` function inside a filter.

-- 
Better --help|less than helpless

Den sön 31 jan. 2021 13:44Eric F. <eforgeot-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:

> it's been a long time, but anyway...
>
> this script would surely be useful, please share it! :)
>
>
> Le vendredi 30 décembre 2016 à 12:10:55 UTC+1, guido.m...@gmail.com a
> écrit :
>
>> I was wondering if it is possible to sort a whole markdown file using
>> headings as keys for sorting, and I found two onle-line scripts, the former
>> in Perl and the latter in (g)awk (see
>> http://stackoverflow.com/questions/25351917/sort-markdown-file-by-heading
>> ).
>>
>> They are easy to manage (the Perl script seems to me to be a little
>> better) but limited to the first heading level. For my person use I wrote a
>> script that supports 2 levels (could be easily adapted to a 3rd level,
>> however). I would like to know if the script looks useful to others: if so,
>> I will clean the code, write a short documentation and publish it. The
>> script assumes a markdown headings syntax using '#' , not  '====='  , but
>> can be adapted if requested.
>>
>> Thanks for this great group, I am learning a lot.
>>
>> guido (italy)
>>
>>
>>
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/2d3fac82-38e7-4220-82e0-85840f4e28adn%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/2d3fac82-38e7-4220-82e0-85840f4e28adn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhAXuSZexp5q3iaEb%3DvNrPihBK4bs6Rz0YG-y_aqq8bwgg%40mail.gmail.com.

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

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

* Re: Sort Markdown file by headings
       [not found]         ` <CADAJKhAXuSZexp5q3iaEb=vNrPihBK4bs6Rz0YG-y_aqq8bwgg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2021-02-01  8:19           ` Eric F.
  0 siblings, 0 replies; 5+ messages in thread
From: Eric F. @ 2021-02-01  8:19 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3188 bytes --]

Someone helped me to make a proper script which will handle 3 levels:


#!/usr/bin/env perl

local $/;
my $text = <>;
my ($start, @chapters) = split/^#(?=[^#])/m, $text;
print $start;
for (sort @chapters) {
    my ($level1, @subchapters) = split/^##(?=[^#])/m;
    print "#$level1";
        for (sort @subchapters) {
        my ($level2, @subsubchapters) = split/^###(?=[^#])/m;
        print "##$level2";
        print map {"###$_"} sort @subsubchapters; 
        }
}


Le dimanche 31 janvier 2021 à 14:17:20 UTC+1, BPJ a écrit :

> One way might be to use the Voom outliner plugin for Vim, which 
> understands Markdown and sort the headings manually in the outline pane if 
> there are not too many. Too bad that sorting non-ASCII letters correctly 
> using Lua probably is a pain if possible at all, or one could sort the 
> output of the `make_sections` function inside a filter.
>
> -- 
> Better --help|less than helpless
>
> Den sön 31 jan. 2021 13:44Eric F. <efor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
>
>> it's been a long time, but anyway...
>>
>> this script would surely be useful, please share it! :)
>>
>>
>> Le vendredi 30 décembre 2016 à 12:10:55 UTC+1, guido.m...@gmail.com a 
>> écrit :
>>
>>> I was wondering if it is possible to sort a whole markdown file using 
>>> headings as keys for sorting, and I found two onle-line scripts, the former 
>>> in Perl and the latter in (g)awk (see 
>>> http://stackoverflow.com/questions/25351917/sort-markdown-file-by-heading
>>> ).
>>>
>>> They are easy to manage (the Perl script seems to me to be a little 
>>> better) but limited to the first heading level. For my person use I wrote a 
>>> script that supports 2 levels (could be easily adapted to a 3rd level, 
>>> however). I would like to know if the script looks useful to others: if so, 
>>> I will clean the code, write a short documentation and publish it. The 
>>> script assumes a markdown headings syntax using '#' , not  '====='  , but 
>>> can be adapted if requested.
>>>
>>> Thanks for this great group, I am learning a lot.
>>>
>>> guido (italy)
>>>
>>>
>>>
>>>
>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "pandoc-discuss" group.
>>
> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pandoc-discuss/2d3fac82-38e7-4220-82e0-85840f4e28adn%40googlegroups.com 
>> <https://groups.google.com/d/msgid/pandoc-discuss/2d3fac82-38e7-4220-82e0-85840f4e28adn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e515afcd-fa02-4fe5-bdf3-a834eb2f2a15n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 5637 bytes --]

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

end of thread, other threads:[~2021-02-01  8:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-30 11:10 Sort Markdown file by headings Guido Milanese
     [not found] ` <d85df17b-0a35-4504-9ce0-e9875d64996b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-12-31 22:45   ` BP Jonsson
2021-01-31 12:43   ` Eric F.
     [not found]     ` <2d3fac82-38e7-4220-82e0-85840f4e28adn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-01-31 13:17       ` BPJ
     [not found]         ` <CADAJKhAXuSZexp5q3iaEb=vNrPihBK4bs6Rz0YG-y_aqq8bwgg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-02-01  8:19           ` Eric F.

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 NNTP newsgroup(s).