Skip to content

Commit 7d0a86b

Browse files
committed
Update for a new GH HTML layout
1 parent b985c02 commit 7d0a86b

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

gh-md-toc

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8)
2424
#
2525

26-
gh_toc_version="0.9.1"
26+
gh_toc_version="0.10.0"
2727

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

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

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

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

281281
# now all rows are like:
282-
# <h1 id="user-content-..."><a href="..."> ... <span ...></span></a></h1
282+
# <h1 class="heading-element">title</h1><a href="..."><span>..</span></a>
283283
# format result line
284284
# * $0 - whole string
285285
# * last element of each row: "</hN" where N in (1,2,3,...)

tests/tests.bats

+10-10
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ load test_helper
5757
# @test "TOC for remote README.md" {
5858
# run $BATS_TEST_DIRNAME/../gh-md-toc https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md
5959
# assert_success
60-
#
60+
#
6161
# assert_equal "${lines[0]}" "Table of Contents"
6262
# assert_equal "${lines[1]}" "================="
6363
# assert_equal "${lines[2]}" "* [sitemap.js](#sitemapjs)"
@@ -72,7 +72,7 @@ load test_helper
7272
# README.md \
7373
# https://github.com/ekalinin/sitemap.js/blob/6bc3eb12c898c1037a35a11b2eb24ababdeb3580/README.md
7474
# assert_success
75-
#
75+
#
7676
# assert_equal "${lines[0]}" "* [gh-md-toc](README.md#gh-md-toc)"
7777
# assert_equal "${lines[1]}" "* [Table of contents](README.md#table-of-contents)"
7878
# assert_equal "${lines[2]}" "* [Installation](README.md#installation)"
@@ -148,7 +148,7 @@ test_help() {
148148
@test "--version" {
149149
run $BATS_TEST_DIRNAME/../gh-md-toc --version
150150
assert_success
151-
assert_equal "${lines[0]}" "0.9.1"
151+
assert_equal "${lines[0]}" "0.10.0"
152152
assert_equal "${lines[1]}" "os: `uname -s`"
153153
assert_equal "${lines[2]}" "arch: `uname -m`"
154154
}
@@ -167,27 +167,27 @@ test_help() {
167167
# run $BATS_TEST_DIRNAME/../gh-md-toc \
168168
# https://github.com/ekalinin/envirius/blob/f939d3b6882bfb6ecb28ef7b6e62862f934ba945/README.ru.md
169169
# assert_success
170-
#
170+
#
171171
# assert_equal "${lines[2]}" "* [envirius](#envirius)"
172172
# assert_equal "${lines[3]}" " * [Идея](#идея)"
173173
# assert_equal "${lines[4]}" " * [Особенности](#особенности)"
174174
# assert_equal "${lines[5]}" "* [Установка](#установка)"
175-
#
176-
#
175+
#
176+
#
177177
# run $BATS_TEST_DIRNAME/../gh-md-toc \
178178
# https://github.com/jlevy/the-art-of-command-line/blob/217da3b4fa751014ecc122fd9fede2328a7eeb3e/README-zh.md
179179
# assert_success
180-
#
180+
#
181181
# assert_equal "${lines[2]}" "* [命令行的艺术](#命令行的艺术)"
182182
# assert_equal "${lines[3]}" " * [必读](#必读)"
183183
# assert_equal "${lines[4]}" " * [基础](#基础)"
184184
# assert_equal "${lines[5]}" " * [日常使用](#日常使用)"
185-
#
186-
#
185+
#
186+
#
187187
# run $BATS_TEST_DIRNAME/../gh-md-toc \
188188
# https://github.com/jlevy/the-art-of-command-line/blob/217da3b4fa751014ecc122fd9fede2328a7eeb3e/README-pt.md
189189
# assert_success
190-
#
190+
#
191191
# assert_equal "${lines[2]}" "* [A arte da linha de comando](#a-arte-da-linha-de-comando)"
192192
# assert_equal "${lines[3]}" " * [Meta](#meta)"
193193
# assert_equal "${lines[4]}" " * [Básico](#básico)"

0 commit comments

Comments
 (0)