#!/usr/bin/awk -f BEGIN { Init=0 } #This Init allows us to use FILENAME, if we didn't have to use it we could put all of this in BEGIN Init == 0 { #Disable init after 1st use Init=1 #Creation of SelfUrl SelfUrl="https://maplecircuit.dev/"tolower(substr(FILENAME, 8)) SelfUrl=(substr(SelfUrl, 1, length(SelfUrl)-3)".html") gsub(/[[:blank:]]/, "-", SelfUrl) #splitting FILENAME to get the PageName PathDeep=split(FILENAME, SplitPath, "/") PageName=SplitPath[PathDeep] sub(".md", "", PageName) #Set the using PathDeep Base="" if(PathDeep==1){Base="."} else { Base=".." while(PathDeep>=3) { Base=Base"/.." PathDeep=PathDeep-1 } } #Header code Header=(" "PageName"
MapleCircuit.dev

" PageName "

") #Code Block code Code="
"
	CodeAfter="
" #Variables BoolCode=0 FootNoteMode=0 Bullet=0 Numbered=0 Callout=0 RawPrint=0 Table=0 printf Header } #BoolCode is needed to manage Code Block #Anything other than 0 will run special code BoolCode == 4 {BoolCode=0} #0->no code #1->will wait 1 line #2->will print entry code #3->internal line #4->exit #Detect Code Block # ``` match($1, /^```/) != 0 { if(BoolCode == 0) { BoolCode=1 } else { gsub($1,CodeAfter) BoolCode=4 } } #If inside Code Block BoolCode != 0 { #Print the inside of the Code Block if(BoolCode >= 3){ print } #Print the start of a Code Block if(BoolCode == 2){ print(Code $0) BoolCode = 3 } #Skip first quote (already handled) if(BoolCode == 1){BoolCode = 2} } #For things that aren't part of a Code Block BoolCode == 0 { #Heading # # This is a big heading # ###### This is a small heading if(match($1, /^#/) != 0) { #Detect Footnote start if($0 == "# Sources:"){FootNoteMode=1} #Create the ID which will be used to link to a specific heading from a link Id=tolower($0) sub(/^#+ /, "", Id) gsub(/[[:blank:]]/, "-", Id) #Apply the specific heading size code # if($1 == "#") { $0=substr($0, 3) print("

"$0"

") ## } else if($1 == "##"){ $0=substr($0, 4) print("

"$0"

") ### } else if($1 == "###"){ $0=substr($0, 5) print("

"$0"

") #### } else if($1 == "####"){ $0=substr($0, 6) print("

"$0"

") ##### } else if($1 == "#####"){ $0=substr($0, 7) print("
"$0"
") ###### } else if($1 == "######"){ $0=substr($0, 8) print("
"$0"
") } #If NOT a heading } else { #Callout # >[!NOTE]- Title of the callout # >Content of the callout if(match($0, /^>\[!.*\]- /) != 0) { sub(/^>\[!.*\]- /, "") $0="
"$0"
" Callout=1 RawPrint=1 } else { if(Callout == 1) { if(match($0, /^>/) != 0) { sub(/^>/, "") } else { print("
") Callout=0 } } } #Table # | Block size | 4KiB | # | ------------------------ | -------------------------- | # | file system blocks | 2,147,483,647 | if(match($0, /^\| /) != 0) { if(Table == 0) { print("
") $0=substr($0, 2, length($0)-2) gsub(/ \| /, "" Table=1 } else if(match($0, /^\| --/) != 0) { $0="" } else { $0=substr($0, 2, length($0)-2) gsub(/ \| /, "" } RawPrint=1 } else { if(Table == 1) { print("
") $0="
"$0"
") $0="
"$0"
") Table=0 } } #Horizontal line # --- if($0 == "---") { $0="
" RawPrint=1 } #Bullet List # - Content of the bullet list # - This code will adapt to multiple line if(match($0, /^- /) != 0) { if(Bullet == 0){ print("
    ") } sub(/^- /, "
  • ") $0=$0"
  • " Bullet=Bullet+1 } else { if(Bullet != 0) { print("
") Bullet=0 } } #Numbered List # 1. Content of the numbered list # 2. This code will adapt to multiple line if(match($0, /^[0-9]+\. /) != 0) { if(Numbered == 0){ print("
    ") } sub(/^[0-9]+\. /, "
  1. ") $0=$0"
  2. " Numbered=Numbered+1 } else { if(Numbered != 0) { print("
") Numbered=0 } } #Upper Footnote Pickup # [^3] InLine=1 while(InLine == 1){ InLine=0 LFP=match($0, /\[\^[0-9]+\]/) if(LFP != 0){ TempLink=substr($0, (LFP+2)) gsub(/&/, "", TempLink) TempLink=substr(TempLink, 1, (match(TempLink, /\]/)-1 )) if(FootNoteMode == 0) { sub(/\[\^[0-9]+\]/, "["TempLink"]") } else if(FootNoteMode == 1) { FootNoteMode=2 sub(/\[\^[0-9]+\]/, "

  1. ") $0=($0"

  2. ") } else { sub(/\[\^[0-9]+\]/, "
  3. ") $0=($0"

  4. ") } InLine=1 } } #Inner Line Check #Local Link # [[Linux/Kernel/General Functions#Big Kernel Lock (BKL)|Big Kernel Lock (BKL)]] InLine=1 while(InLine == 1){ InLine=0 LLink=match($0, /\[\[.*\]\]/) if(LLink != 0){ TempLink=substr($0, (LLink+2), (match(substr($0, (LLink+3)), /]]/))) if(0!=match(TempLink, /^#/)){ if(0!=match(TempLink, /\|/)){ NameLLink=substr(TempLink, (match(TempLink, /\|/)+1)) TempLink=substr(TempLink, 0, (match(TempLink, /\|/)-1)) } else{NameLLink=substr(TempLink, 1)} sub(/#/, SelfUrl"#", TempLink) } else { sub(/.canvas/, "", TempLink) gsub(/&/, "", TempLink) #will extract name (what is after |) NameLLink=substr(TempLink,(match(TempLink, /\|/)+1)) #will remove name from TempLink TempLink=substr(TempLink, 0, (match(TempLink, /\|/)-1) ) #insert .html before # if it exist if(sub(/#/, ".html#", TempLink) == 0) {TempLink=(TempLink".html")} } TempLink=tolower(TempLink) gsub(/[[:blank:]]/, "-", TempLink) sub(/\[\[.*\]\]/, ""NameLLink"") InLine=1 } } #External Link # [My source is that I made it the F@#& up](https://www.youtube.com/watch?v=r7l0Rq9E8MY) InLine=1 while(InLine == 1){ InLine=0 gsub(/&/, "") ELink=match($0, /\[.*\]\(.*\)/) if(ELink != 0){ SBOffset=match(substr($0, (ELink+2)), /\]\(/ ) NameELink=substr($0, (ELink+1), SBOffset) UrlELink=substr($0, (ELink+SBOffset+3), match(substr($0, (ELink+SBOffset+4)), /\)/)) sub(/\[.*\]\(.*\)/, ""NameELink"") InLine=1 } } #Strong # **Strong text** InLine=1 while(InLine == 1){ InLine=0 if(match($0, /\*\*.*\*\*/) != 0){ sub(/\*\*/, "") sub(/\*\*/, "") InLine=1 } } #Highlight # ==Highlighted text== InLine=1 while(InLine == 1){ InLine=0 if(match($0, /==.*==/) != 0){ sub(/==/, "") sub(/==/, "") InLine=1 } } #Strike # ~~Text with a strike~~ InLine=1 while(InLine == 1){ InLine=0 if(match($0, /~~.*~~/) != 0){ sub(/~~/, "") sub(/~~/, "") InLine=1 } } #Italic (*) # *This text is in italic* InLine=1 while(InLine == 1){ InLine=0 if(match($0, /\*.*\*/) != 0){ sub(/\*/, "") sub(/\*/, "") InLine=1 } } #Italic (_) DISABLE FOR NOW # _This is in italic_ # InLine=1 # while(InLine == 1){ # InLine=0 # if(match($0, /_.*_/) != 0){ # sub(/_/, "") # sub(/_/, "") # InLine=1 # } # } #Code # `This is code` InLine=1 while(InLine == 1){ InLine=0 if(match($0, /`.*`/) != 0){ sub(/`/, "") sub(/`/, "") InLine=1 } } if(FootNoteMode == 2 || Bullet != 0 || Numbered != 0) { print } else if(RawPrint == 1) { print RawPrint=0 } else { print("

    "$0"

    ") } } } END { if(FootNoteMode == 2){print "
"} printf "
" }