Skip to content

Commit dae8c02

Browse files
committed
Prepared internal data structures
1 parent f7bafe3 commit dae8c02

1 file changed

Lines changed: 45 additions & 7 deletions

File tree

AAH2html.ahk

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,67 @@ FileRead, Input, README.md
4343

4444
Entries := []
4545
Sections := []
46+
47+
SectionHierarchy := []
48+
EntriesNEW := []
49+
Section2Name := "_EMPTY_"
50+
Section3Name := "_EMPTY_"
51+
Section4Name := "_EMPTY_"
52+
4653
for each, Line in StrSplit(Input, "`n", "`r")
4754
{
48-
if RegExMatch(Line, "^##\s+(.*)$", Match) ; New section
55+
56+
if RegExMatch(Line, "^##") ; New section
4957
{
50-
if (Entries.MaxIndex()) ; Previous section done, so go ahead and write the page
58+
if RegExMatch(Line, "^##\s+(.*)\s*$", Match) ; New level 2 section - starting with ##
59+
{
60+
if (Entries.MaxIndex()) ; Previous section done, so go ahead and write the page
61+
{
62+
FileOpen(Section2Name ".html", "w").Write(RenderPage(Section2Name, Entries))
63+
Sections.Insert({URL: Section2Name ".html", Name: Section2Name}) ; Show in the index page
64+
Entries := []
65+
}
66+
Section2Name := Match1
67+
SectionHierarchy[Section2Name] := []
68+
Section3Name := "_EMPTY_"
69+
Section4Name := "_EMPTY_"
70+
}
71+
else if RegExMatch(Line, "^###\s+(.*)\s*$", Match) ; New level 3 section - starting with ###
72+
{
73+
Section3Name := Match1
74+
Section4Name := "_EMPTY_"
75+
76+
if !(SectionHierarchy.HasKey(Section2Name))
77+
SectionHierarchy[Section2Name] := []
78+
SectionHierarchy[Section2Name][Section3Name] := []
79+
}
80+
else if RegExMatch(Line, "^####\s+(.*)\s*$", Match) ; New level 4 section - starting with ####
5181
{
52-
FileOpen(SectionName ".html", "w").Write(RenderPage(SectionName, Entries))
53-
Sections.Insert({URL: SectionName ".html", Name: SectionName}) ; Show in the index page
54-
Entries := []
82+
Section4Name := Match1
83+
if !(SectionHierarchy[Section2Name].HasKey(Section3Name))
84+
SectionHierarchy[Section2Name][Section3Name] := []
85+
SectionHierarchy[Section2Name][Section3Name][Section4Name] := []
5586
}
56-
SectionName := Match1
5787
}
5888
else if RegExMatch(Line, "^\* \[(?P<Name>.+?)\]\((?P<URL>[^)]+)\)(?: by (?P<Author>[^\-]+?))?(?: - (?P<Desc>.+))?$", Match)
5989
{
6090
MatchDesc := RegExReplace(MatchDesc, "\[(.*?)\]\((.*?)\)", "<a href='$2'>$1</a>")
6191
Entries.Insert({URL:MatchUrl, Name:MatchName, Desc:MatchDesc})
92+
93+
if !(SectionHierarchy[Section2Name].HasKey(Section3Name))
94+
SectionHierarchy[Section2Name][Section3Name] := []
95+
if !(SectionHierarchy[Section2Name][Section3Name].HasKey(Section4Name))
96+
SectionHierarchy[Section2Name][Section3Name][Section4Name] := []
97+
SectionHierarchy[Section2Name][Section3Name][Section4Name].Insert(MatchName)
98+
EntriesNEW[MatchName] := []
99+
EntriesNEW[MatchName].Insert({URL:MatchUrl, Name:MatchName, Desc:MatchDesc})
62100
}
63101
}
64102

65103
; Fill in the last section
66104
if (Entries.MaxIndex())
67105
{
68-
FileOpen(SectionName ".html", "w").Write(RenderPage(SectionName, Entries))
106+
FileOpen(Section2Name ".html", "w").Write(RenderPage(SectionName, Entries))
69107
Sections.Insert({URL: SectionName ".html", Name: SectionName})
70108
Entries := []
71109
}

0 commit comments

Comments
 (0)