Bug fix in heading escaping

 * Only run when opts.isLastChild of the heading.

Bug: T84903
Change-Id: I46d7dad9a6f97fbae9389e2b4530de46f80d6392