copy #891 code to nikola.utils

Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
resolve #891 — implement demoting headers

Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
fix tests

Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
actually fix tests

Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
allow the compiler to be None

Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
move the header demotion test from markdown to utils

Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
flake8

[ci skip]

Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
use a real fake compiler

Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
missed an instance of the former setup in reST

Note that I am doing that ONLY because I want a single implementation
troughout the entire codebase, without using compiler-specific nonsense.

If we did not do this, we’d have to have “I can do it by myself” value
for the compiler.demote_headers variable (there is no AlreadyDone
singleton in Python, is there?  Lying with False does not count), and
we’d have to query the site config in the reST plugin.  Not worth the
hassle.

Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
flake8

[ci skip]

Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
Make the tests pass and header demotion work correctly!

Finding the solution took me forever.  The lxml.etree.ParseError was not
shown by the test suite.  I also couldn’t see it  on  manual  demo  site
builds before (it’s now obvious to me why this happened, I did not  have
an empty file that is created by the test suite)  I  had  to  *manually*
run the test case (as in, copy-paste  stuff  from  the  test_integration
module into a .py file and run it) to get the *PROPER*  traceback.   And
then everything became fairly obvious.  But I could’ve been  done  EIGHT
commits and  FIVE  hours  ago.   But  no,  tracebacks  cannot  be  sane.

/rant

cc @ralsina — you may want to look into it and tell me why that happens.

(just in case GitHub goes weird due to the mess I made: close #891)

Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
Merge pull request #898 from getnikola/demote_headers

Implement header demotion (via #891)