Continuing my journey from last week, as I got to implementing my regex solutions into telescope I decided to check different posts one more time for use cases I may have skipped over one more time. I found that I skipped one and made a mistake in my paragraph regex.
Firstly, I found that many students using blogspot as their blogging platform had posts that we’re offenders of creating whitespace only blocks and nesting <br> elements in <div> and <p> elements as well as the creation of <p> elements. Secondly, I decided to revisit my methodology of paragraph element removal. I decided that <br> elements wrapped in <p> elements should just be replaced with a single <br> rather than being deleted out right as I originally planned, this logic was also going to be applied to <br> elements wrapped in <div> elements since both happened to appear on blogspot posts.
So with this new knowledge and methodology I created a single monster of a regular expression that finds multiple <br> elements and any <br> elements wrapped by <div> and <p> elements to be replaced with a single <br> and with the inspiration of the remove anchor functionality that was already present in telescope, I created a very similar function that would remove paragraphs as long as they only contained whitespace so no regex required!
This new regex is a beast:
Here it is in action:
So, I wrote a function that replaces the matches found above with a single <br> and then passes it to jsdom to create a new virtualDOM object that telescope should then display.
I wrote tests for the two functions implemented and ensured that they worked with jest, made sure my linting was fine as it wasn’t last time and I had to re-commit a stuff… and I pushed it to it’s own branch and created a pull request. Job done.
I really enjoyed this course and I think it will finally push me to try and contribute more as I always wanted to but just couldn’t find the courage to start. I ended up learning a ton of new things and look forward to breaking more things! or uh fixing them.. yep.