Skip to content

Commit 4bd04c8

Browse files
committed
update README.md with Table Of Contents
1 parent 0b5428d commit 4bd04c8

File tree

2 files changed

+243
-25
lines changed

2 files changed

+243
-25
lines changed

README.md

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
11
# Markdown Slides
22

3+
Table of Contents
4+
=================
5+
6+
* [Markdown Slides](#markdown-slides)
7+
* [English](#english)
8+
* [About](#about)
9+
* [What is it?](#what-is-it)
10+
* [Samples](#samples)
11+
* [Contributors](#contributors)
12+
* [Licence](#licence)
13+
* [Instalation](#instalation)
14+
* [Dependencies](#dependencies)
15+
* [Requirements](#requirements)
16+
* [Download](#download)
17+
* [Docker](#docker)
18+
* [Building docker image](#building-docker-image)
19+
* [Launch the container](#launch-the-container)
20+
* [How to use](#how-to-use)
21+
* [Creation](#creation)
22+
* [Notes](#notes)
23+
* [Levels](#levels)
24+
* [Numbering](#numbering)
25+
* [Configuration](#configuration)
26+
* [Build](#build)
27+
* [Releases notes](#releases-notes)
28+
* [Relese 1.0](#relese-10)
29+
* [Relese 2.0](#relese-20)
30+
* [Español](#español)
31+
* [Acerca de](#acerca-de)
32+
* [¿Qué es esto?](#qué-es-esto)
33+
* [Ejemplos](#ejemplos)
34+
* [Colaboradores](#colaboradores)
35+
* [Licencia](#licencia)
36+
* [Instalación](#instalación)
37+
* [Dependencias](#dependencias)
38+
* [Requisitos](#requisitos)
39+
* [Descarga](#descarga)
40+
* [Docker](#docker-1)
41+
* [Construir la imagen](#construir-la-imagen)
42+
* [Lanzar el contenedor](#lanzar-el-contenedor)
43+
* [Manejo](#manejo)
44+
* [Creación](#creación)
45+
* [Notas](#notas)
46+
* [Niveles](#niveles)
47+
* [Numeración](#numeración)
48+
* [Configuración](#configuración)
49+
* [Generación](#generación)
50+
* [Releases notes](#releases-notes-1)
51+
* [Relese 1.0](#relese-10-1)
52+
* [Relese 2.0](#relese-20-1)
53+
54+
Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
55+
356
## English
457

558
### About
@@ -178,11 +231,11 @@ BUILD_EPUB_BOOK='max'
178231
./build.sh [clean] [mode] [folder]
179232
~~~
180233

181-
- If you add [**cleaN**] the folder **lib** will be cleaned and the dependencies will be downloaded again.
234+
- If you add [**cleaN**] the folder **lib** will be cleaned and the dependencies will be downloaded again.
182235

183-
- [**mode**] can take the next values: **min, med o máx**.
236+
- [**mode**] can take the next values: **min, med o máx**.
184237

185-
- [**folder**] is the name of the folder wher to find the md files. If no folder name, it will convert all md files of all the folders.
238+
- [**folder**] is the name of the folder wher to find the md files. If no folder name, it will convert all md files of all the folders.
186239

187240
### Releases notes
188241

@@ -212,36 +265,29 @@ BUILD_EPUB_BOOK='max'
212265
#### Relese 2.0
213266

214267
- Export slides to:
215-
216268
- reveal-slides
217269
- reveal-slides-pdf
218270
- reveal-slides-online
219271
- reveal-slides-alternative
220272
- reveal-slides-alternative-pdf
221273
- reveal-slides-alternative-online
222-
223274
- Export books to:
224-
225275
- html-book
226276
- docx-book
227277
- epub-book
228-
229278
- Deprecated:
230-
231279
- beamer-slides
232280
- deck-slides
233281
- deck-slides-alternative
234282
- odt-book
235283
- pdf-book
236-
237284
- Added menu thanks to [Raul Jimenez Ortega] (https://github.com/hhkaos).
238285
- Added dockerfile thanks to [Rubén Gómez García] (https://github.com/kaneproject).
239286
- Clean zip files from libraries thanks to [Cesar Seoane] (https://github.com/cesarseoane).
240287
- Added type 'online' thanks to [Cesar Seoane] (https://github.com/cesarseoane).
241288
- Fixed bug HTTPS images thanks to [Cesar Seoane] (https://github.com/cesarseoane).
242289
- Loading the online libraries with HTTPS thanks to [Cesar Seoane] (https://github.com/cesarseoane).
243290
- Configuration PDF resolution thanks to [Cesar Seoane] (https://github.com/cesarseoane).
244-
245291
- New format 'epub'.
246292
- Added 'bash strict mode'.
247293
- Added 'build.properties' to configure file generation.
@@ -428,71 +474,60 @@ BUILD_EPUB_BOOK='max'
428474
./build.sh [clean] [modo] [carpeta]
429475
~~~
430476

431-
- Si añades [**clean**] se limpiará la carpeta **lib** y se volverán a bajar las dependencias.
477+
- Si añades [**clean**] se limpiará la carpeta **lib** y se volverán a bajar las dependencias.
432478

433-
- [**modo**] puede tomar los siguientes valores: **min, med o máx**.
479+
- [**modo**] puede tomar los siguientes valores: **min, med o máx**.
434480

435-
- [**carpeta**] es la carpeta donde va a buscar los ficheros md.
436-
Si no se indica nada convertirá todos los ficheros md de todas las carpetas.
481+
- [**carpeta**] es la carpeta donde va a buscar los ficheros md.
482+
Si no se indica nada convertirá todos los ficheros md de todas las carpetas.
437483

438484
### Releases notes
439485

440486
#### Relese 1.0
441487

442488
- Exporta slides a:
443-
444489
- reveal-slides
445490
- reveal-slides-pdf
446491
- reveal-slides-alternative
447492
- reveal-slides-alternative-pdf
448493
- beamer-slides
449494
- deck-slides
450495
- deck-slides-alternative
451-
452496
- Exporta books a:
453-
454497
- html-book
455498
- docx-book
456499
- odt-book
457500
- pdf-book
458-
459501
- Añadidos los modos de generación 'min', 'med' y 'max'.
460502
- Descarga automática de librerías externas.
461503
- Numeración (I), (II), (III)...
462504

463505
#### Relese 2.0
464506

465507
- Exporta slides a:
466-
467508
- reveal-slides
468509
- reveal-slides-pdf
469510
- reveal-slides-online
470511
- reveal-slides-alternative
471512
- reveal-slides-alternative-pdf
472513
- reveal-slides-alternative-online
473-
474514
- Exporta books a:
475-
476515
- html-book
477516
- docx-book
478517
- epub-book
479-
480518
- Deprecated:
481-
482519
- beamer-slides
483520
- deck-slides
484521
- deck-slides-alternative
485522
- odt-book
486523
- pdf-book
487-
488524
- Añadido menú gracias a [Raul Jimenez Ortega](https://github.com/hhkaos).
489525
- Añadido dockerfile gracías a [Rubén Gómez García](https://github.com/kaneproject).
490526
- Limpieza de ficheros zip de las librerías gracias a [Cesar Seoane](https://github.com/cesarseoane).
491527
- Añadido tipo 'online' gracias a [Cesar Seoane](https://github.com/cesarseoane).
492528
- Arreglado fallo imágenes HTTPS gracias a [Cesar Seoane](https://github.com/cesarseoane).
493529
- Carga de librerias 'online' por HTTPS gracias a [Cesar Seoane](https://github.com/cesarseoane).
494530
- Configuración resolución PDF gracias a [Cesar Seoane](https://github.com/cesarseoane).
495-
496531
- Nuevo formato 'epub'.
497532
- Añadido 'bash strict mode'.
498533
- Añadido 'build.properties' para configurar la generación de ficheros.

gh-md-toc

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Steps:
5+
#
6+
# 1. Download corresponding html file for some README.md:
7+
# curl -s $1
8+
#
9+
# 2. Discard rows where no substring 'user-content-' (github's markup):
10+
# awk '/user-content-/ { ...
11+
#
12+
# 3.1 Get last number in each row like ' ... </span></a>sitemap.js</h1'.
13+
# It's a level of the current header:
14+
# substr($0, length($0), 1)
15+
#
16+
# 3.2 Get level from 3.1 and insert corresponding number of spaces before '*':
17+
# sprintf("%*s", substr($0, length($0), 1)*2, " ")
18+
#
19+
# 4. Find head's text and insert it inside "* [ ... ]":
20+
# substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)
21+
#
22+
# 5. Find anchor and insert it inside "(...)":
23+
# substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8)
24+
#
25+
26+
gh_toc_version="0.4.7"
27+
28+
gh_user_agent="gh-md-toc v$gh_toc_version"
29+
30+
#
31+
# Download rendered into html README.md by its url.
32+
#
33+
#
34+
gh_toc_load() {
35+
local gh_url=$1
36+
37+
if type curl &>/dev/null; then
38+
curl --user-agent "$gh_user_agent" -s "$gh_url"
39+
elif type wget &>/dev/null; then
40+
wget --user-agent="$gh_user_agent" -qO- "$gh_url"
41+
else
42+
echo "Please, install 'curl' or 'wget' and try again."
43+
exit 1
44+
fi
45+
}
46+
47+
#
48+
# Converts local md file into html by GitHub
49+
#
50+
# ➥ curl -X POST --data '{"text": "Hello world github/linguist#1 **cool**, and #1!"}' https://api.github.com/markdown
51+
# <p>Hello world github/linguist#1 <strong>cool</strong>, and #1!</p>'"
52+
gh_toc_md2html() {
53+
local gh_file_md=$1
54+
curl -s --user-agent "$gh_user_agent" \
55+
--data-binary @"$gh_file_md" -H "Content-Type:text/plain" \
56+
https://api.github.com/markdown/raw
57+
}
58+
59+
#
60+
# Is passed string url
61+
#
62+
gh_is_url() {
63+
if [[ $1 == https* || $1 == http* ]]; then
64+
echo "yes"
65+
else
66+
echo "no"
67+
fi
68+
}
69+
70+
#
71+
# TOC generator
72+
#
73+
gh_toc(){
74+
local gh_src=$1
75+
local gh_src_copy=$1
76+
local gh_ttl_docs=$2
77+
78+
if [ "$gh_src" = "" ]; then
79+
echo "Please, enter URL or local path for a README.md"
80+
exit 1
81+
fi
82+
83+
84+
# Show "TOC" string only if working with one document
85+
if [ "$gh_ttl_docs" = "1" ]; then
86+
87+
echo "Table of Contents"
88+
echo "================="
89+
echo ""
90+
gh_src_copy=""
91+
92+
fi
93+
94+
if [ "$(gh_is_url "$gh_src")" == "yes" ]; then
95+
gh_toc_load "$gh_src" | gh_toc_grab "$gh_src_copy"
96+
else
97+
gh_toc_md2html "$gh_src" | gh_toc_grab "$gh_src_copy"
98+
fi
99+
}
100+
101+
#
102+
# Grabber of the TOC from rendered html
103+
#
104+
# $1 — a source url of document.
105+
# It's need if TOC is generated for multiple documents.
106+
#
107+
gh_toc_grab() {
108+
# if closed <h[1-6]> is on the new line, then move it on the prev line
109+
# for example:
110+
# was: The command <code>foo1</code>
111+
# </h1>
112+
# became: The command <code>foo1</code></h1>
113+
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' |
114+
# find strings that corresponds to template
115+
grep -E -o '<a\s*id="user-content-[^"]*".*</h[1-6]' |
116+
# remove code tags
117+
sed 's/<code>//' | sed 's/<\/code>//' |
118+
# now all rows are like:
119+
# <a id="user-content-..." href="..."><span ...></span></a> ... </h1
120+
# format result line
121+
# * $0 — whole string
122+
echo -e "$(awk -v "gh_url=$1" '{
123+
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')"
124+
}
125+
126+
#
127+
# Returns filename only from full path or url
128+
#
129+
gh_toc_get_filename() {
130+
echo "${1##*/}"
131+
}
132+
133+
#
134+
# Options hendlers
135+
#
136+
gh_toc_app() {
137+
local app_name="gh-md-toc"
138+
139+
if [ "$1" = '--help' ] || [ $# -eq 0 ] ; then
140+
echo "GitHub TOC generator ($app_name): $gh_toc_version"
141+
echo ""
142+
echo "Usage:"
143+
echo " $app_name src [src] Create TOC for a README file (url or local path)"
144+
echo " $app_name - Create TOC for markdown from STDIN"
145+
echo " $app_name --help Show help"
146+
echo " $app_name --version Show version"
147+
return
148+
fi
149+
150+
if [ "$1" = '--version' ]; then
151+
echo "$gh_toc_version"
152+
return
153+
fi
154+
155+
if [ "$1" = "-" ]; then
156+
if [ -z "$TMPDIR" ]; then
157+
TMPDIR="/tmp"
158+
elif [ -n "$TMPDIR" -a ! -d "$TMPDIR" ]; then
159+
mkdir -p "$TMPDIR"
160+
fi
161+
local gh_tmp_md
162+
gh_tmp_md=$(mktemp $TMPDIR/tmp.XXXXXX)
163+
while read input; do
164+
echo "$input" >> "$gh_tmp_md"
165+
done
166+
gh_toc_md2html "$gh_tmp_md" | gh_toc_grab ""
167+
return
168+
fi
169+
170+
for md in "$@"
171+
do
172+
echo ""
173+
gh_toc "$md" "$#"
174+
done
175+
176+
echo ""
177+
echo "Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)"
178+
}
179+
180+
#
181+
# Entry point
182+
#
183+
gh_toc_app "$@"

0 commit comments

Comments
 (0)