Validating flower brace{} liquid tag in markdown validator
0
votes
1
answer
44
views
WE have a markdown validator that authors use to validate their md files, One check in that is the liquid tag validation where we check for invalid liquid tags in the md files. My requirement is to add a validation to check whether the flower braces are used properly and are properly terminated. eg if an author opens 5 { , there should be equally 5 closing }. But we also have to exclude code blocks from this validation. any brackets inside a code block should not be validated. code blocks may be a 4 space indentation, 3 backticks or a single backtick.
bracecountopen=$(grep -o -i '{' $file | wc -l);
bracecountclose=$(grep -o -i '}' $file | wc -l);
if [ "$bracecountopen" != "$bracecountclose" ]; then
throw error
fi
for excluding code blocks
var+=$(grep '^\ \ \ \ [^>]' $file);
while IFS= read -n1 char; do
if [[ "$char" == "\`" ]]; then
if [ $flag = 1 ]; then
flag=0;
continue
fi
flag=1;
fi
if [ $flag = 1 ]; then
# var+=$char;
echo ""
fi
done <$file
codebraceopen=$(echo "$var" | grep -o -i '{' | wc -l)
codebraceclose=$(echo "$var" | grep -o -i '}' | wc -l)
let "bracecountopen=bracecountopen - codebraceopen"
let "bracecountclose=bracecountclose - codebraceclose"
Is this approach correct? Is there any better logic to achieve this?
The problem here is some author add a tab or 4 spaces before starting their code block with back ticks which makes the content appear twice in the 'var' , it is counted in the 4 space as well as the backticks check. How to fix this?
Asked by Anonymous
(1 rep)
Dec 15, 2022, 06:48 AM
Last activity: Dec 15, 2022, 10:24 AM
Last activity: Dec 15, 2022, 10:24 AM