Skip to content

Commit

Permalink
Update for a new GH HTML layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ekalinin committed Mar 3, 2024
1 parent b985c02 commit 7d0a86b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions gh-md-toc
Expand Up @@ -23,7 +23,7 @@
# substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8)
#

gh_toc_version="0.9.1"
gh_toc_version="0.10.0"

gh_user_agent="gh-md-toc v$gh_toc_version"

Expand Down Expand Up @@ -253,7 +253,7 @@ gh_toc_grab() {
echoargs="-e"
awkscript='{
level = substr($0, 3, 1)
text = substr($0, match($0, /<\/span><\/a>.*<\/h/)+11, RLENGTH-14)
text = substr($0, match($0, /">.*<\/h/)+2, RLENGTH-5)
href = substr($0, match($0, '$href_regex')+6, RLENGTH-7)
'"$common_awk_script"'
}'
Expand All @@ -270,7 +270,7 @@ gh_toc_grab() {
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<span/<span/g' |

# find strings that corresponds to template
$grepcmd '<h.*id="user-content-[^"]*".*</h[1-6]' |
$grepcmd '<h.*class="heading-element".*</a' |

# remove code tags
sed 's/<code>//g' | sed 's/<\/code>//g' |
Expand All @@ -279,7 +279,7 @@ gh_toc_grab() {
sed 's/<g-emoji[^>]*[^<]*<\/g-emoji> //g' |

# now all rows are like:
# <h1 id="user-content-..."><a href="..."> ... <span ...></span></a></h1
# <h1 class="heading-element">title</h1><a href="..."><span>..</span></a>
# format result line
# * $0 - whole string
# * last element of each row: "</hN" where N in (1,2,3,...)
Expand Down
20 changes: 10 additions & 10 deletions tests/tests.bats
Expand Up @@ -57,7 +57,7 @@ load test_helper
# @test "TOC for remote README.md" {
# run $BATS_TEST_DIRNAME/../gh-md-toc https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md
# assert_success
#
#
# assert_equal "${lines[0]}" "Table of Contents"
# assert_equal "${lines[1]}" "================="
# assert_equal "${lines[2]}" "* [sitemap.js](#sitemapjs)"
Expand All @@ -72,7 +72,7 @@ load test_helper
# README.md \
# 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)"
Expand Down Expand Up @@ -148,7 +148,7 @@ test_help() {
@test "--version" {
run $BATS_TEST_DIRNAME/../gh-md-toc --version
assert_success
assert_equal "${lines[0]}" "0.9.1"
assert_equal "${lines[0]}" "0.10.0"
assert_equal "${lines[1]}" "os: `uname -s`"
assert_equal "${lines[2]}" "arch: `uname -m`"
}
Expand All @@ -167,27 +167,27 @@ test_help() {
# run $BATS_TEST_DIRNAME/../gh-md-toc \
# 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]}" "* [Установка](#установка)"
#
#
#
#
# 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]}" " * [日常使用](#日常使用)"
#
#
#
#
# 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)"
Expand Down

0 comments on commit 7d0a86b

Please sign in to comment.