config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 651e619e66fedeb8643790f61aa3329596828565
parent c7b5d53419a248b16034b3cfe52431eb4a6ac34f
Author: Jacob R. Edwards <n/a>
Date:   Fri,  3 Dec 2021 15:26:07 -0800

Add script to number markdown headings

Diffstat:
Alocal/bin/bin/mdnh | 27+++++++++++++++++++++++++++
1 file changed, 27 insertions(+), 0 deletions(-)

diff --git a/local/bin/bin/mdnh b/local/bin/bin/mdnh @@ -0,0 +1,27 @@ +#!/usr/bin/awk -f +# Copyright 2021 Jacob R. Edwards +# Number Markdown headings + +status = match($0, "^#+") > 0 { + level = RLENGTH; + ++counts[level]; + + for (i = level + 1; counts[i]; ++i) + counts[i] = 0; + + for (i = 1; i < level; ++i) + if (!counts[i]) + counts[i] = 1; + + markup = ""; + num = ""; + for (i = 1; i <= level; ++i) { + markup = markup "#"; + num = num counts[i] "."; + } + + sub("^#+ ?", "", $0); + printf "%s %s %s\n", markup, num, $0; +} + +!status