/ {
melInsideCode = 1
}
/<\/code>/ {
melInsideCode = 0
}
melInsideCode == 0 && /^[ \t]*()?&/ {
newLine = ""
lineCopy = $0
while (match(lineCopy, /&(((::|[[{(:.])[^[:space:].:[{(<>)}\]&]+)|[\]})])/)) {
RSTART = RSTART + 5
RLENGTH = RLENGTH - 5
# Inside closing tag
if (RLENGTH == 1) {
replaceWith = MEL[topStack("mel"), MELCLOSE]
popStack("mel")
}
# Inside opening tag
else if (substr(lineCopy, RSTART, 1) ~ /[[{(]/) {
name = substr(lineCopy, RSTART + 1, RLENGTH - 1)
replaceWith = MEL[name, MELOPEN]
pushStack("mel", name)
}
# Inside paragraph/one line/insert
# TODO: currently all work as insert
else {
nameStart = 1 + (substr(lineCopy, RSTART + 1, 1) == ":")
name = substr(lineCopy, RSTART + nameStart, RLENGTH - nameStart)
replaceWith = MEL[name, MELSINGLE]
}
newLine = newLine substr(lineCopy, 0, RSTART - 6) replaceWith
lineCopy = substr(lineCopy, RSTART + RLENGTH)
}
$0 = newLine lineCopy
if (length(newLine) > 0)
gsub(/(
|<\/p>)/, "")
}