Last active
May 12, 2017 04:38
-
-
Save kencoba/b0069d11c5b85feedf0d7c943625ed80 to your computer and use it in GitHub Desktop.
Add header number to markdown file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Markdown_AddHeaderNumber | |
# input: Markdown.md | |
# output: Markdown.md added number on headers | |
# | |
# header format | |
# | |
# ```Markdown | |
# # 1. header | |
# ## 1.1. header | |
# ``` | |
BEGIN { | |
h1 = 0 | |
h2 = 0 | |
h3 = 0 | |
h4 = 0 | |
h5 = 0 | |
h6 = 0 | |
h7 = 0 | |
number = /[0-9\.]+/ | |
} | |
$1 == "#" && $2 ~ /[0-9.]+/ { | |
$2 = ++h1 "." | |
h2 = 0; h3 = 0; h4 = 0; h5 = 0; h6 = 0; h7 = 0; | |
} | |
$1 == "##" && $2 ~ /[0-9.]+/ { | |
$2 = h1 "." ++h2 | |
h3 = 0; h4 = 0; h5 = 0; h6 = 0; h7 = 0; | |
} | |
$1 == "###" && $2 ~ /[0-9.]+/ { | |
$2 = h1 "." h2 "." ++h3 | |
h4 = 0; h5 = 0; h6 = 0; h7 = 0; | |
} | |
$1 == "####" && $2 ~ /[0-9.]+/ { | |
$2 = h1 "." h2 "." h3 "." ++h4 | |
h5 = 0; h6 = 0; h7 = 0; | |
} | |
$1 == "#####" && $2 ~ /[0-9.]+/ { | |
$2 = h1 "." h2 "." h3 "." h4 "." ++h5 | |
h6 = 0; h7 = 0; | |
} | |
$1 == "######" && $2 ~ /[0-9.]+/ { | |
$2 = h1 "." h2 "." h3 "." h4 "." h5 "." ++h6 | |
h7 = 0; | |
} | |
$1 == "#######" && $2 ~ /[0-9.]+/ { | |
$2 = h1 "." h2 "." h3 "." h4 "." h5 "." h6 "." ++h7 | |
} | |
$1 ~ /[^#]+/ | |
$0 == "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment