Skip to content

Commit

Permalink
Merge pull request #28 from chengweiv5/more-toc-levels
Browse files Browse the repository at this point in the history
More toc levels
  • Loading branch information
ekalinin authored Oct 21, 2016
2 parents 51e4538 + 7785c4c commit a8a01a6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion gh-md-toc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ gh_toc_grab() {
# format result line
# * $0 — whole string
echo -e "$(awk -v "gh_url=$1" '{
print sprintf("%*s", substr($0, length($0), 1)*2, " ") "* [" substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)"](" gh_url substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8) ")"}' | sed 'y/+/ /; s/%/\\x/g')"
print sprintf("%*s", substr($0, length($0), 1)*3, " ") "* [" substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)"](" gh_url substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8) ")"}' | sed 'y/+/ /; s/%/\\x/g')"
}

#
Expand Down
118 changes: 59 additions & 59 deletions tests/tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ load test_helper

assert_equal "${lines[0]}" "Table of Contents"
assert_equal "${lines[1]}" "================="
assert_equal "${lines[2]}" " * [gh-md-toc](#gh-md-toc)"
assert_equal "${lines[3]}" " * [Table of contents](#table-of-contents)"
assert_equal "${lines[4]}" " * [Installation](#installation)"
assert_equal "${lines[5]}" " * [Usage](#usage)"
assert_equal "${lines[6]}" " * [STDIN](#stdin)"
assert_equal "${lines[7]}" " * [Local files](#local-files)"
assert_equal "${lines[8]}" " * [Remote files](#remote-files)"
assert_equal "${lines[9]}" " * [Multiple files](#multiple-files)"
assert_equal "${lines[10]}" " * [Combo](#combo)"
assert_equal "${lines[11]}" " * [Tests](#tests)"
assert_equal "${lines[12]}" " * [Dependency](#dependency)"
assert_equal "${lines[2]}" " * [gh-md-toc](#gh-md-toc)"
assert_equal "${lines[3]}" " * [Table of contents](#table-of-contents)"
assert_equal "${lines[4]}" " * [Installation](#installation)"
assert_equal "${lines[5]}" " * [Usage](#usage)"
assert_equal "${lines[6]}" " * [STDIN](#stdin)"
assert_equal "${lines[7]}" " * [Local files](#local-files)"
assert_equal "${lines[8]}" " * [Remote files](#remote-files)"
assert_equal "${lines[9]}" " * [Multiple files](#multiple-files)"
assert_equal "${lines[10]}" " * [Combo](#combo)"
assert_equal "${lines[11]}" " * [Tests](#tests)"
assert_equal "${lines[12]}" " * [Dependency](#dependency)"
assert_equal "${lines[13]}" "Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)"

}
Expand All @@ -30,10 +30,10 @@ load test_helper

assert_equal "${lines[0]}" "Table of Contents"
assert_equal "${lines[1]}" "================="
assert_equal "${lines[2]}" " * [sitemap.js](#sitemapjs)"
assert_equal "${lines[3]}" " * [Installation](#installation)"
assert_equal "${lines[4]}" " * [Usage](#usage)"
assert_equal "${lines[5]}" " * [License](#license)"
assert_equal "${lines[2]}" " * [sitemap.js](#sitemapjs)"
assert_equal "${lines[3]}" " * [Installation](#installation)"
assert_equal "${lines[4]}" " * [Usage](#usage)"
assert_equal "${lines[5]}" " * [License](#license)"
assert_equal "${lines[6]}" "Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)"
}

Expand All @@ -43,39 +43,39 @@ load test_helper
https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md
assert_success

assert_equal "${lines[0]}" " * [gh-md-toc](README.md#gh-md-toc)"
assert_equal "${lines[1]}" " * [Table of contents](README.md#table-of-contents)"
assert_equal "${lines[2]}" " * [Installation](README.md#installation)"
assert_equal "${lines[3]}" " * [Usage](README.md#usage)"
assert_equal "${lines[4]}" " * [STDIN](README.md#stdin)"
assert_equal "${lines[5]}" " * [Local files](README.md#local-files)"
assert_equal "${lines[6]}" " * [Remote files](README.md#remote-files)"
assert_equal "${lines[7]}" " * [Multiple files](README.md#multiple-files)"
assert_equal "${lines[8]}" " * [Combo](README.md#combo)"
assert_equal "${lines[9]}" " * [Tests](README.md#tests)"
assert_equal "${lines[10]}" " * [Dependency](README.md#dependency)"
assert_equal "${lines[11]}" " * [sitemap.js](https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md#sitemapjs)"
assert_equal "${lines[12]}" " * [Installation](https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md#installation)"
assert_equal "${lines[13]}" " * [Usage](https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md#usage)"
assert_equal "${lines[14]}" " * [License](https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md#license)"
assert_equal "${lines[0]}" " * [gh-md-toc](README.md#gh-md-toc)"
assert_equal "${lines[1]}" " * [Table of contents](README.md#table-of-contents)"
assert_equal "${lines[2]}" " * [Installation](README.md#installation)"
assert_equal "${lines[3]}" " * [Usage](README.md#usage)"
assert_equal "${lines[4]}" " * [STDIN](README.md#stdin)"
assert_equal "${lines[5]}" " * [Local files](README.md#local-files)"
assert_equal "${lines[6]}" " * [Remote files](README.md#remote-files)"
assert_equal "${lines[7]}" " * [Multiple files](README.md#multiple-files)"
assert_equal "${lines[8]}" " * [Combo](README.md#combo)"
assert_equal "${lines[9]}" " * [Tests](README.md#tests)"
assert_equal "${lines[10]}" " * [Dependency](README.md#dependency)"
assert_equal "${lines[11]}" " * [sitemap.js](https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md#sitemapjs)"
assert_equal "${lines[12]}" " * [Installation](https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md#installation)"
assert_equal "${lines[13]}" " * [Usage](https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md#usage)"
assert_equal "${lines[14]}" " * [License](https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md#license)"
assert_equal "${lines[15]}" "Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)"
}

@test "TOC for markdown from stdin" {
cat README.md | {
run $BATS_TEST_DIRNAME/../gh-md-toc -
assert_success
assert_equal "${lines[0]}" " * [gh-md-toc](#gh-md-toc)"
assert_equal "${lines[1]}" " * [Table of contents](#table-of-contents)"
assert_equal "${lines[2]}" " * [Installation](#installation)"
assert_equal "${lines[3]}" " * [Usage](#usage)"
assert_equal "${lines[4]}" " * [STDIN](#stdin)"
assert_equal "${lines[5]}" " * [Local files](#local-files)"
assert_equal "${lines[6]}" " * [Remote files](#remote-files)"
assert_equal "${lines[7]}" " * [Multiple files](#multiple-files)"
assert_equal "${lines[8]}" " * [Combo](#combo)"
assert_equal "${lines[9]}" " * [Tests](#tests)"
assert_equal "${lines[10]}" " * [Dependency](#dependency)"
assert_equal "${lines[0]}" " * [gh-md-toc](#gh-md-toc)"
assert_equal "${lines[1]}" " * [Table of contents](#table-of-contents)"
assert_equal "${lines[2]}" " * [Installation](#installation)"
assert_equal "${lines[3]}" " * [Usage](#usage)"
assert_equal "${lines[4]}" " * [STDIN](#stdin)"
assert_equal "${lines[5]}" " * [Local files](#local-files)"
assert_equal "${lines[6]}" " * [Remote files](#remote-files)"
assert_equal "${lines[7]}" " * [Multiple files](#multiple-files)"
assert_equal "${lines[8]}" " * [Combo](#combo)"
assert_equal "${lines[9]}" " * [Tests](#tests)"
assert_equal "${lines[10]}" " * [Dependency](#dependency)"
}
}

Expand Down Expand Up @@ -107,42 +107,42 @@ load test_helper

@test "TOC for non-english chars, #6, #10" {
run $BATS_TEST_DIRNAME/../gh-md-toc \
https://github.com/ekalinin/envirius/blob/f939d3b6882bfb6ecb28ef7b6e62862f934ba945/README.ru.md
https://github.com/ekalinin/envirius/blob/f939d3b6882bfb6ecb28ef7b6e62862f934ba945/README.ru.md
assert_success

assert_equal "${lines[2]}" " * [envirius](#envirius)"
assert_equal "${lines[3]}" " * [Идея](#Идея)"
assert_equal "${lines[4]}" " * [Особенности](#Особенности)"
assert_equal "${lines[5]}" " * [Установка](#Установка)"
assert_equal "${lines[2]}" " * [envirius](#envirius)"
assert_equal "${lines[3]}" " * [Идея](#Идея)"
assert_equal "${lines[4]}" " * [Особенности](#Особенности)"
assert_equal "${lines[5]}" " * [Установка](#Установка)"


run $BATS_TEST_DIRNAME/../gh-md-toc \
https://github.com/jlevy/the-art-of-command-line/blob/217da3b4fa751014ecc122fd9fede2328a7eeb3e/README-zh.md
assert_success

assert_equal "${lines[2]}" " * [命令行的艺术](#命令行的艺术)"
assert_equal "${lines[3]}" " * [必读](#必读)"
assert_equal "${lines[4]}" " * [基础](#基础)"
assert_equal "${lines[5]}" " * [日常使用](#日常使用)"
assert_equal "${lines[2]}" " * [命令行的艺术](#命令行的艺术)"
assert_equal "${lines[3]}" " * [必读](#必读)"
assert_equal "${lines[4]}" " * [基础](#基础)"
assert_equal "${lines[5]}" " * [日常使用](#日常使用)"


run $BATS_TEST_DIRNAME/../gh-md-toc \
https://github.com/jlevy/the-art-of-command-line/blob/217da3b4fa751014ecc122fd9fede2328a7eeb3e/README-pt.md
assert_success

assert_equal "${lines[2]}" " * [A arte da linha de comando](#a-arte-da-linha-de-comando)"
assert_equal "${lines[3]}" " * [Meta](#meta)"
assert_equal "${lines[4]}" " * [Básico](#básico)"
assert_equal "${lines[5]}" " * [Uso diário](#uso-diário)"
assert_equal "${lines[2]}" " * [A arte da linha de comando](#a-arte-da-linha-de-comando)"
assert_equal "${lines[3]}" " * [Meta](#meta)"
assert_equal "${lines[4]}" " * [Básico](#básico)"
assert_equal "${lines[5]}" " * [Uso diário](#uso-diário)"
}

@test "TOC for text with backquote, #13" {
run $BATS_TEST_DIRNAME/../gh-md-toc tests/test_backquote.md
assert_success

assert_equal "${lines[2]}" " * [The command foo1](#the-command-foo1)"
assert_equal "${lines[3]}" " * [The command foo2 is better](#the-command-foo2-is-better)"
assert_equal "${lines[4]}" " * [The command bar1](#the-command-bar1)"
assert_equal "${lines[5]}" " * [The command bar2 is better](#the-command-bar2-is-better)"
assert_equal "${lines[6]}" " * [The command bar3 is the best](#the-command-bar3-is-the-best)"
assert_equal "${lines[2]}" " * [The command foo1](#the-command-foo1)"
assert_equal "${lines[3]}" " * [The command foo2 is better](#the-command-foo2-is-better)"
assert_equal "${lines[4]}" " * [The command bar1](#the-command-bar1)"
assert_equal "${lines[5]}" " * [The command bar2 is better](#the-command-bar2-is-better)"
assert_equal "${lines[6]}" " * [The command bar3 is the best](#the-command-bar3-is-the-best)"
}

0 comments on commit a8a01a6

Please sign in to comment.