CuteMarkEd icon indicating copy to clipboard operation
CuteMarkEd copied to clipboard

Allow Generation of Table of Contents?

Open thomasnield opened this issue 10 years ago • 2 comments

Probably tied to my other issue #276, but can we also allow a feature to quickly insert a Table of Contents at the top of the page with hyperlink support to the sections?

thomasnield avatar Jan 28 '16 14:01 thomasnield

Might not be much help, but I finished an AHK script that turns Markdown text on a clipboard into a hyperlinked Markdown Table of Contents. More or less what my ask wanted to accomplish. It would be nice if this was integrated into CuteMarkEd though.

msgbox Copy a Markdown file to your clipboard and press CTRL + L to turn it into an outline

^l:: 

Loop, parse, clipboard, `n, `r 
{
    trimmed := RegexReplace(A_LoopField, "(?=(^|#))\s*","")
    Pos=1
    While Pos := RegExMatch(trimmed, "^[#]+", hashTags,Pos+StrLen(hashTags)) 
    {
        StringReplace noHashTags, trimmed, #,,All

        firstBlock = [%noHashTags%]
        StringReplace secondBlock,noHashTags,%A_Space%,.,All
        secondBlock = (#%secondBlock%)

        StringReplace padding,hashTags,#,%A_Space%,All

        fullBlock = %padding%%firstBlock%%secondBlock%

        StringReplace fullBlock,fullBlock,[%A_Space%,[,All
        StringReplace fullBlock,fullBlock,#.,#,All
        StringReplace fullBlock,fullBlock,.),),All

        StringReplace padding,hashTags,#,    ,All

        fullBlock = %padding%%A_Space%%fullBlock%

        output = %output% %fullBlock% <br>
    }

}
msgbox Markdown outline on clipboard!

Clipboard := output

return

thomasnield avatar Jan 29 '16 19:01 thomasnield

@thomasnield: Nice script, thanks. But It does not fit directly to the needs of CuteMarkED.

CuteMarkED generates headlines like this:

<h1 id="toc_0">Contents</h1>

your script expects

<h1 id="Contents">Contents</h1>

Generally, it would be better, CuteMarkED would generate headline id´s as in the last example, because this would make it much easier to link in documents to them.

Inserting contents should not be on top in general, a function, to insert it at current cursor position would be nice.

BsNoSi avatar Mar 29 '16 05:03 BsNoSi