")
#Code Block code
Code="
"
#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("
")
##
} else if($1 == "##"){
$0=substr($0, 4)
print("
")
###
} else if($1 == "###"){
$0=substr($0, 5)
print("
")
####
} else if($1 == "####"){
$0=substr($0, 6)
print("
")
#####
} else if($1 == "#####"){
$0=substr($0, 7)
print("
")
######
} else if($1 == "######"){
$0=substr($0, 8)
print("
")
}
#If NOT a heading
} else {
#Callout
# >[!NOTE]- Title of the callout
# >Content of the callout
if(match($0, /^>\[!.*\]- /) != 0) {
sub(/^>\[!.*\]- /, "")
$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(/ \| /, "")
$0=" | "$0" |
"
Table=1
}
else if(match($0, /^\| --/) != 0) {
$0=""
}
else {
$0=substr($0, 2, length($0)-2)
gsub(/ \| /, "")
$0=" | "$0" |
"
}
RawPrint=1
}
else {
if(Table == 1) {
print("
")
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]+\. /, "- ")
$0=$0"
"
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]+\]/, "")
} else if(FootNoteMode == 1) {
FootNoteMode=2
sub(/\[\^[0-9]+\]/, "
"}
printf "