innovationOUtside / nb_spellchecker

Simple tool to try support spell checking of Jupyter notebooks
MIT License
0 stars 0 forks source link

Useful style rule regexes #8

Open psychemedia opened 3 years ago

psychemedia commented 3 years ago

Run as eg

for i in content/*/.md/*.md; do  gsed -i 's/^\(#.*ctivity \)[–—-] \([a-zA-Z]\)/\1– \U\2/g' "$i"; done

Check style of Activity header - lower case first word, en-dash eg ## 1.2.3 Activity – lower case Also account for Opetional activity.

gsed -i 's/^\(#.*ctivity \)[–—-] \([a-zA-Z]\)/\1– \U\2/g'

echo '### 4.2.1 Activity – No Yes' | gsed -i 's/^\(#.*ctivity \)[–—-] \([a-zA-Z]\)/\1– \L\2/g' 

### 4.2.1 Activity – no Yes

Actually we need to lower case start of all words after the en dash? This may be a bit aggressive?

gsed -e 's/^\(#.*ctivity \)[–—-] \([a-zA-Z]\)\(.*\)/\1– \U\2\L\3/g'


Ensure space character after #:

gsed -e 's/^\(##*\)\([A-Za-z0-9`-]\)/\1 \2/g'

echo '##asasas' | gsed -e 's/^\(##*\)\([A-Za-z0-9`-]\)/\1 \2/g'
## asasas

I’m a little wary of gsed -i 's/^\(\s*##*\)\([A-Za-z0-9`-]\)/\1 \2/g' which will patch in code cells with whitespace preceding # because where we have something like:

  #Uncomment the following line
  #print(“hello”)

We want a student to just delete the comment # before the print and not have extraneous whitespace.

I guess a way round this is to just report this? Or we could do the changes and then an editor using a differ could just reject the changes that weren’t required (which is probably how I’d do it… I’d commit all the files, then run the above to generate changes, then inspect and accept (by default) or refuse (by positive action) the changes) (vice versa is also easy enough)