Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Last active April 2, 2020 13:27
Show Gist options
  • Select an option

  • Save JamieMason/c43e7ee1d078fc63e7c0f15746845c2e to your computer and use it in GitHub Desktop.

Select an option

Save JamieMason/c43e7ee1d078fc63e7c0f15746845c2e to your computer and use it in GitHub Desktop.

Revisions

  1. JamieMason revised this gist Apr 2, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions GET_GITHUB_TABLE_OF_CONTENTS.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ Paste this into the console in Google Chrome.
    ```js
    [].map
    .call(document.querySelectorAll('.anchor'), el =>
    `* [${el.nextSibling.nodeValue}](${el.getAttribute('href')})`
    `* [${el.parentNode.innerText}](${el.getAttribute('href')})`
    )
    .join('\n');
    ```
    @@ -29,7 +29,7 @@ The following version is longer, but will indent the items according to the head
    [].map
    .call(document.querySelectorAll('.anchor'), function(el) {
    var indents = ' '.repeat(parseFloat(el.parentNode.nodeName.charAt(1)) - 1);
    var label = el.nextSibling.nodeValue;
    var label = el.parentNode.innerText;
    var link = el.getAttribute('href');
    return `${indents}* [${label}](${link})`
    })
  2. JamieMason revised this gist Aug 16, 2016. 1 changed file with 13 additions and 6 deletions.
    19 changes: 13 additions & 6 deletions GET_GITHUB_TABLE_OF_CONTENTS.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ Paste this into the console in Google Chrome.
    .join('\n');
    ```

    The output should look something like this;
    The output if run on the [lodash README](https://github.com/lodash/lodash) should look something like this;

    > ```
    > "* [lodash v4.14.0](#lodash-v4140)
    @@ -21,11 +21,9 @@ The output should look something like this;
    > * [Module Formats](#module-formats)"
    > ```
    The above example was run at https://github.com/lodash/lodash.
    ## Include indentation
    **EDIT**
    The following version is longer, but will indent the list according to the headers;
    The following version is longer, but will indent the items according to the headers;
    ```javascript
    [].map
    @@ -36,4 +34,13 @@ The following version is longer, but will indent the list according to the heade
    return `${indents}* [${label}](${link})`
    })
    .join('\n');
    ```
    ```
    The output if run on the [lodash README](https://github.com/lodash/lodash) should look something like this;

    > ```
    > "* [lodash v4.15.0](#lodash-v4150)
    > * [Download](#download)
    > * [Why Lodash?](#why-lodash)
    > * [Module Formats](#module-formats)"
    > ```
  3. JamieMason revised this gist Aug 16, 2016. 1 changed file with 16 additions and 1 deletion.
    17 changes: 16 additions & 1 deletion GET_GITHUB_TABLE_OF_CONTENTS.md
    Original file line number Diff line number Diff line change
    @@ -21,4 +21,19 @@ The output should look something like this;
    > * [Module Formats](#module-formats)"
    > ```
    The above example was run at https://github.com/lodash/lodash.
    The above example was run at https://github.com/lodash/lodash.
    **EDIT**
    The following version is longer, but will indent the list according to the headers;
    ```javascript
    [].map
    .call(document.querySelectorAll('.anchor'), function(el) {
    var indents = ' '.repeat(parseFloat(el.parentNode.nodeName.charAt(1)) - 1);
    var label = el.nextSibling.nodeValue;
    var link = el.getAttribute('href');
    return `${indents}* [${label}](${link})`
    })
    .join('\n');
    ```
  4. JamieMason created this gist Jul 19, 2016.
    24 changes: 24 additions & 0 deletions GET_GITHUB_TABLE_OF_CONTENTS.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    ## Quick way to generate a table of contents from a GitHub README

    Visit the README.md on GitHub.

    Paste this into the console in Google Chrome.

    ```js
    [].map
    .call(document.querySelectorAll('.anchor'), el =>
    `* [${el.nextSibling.nodeValue}](${el.getAttribute('href')})`
    )
    .join('\n');
    ```

    The output should look something like this;

    > ```
    > "* [lodash v4.14.0](#lodash-v4140)
    > * [Download](#download)
    > * [Why Lodash?](#why-lodash)
    > * [Module Formats](#module-formats)"
    > ```
    The above example was run at https://github.com/lodash/lodash.