Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possibile to get the Markdown title? #936

Open
flaviotordini opened this issue Jul 10, 2022 · 5 comments
Open

Is it possibile to get the Markdown title? #936

flaviotordini opened this issue Jul 10, 2022 · 5 comments

Comments

@flaviotordini
Copy link

I'm using showdown to render Markdown but I also would like to access the standard Markdown title (#) to generate some custom table of contents I need.

I read about the "metadata" stuff but I don't want to force authors to use a redundant tag. The title is already there.

Is there a way? If not will you consider adding the feature?

@MarketingPip
Copy link

@flaviotordini - I am not a contributor etc on this project. But hoping I can maybe provide you some insight for your problem. Correct me if wrong are you just looking to place a TOC in your markdown content already? Or build it in another place...?

If you are looking to build it in another place - can I suggest using an existing Table Of Contents generator, modifying it for your own needs to produce the output file somewhere else with the added Table Of Contents?

This is not what you need - but you could use the NPM package it uses to do this, again the script might need modifications assuming you are trying to get H1 values from what I am reading (if you need any help etc - feel free to make a comment here & I will try my best to guide you through)

MarketingPipeline/TOC-Generator-Action: A Github Action to generate a table of contents in your README

Hope this helps.

@flaviotordini
Copy link
Author

Thanks but I want to generate an external toc made of the titles (and paths) of many different Markdown documents.

@MarketingPip
Copy link

Thanks but I want to generate an external toc made of the titles (and paths) of many different Markdown documents.

@flaviotordini I figured this is what you are wanting to do. I will guide you through the steps to do this.

You will need this package or something similar (this is what I have setup in the action above)

markdown-toc-gen - npm

Insert in your Markdown Documents (the files you want to create a Table of Contents in) the following wherever you want the table of contents placed. There are options to place automatically at the start of each file keep in mind.

<-- toc --> <-- tocstop -->

then after installing markdown-toc-gen use the following command with [files] being your Markdown file paths.

markdown-toc-gen update [files..]

for more documentation on this again - read the following here. markdown-toc-gen - npm

Tho you mentioned you want to create something like the following example.

   [File Name](my_file_path/folder/File_Name.md)
   [File Name 2](my_file_path/folder/File_Name_2.md)

Assuming this is the case you will need to do some customization / scripting of your own to grab all file names & paths, place them inside a single markdown document with a separate header etc for each new line / file added ## [YOUR FILE NAME](YOUR FILE PATH), then add your <-- toc --> tags inside the document & generate the TOC, then remove all content after the generated TOCS / <-- toc --> tags.

Hope this helps & being this is kind of off topic from showdown I would suggest closing this issue. Tho I will be willing to help you if you have any questions - just prefer not spamming / using showdown issues section to discuss something somewhat off topic.

Again, hope this helps. 👍

ps; in terms of getting the title inside the MD document, look for the first case of a H1 heading etc.

@MarketingPip
Copy link

@flaviotordini - I did creep your profile too & seen you do mostly work in C++.

If you are not experienced or confident with doing this, I can possibility make you a Python based script that does exactly what you need. Tho I can not guarantee an exact timeline on this.

@MarketingPip
Copy link

@flaviotordini - was this not what you were needing..?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants