fix anchors in table of contents

This commit is contained in:
Alex Grintsvayg 2018-11-02 14:35:20 -04:00
parent b84c209aa4
commit a49b5f71aa
4 changed files with 78 additions and 19 deletions

View file

@ -1,3 +1,3 @@
index.html: index.md head.html
./bin/gh-md-toc --insert index.md
./bin/mmark-linux-amd64 -head head.html -html index.md > index.html
./bin/mmark-linux-amd64 -head head.html -html index.md > index.html
./bin/toc.sh index.html index.md

59
bin/toc.sh Executable file
View file

@ -0,0 +1,59 @@
#!/bin/bash
set -euo pipefail
# set -x
HTML=${1:-}
MARKDOWN=${2:-}
if [ -z "$HTML" -o -z "$MARKDOWN" ]; then
echo "Usage: $0 HTML MARKDOWN"
exit 1
fi
if [ ! -f "${HTML}" ]; then
echo "HTML file not found"
exit 1
fi
if [ ! -f "${MARKDOWN}" ]; then
echo "MARKDOWN file not found"
exit 1
fi
regex='<h([2-6]) id="([^"]+)">([^<]+)</h'
toc=''
while read line; do
if [[ $line =~ $regex ]]; then
level="${BASH_REMATCH[1]}"
id="${BASH_REMATCH[2]}"
header="${BASH_REMATCH[3]}"
[ -n "$toc" ] && printf -v toc "$toc\n"
for ((i=$level-2; i>0; i--)); do toc="${toc} "; done
toc="${toc}* [${header}](#${id})"
fi
done < "${HTML}"
# fix sed on mac
sed='sed -i'
if [[ "$(uname)" == "Darwin" ]]; then
sed='sed -i ""'
fi
ts="<\!--ts-->"
te="<\!--te-->"
tmp="$(mktemp)"
function finish {
rm "$tmp"
}
trap finish EXIT
echo "${toc}" > "${tmp}"
# clear old toc
$sed "/${ts}/,/${te}/{//!d;}" "$MARKDOWN"
# insert toc
$sed "/${ts}/r ${tmp}" "$MARKDOWN"

View file

@ -83,7 +83,7 @@
## Table of Contents
<!-- this TOC is only here for github or js-challenged browsers -->
<!-- this TOC is autogenerated for github preview or js-challenged browsers -->
<!--ts-->
* [Introduction](#introduction)
@ -255,13 +255,13 @@
<dl>
<dt>claimId</dt>
<dd>A 20-byte hash unique among all claims. See [Claim Identifier Generation](#claim-identifier-generation).</dd>
<dd>A 20-byte hash unique among all claims. See <a href="#fixme">Claim Identifier Generation</a>.</dd>
<dt>name</dt>
<dd>A normalized UTF-8 string of up to 255 bytes used to address the claim. See [URLs](#urls) and [Normalization](#normalization).</dd>
<dd>A normalized UTF-8 string of up to 255 bytes used to address the claim. See <a href="#urls">URLs</a> and <a href="#normalization">Normalization</a>.</dd>
<dt>amount</dt>
<dd>A quantity of tokens used to stake the claim. See [Controlling](#controlling).</dd>
<dd>A quantity of tokens used to stake the claim. See <a href="#controlling">Controlling</a>.</dd>
<dt>value</dt>
<dd>Metadata about a stream or a channel. See [Metadata](#metadata).</dd>
<dd>Metadata about a stream or a channel. See <a href="#metadata">Metadata</a>.</dd>
</dl>

View file

@ -33,7 +33,7 @@ A> For more technical information about LBRY, visit [lbry.tech](https://lbry.tec
## Table of Contents
<!-- this TOC is only here for github or js-challenged browsers -->
<!-- this TOC is autogenerated for github preview or js-challenged browsers -->
<!--ts-->
* [Introduction](#introduction)
@ -41,12 +41,12 @@ A> For more technical information about LBRY, visit [lbry.tech](https://lbry.tec
* [Conventions and Terminology](#conventions-and-terminology)
* [Blockchain](#blockchain)
* [Claims](#claims)
* [Properties {#claim-properties}](#properties-claim-properties)
* [Properties](#claim-properties)
* [Example Claim](#example-claim)
* [Operations {#claim-operations}](#operations-claim-operations)
* [Operations](#claim-operations)
* [Supports](#supports)
* [Claimtrie](#claimtrie)
* [Statuses {#claim-statuses}](#statuses-claim-statuses)
* [Statuses](#claim-statuses)
* [Accepted](#accepted)
* [Abandoned](#abandoned)
* [Active](#active)
@ -71,7 +71,7 @@ A> For more technical information about LBRY, visit [lbry.tech](https://lbry.tec
* [Claim Sequence](#claim-sequence-1)
* [Bid Position](#bid-position-1)
* [ChannelName and ClaimName](#channelname-and-claimname)
* [Examples {#url-resolution-examples}](#examples-url-resolution-examples)
* [Examples](#url-resolution-examples)
* [Design Notes](#design-notes)
* [Transactions](#transactions)
* [Operations and Opcodes](#operations-and-opcodes)
@ -84,7 +84,7 @@ A> For more technical information about LBRY, visit [lbry.tech](https://lbry.tec
* [Block Rewards](#block-rewards)
* [Metadata](#metadata)
* [Specification](#specification)
* [Example {#metadata-example}](#example-metadata-example)
* [Example](#metadata-example)
* [Key Fields](#key-fields)
* [Source and Stream Hashes](#source-and-stream-hashes)
* [Fees and Fee Structure](#fees-and-fee-structure)
@ -92,9 +92,9 @@ A> For more technical information about LBRY, visit [lbry.tech](https://lbry.tec
* [Thumbnail](#thumbnail)
* [Content Type](#content-type)
* [Certificate](#certificate)
* [Channels (Identities) {#channels}](#channels-identities-channels)
* [Channels (Identities)](#channels)
* [Example Channel Metadata](#example-channel-metadata)
* [Validation {#metadata-validation}](#validation-metadata-validation)
* [Validation](#metadata-validation)
* [Data](#data)
* [Encoding](#encoding)
* [Blobs](#blobs)
@ -210,13 +210,13 @@ Claims have four properties:
<dl>
<dt>claimId</dt>
<dd>A 20-byte hash unique among all claims. See [Claim Identifier Generation](#claim-identifier-generation).</dd>
<dd>A 20-byte hash unique among all claims. See <a href="#fixme">Claim Identifier Generation</a>.</dd>
<dt>name</dt>
<dd>A normalized UTF-8 string of up to 255 bytes used to address the claim. See [URLs](#urls) and [Normalization](#normalization).</dd>
<dd>A normalized UTF-8 string of up to 255 bytes used to address the claim. See <a href="#urls">URLs</a> and <a href="#normalization">Normalization</a>.</dd>
<dt>amount</dt>
<dd>A quantity of tokens used to stake the claim. See [Controlling](#controlling).</dd>
<dd>A quantity of tokens used to stake the claim. See <a href="#controlling">Controlling</a>.</dd>
<dt>value</dt>
<dd>Metadata about a stream or a channel. See [Metadata](#metadata).</dd>
<dd>Metadata about a stream or a channel. See <a href="#metadata">Metadata</a>.</dd>
</dl>
#### Example Claim