This implementation has some problem that some side case are not handled.

Please reference this previous patch email:

https://lists.gnu.org/archive/html/emacs-orgmode/2018-03/msg00507.html