Giter Site home page Giter Site logo

kevingimbel / mktoc Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 3.0 1.98 MB

๐Ÿฆ€ Markdown Table of Content generator

Home Page: https://kevingimbel.de/oss/mktoc

License: MIT License

Rust 95.84% Makefile 2.13% Shell 2.02%
rust markdown table-of-contents toc generator rust-library command-line command-line-tool cli

mktoc's Issues

Strip special characters

Special characters like ( must be removed from the link.

The headline

## MongoDB (Atlas)

must be linked as

- [MongoDB (Atlas)](#mongodb-atlas)

but currently mktoc produces a link like

- [MongoDB (Atlas)](#mongodb-(atlas))

Feature: wrap ToC in details block

Add an option to wrap the generated ToC in a <details> element.

Example:

Table of Contents

Code:

<!-- BEGIN mktoc -->
<details>
  <summary>Table of Contents</summary>

- [Installation ๐Ÿค–](#installation)
  - [Build from source](#build-from-source)
    - [Prerequisites](#prerequisites)
    - [Instructions](#instructions)
  - [Binary releases](#binary-releases)
  - [Docker](#docker)
    - [Images](#images)
    - [Usage](#usage)
    - [Building](#building)
</details>
<!-- END mktoc -->

Important:

  • Newline after <summary> is required, otherwise the markdown is not parsed.
  • Should be configurable via ENV, cli argument, and inline config

Parsing issues

Since we're using a "simple" Regex based parser to find headlines we also get things that are not a headline, e.g. comment blocks inside of code snippets:

# my comment
pub fn is_issue() -> bool {
  true
}

Here # my comment would be added to the Table of Contents. So far I cannot think of a way to fix this without using a markdown parser to process the markdown before getting the headlines.

Links in Headlines produce wrong output

The rendered output is wrong

Code:

<!-- BEGIN mktoc -->

  - [Links in [Headlines](/headlines/)](#links-in-headlinesheadlines)
<!-- END mktoc -->

### Links in [Headlines](/headlines/)

Rendered like:

  • [Links in Headlines](#links-in-headlinesheadlines)

Desired Output:

<!-- BEGIN mktoc -->

  - [Links in Headlines](#links-in-headlines)
<!-- END mktoc -->

### Links in [Headlines](/headlines/)

Link inside a Headline must be stripped out.

Extract input manipulation

The code responsible for adding the ToC is inside the make_toc function. This means a third-party user cannot get a full Markdown file generated without specifying an actual file (make_toc takes a file path).

https://github.com/KevinGimbel/mktoc/blob/main/src/lib.rs#L227-L237

Todo

Extract code into function

fn add_toc(original_file_content: String, new_toc: String) -> String

Write tests

  • Adding the ToC is implicitly tested, should be explicitly tested

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.