That is a good, if not easy, problem to solve!
In the result, I would like to take the following code in <blockquote> tag
function fold(initial, desired)
folds = 0 # initial number of folds
achieved = initial # initial thickness
results = []
while true
achieved = achieved * 2 # fold
#if achieved >= desired break end # if you want to exit before achieving
push!(results, achieved) # add to results
folds = folds + 1 # increment
if achieved >= desired break end # if you want to exit after achieving
end
return results
end
and color it by the language-specific keywords to look something like that:
What are the steps I would take?
- In JavaScript, I would find the next blockquote element
- Extract the text from it
- Parse the comments ( from # to the end of the line)
- Parse text by the white space (preserving white space)
- Compare each WORD token to the dictionary of the reserved word
- Do something about variable names
- Do something about variable values
- Wrap reserved words in <span color> tags
- Re-assemble to content of the <blockquote>
Since this is a several-evenings project, I will leave it for later.
If you are doing this, or have done something similar, please let me know in the comments.