csstoc [-v] [--no-color] [-h] [--css | --sass] [-s] [-f filePath ]
Csstoc stands for 'css table of content'. It prints a table of content inside a .css or .scss files, based on user set titles. It is inspired by the way markdown allows generating toc.
-v, --verbose
Print script debug info--no-color
Disable colours in output.-h, --help
Print this help and exit--css
Force csstoc to watch for css comments to build the toc--sass
Force csstoc to watch for sass/scss/less comments to build the toc-s, --standard-output
Print results to standard-output-f, --file
FilePath in which to generate a toc
⚠️ Concatenated flags like for example-vs
are not supported.- It is not possible to mix both
//
and/*
comments type to generate a toc
In order to generate a csstoc, the following conditions must apply:
- the css/scss file must have these two tags inside à block comment to delimit where toc should be placed.
<-- toc -->
<-- tocstop -->
- Titles are identified like this in
css
files:
-
Level 1 Title
/*1# Title's name
-
Level 2 Title
/*2# Title's name
-
Level 3 Title
/*3# Title's name
-
Level 4 Title
/*4# Title's name
- Titles are identified like this in
scss, sass, less
files:
-
Level 1 Title
//1# Title's name
-
Level 2 Title
//2# Title's name
-
Level 3 Title
//3# Title's name
-
Level 4 Title
//4# Title's name
- Download the file called
csstoc
and make it executable
wget https://raw.githubusercontent.com/Shammas44/csstoc/main/csstoc
chmod +x csstoc
- Store the newly created file somewhere available to your
$PATH
variable.
mv csstoc <path available to your $PATH variable>
- Install the vs code extension Command Runner.
- In vs code, edit your
settings.json
to add your custom command.
"command-runner.commands": {
"csstoc": "csstoc -f ${file}",
},
${file}
equals to the current opened file.
- Now you can effortlessly run your script from within the vs code command palette.