Skip to content

Commit c836e5e

Browse files
jkburgesekalininvlad-diachenko
authored
Fix parsing of HTML returned from raw API (#144)
* Fix parsing of HTML returned from raw API Github must have changed something on their end, the HTML seems to have changed a little. * Update gh-md-toc Co-authored-by: Vladyslav Diachenko <[email protected]> --------- Co-authored-by: Eugene Kalinin <[email protected]> Co-authored-by: Vladyslav Diachenko <[email protected]>
1 parent 661b5c5 commit c836e5e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

gh-md-toc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,17 @@ gh_toc_grab() {
241241
grepcmd="pcregrep -o"
242242
echoargs=""
243243
awkscript='{
244-
level = substr($0, length($0), 1)
245-
text = substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)
244+
level = substr($0, 3, 1)
245+
text = substr($0, match($0, />[^<]*<span aria-hidden/)+1, RLENGTH-18)
246246
href = substr($0, match($0, "href=\"([^\"]+)?\"")+6, RLENGTH-7)
247247
'"$common_awk_script"'
248248
}'
249249
else
250250
grepcmd="grep -Eo"
251251
echoargs="-e"
252252
awkscript='{
253-
level = substr($0, length($0), 1)
254-
text = substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)
253+
level = substr($0, 3, 1)
254+
text = substr($0, match($0, />[^<]*<span aria-hidden/)+1, RLENGTH-18)
255255
href = substr($0, match($0, "href=\"[^\"]+?\"")+6, RLENGTH-7)
256256
'"$common_awk_script"'
257257
}'
@@ -266,7 +266,7 @@ gh_toc_grab() {
266266
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' |
267267

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

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

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

0 commit comments

Comments
 (0)