mirror of
https://github.com/VincentWei/minigui-docs.git
synced 2025-10-23 10:08:11 +08:00
auto generate TOC by using AWK
This commit is contained in:
53
programming-guide/generate_toc.awk
Normal file
53
programming-guide/generate_toc.awk
Normal file
@@ -0,0 +1,53 @@
|
||||
BEGIN { print "" }
|
||||
|
||||
#- [Basic Programming Concepts](#basic-programming-concepts)
|
||||
# + [Event Driven Programming](#event-driven-programming)
|
||||
# + [Three Runtime Modes of MiniGUI](#three-runtime-modes-of-minigui)
|
||||
#- [Hello, world!](#hello-world)
|
||||
# + [Header Files](#header-files)
|
||||
# + [Entrance of the Program](#entrance-of-the-program)
|
||||
# + [Joining a Layer in MiniGUI-Processes](#joining-a-layer-in-minigui-processes)
|
||||
# + [Creating and Showing Main Window](#creating-and-showing-main-window)
|
||||
# + [Window Procedure Function](#window-procedure-function)
|
||||
# + [Screen Output](#screen-output)
|
||||
# + [Exit of the Program](#exit-of-the-program)
|
||||
#- [Compiling, Linking and Running](#compiling-linking-and-running)
|
||||
#- [Writing Autotools Scripts for MiniGUI Application](#writing-autotools-scripts-for-minigui-application)
|
||||
|
||||
function get_anchor(title)
|
||||
{
|
||||
gsub(/-/, "_", title)
|
||||
gsub(/ /, "_", title)
|
||||
gsub(/\W/, "", title)
|
||||
gsub(/_/, "-", title)
|
||||
anchor = tolower(title)
|
||||
return anchor
|
||||
}
|
||||
|
||||
{
|
||||
if (match ($0, /^(#+) (.*)/, fields)) {
|
||||
level = fields[1]
|
||||
title = fields[2]
|
||||
|
||||
anchor = get_anchor(title)
|
||||
if (length(anchor) == 0) {
|
||||
print "BAD TITLE: " title
|
||||
next
|
||||
}
|
||||
|
||||
switch (length(level)) {
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
print "- [" title "](#" anchor ")"
|
||||
break;
|
||||
case 3:
|
||||
print " + [" title "](#" anchor ")"
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END { print "" }
|
||||
Reference in New Issue
Block a user