From 35eb537633d9950afc8ae7bdf0edb6134584e9fc Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Thu, 8 Sep 2016 23:28:54 -0700 Subject: [PATCH] Set LIST_ITEM_END_OF_LIST when list is at end of document. (#305) The LIST_ITEM_END_OF_LIST flag is an internal flag passed to renderers when rendering list items. It's normally set for the last item in the list. This change fixes the issue where that flag wasn't set in situations where the Markdown document ends with the list being the last block level item in it. The cases above detect and set LIST_ITEM_END_OF_LIST flag when the list ends because another thing begins, but they miss it when the end of document is reached. No tests here because this subtle internal behavior is hard to test and would require quite a bit of testing/mock infrastructure. Helps shurcooL/markdownfmt#30. --- block.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block.go b/block.go index 0b5510d..9cf451f 100644 --- a/block.go +++ b/block.go @@ -1244,6 +1244,12 @@ gatherlines: line = i } + // If reached end of data, the Renderer.ListItem call we're going to make below + // is definitely the last in the list. + if line >= len(data) { + *flags |= LIST_ITEM_END_OF_LIST + } + rawBytes := raw.Bytes() // render the contents of the list item