diff --git a/.gitignore b/.gitignore index 06a9f10b..75623dcc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ _obj _test* markdown +tags diff --git a/block.go b/block.go index 5f71bc6f..a4ab9302 100644 --- a/block.go +++ b/block.go @@ -1230,6 +1230,17 @@ func (p *parser) paragraph(out *bytes.Buffer, data []byte) int { return i } + // if there's a list after this, paragraph is over + if p.flags&EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK != 0 { + if p.uliPrefix(current) != 0 || + p.oliPrefix(current) != 0 || + p.quotePrefix(current) != 0 || + p.codePrefix(current) != 0 { + p.renderParagraph(out, data[:i]) + return i + } + } + // otherwise, scan to the beginning of the next line for data[i] != '\n' { i++ diff --git a/block_test.go b/block_test.go index d2edaf84..de4f7a93 100644 --- a/block_test.go +++ b/block_test.go @@ -692,3 +692,281 @@ func TestTable(t *testing.T) { } doTestsBlock(t, tests, EXTENSION_TABLES) } + +func TestUnorderedListWith_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) { + var tests = []string{ + "* Hello\n", + "
Yin
Yang
Ting
Bong
Goo
Yin
Yang
Ting
Bong
Goo
Yin
Yang
Ting
Bong
Goo
*Hello
\n", + + "* Hello \n", + "Paragraph
\n\nParagraph
\n\nList
\n\nList\nSecond line
\n\nList
\n\nContinued
List
\n\ncode block\n
List
\n\n code block with spaces\n
List
\n\nnormal text
\n\nYin
Yang
Ting
Bong
Goo
1 Hello
\n", + + "1.Hello\n", + "1.Hello
\n", + + "1. Hello \n", + "Paragraph
\n\nParagraph
\n\nList
\n\nList\nSecond line
\n\nList
\n\nContinued
List
\n\ncode block\n
List
\n\n code block with spaces\n
func foo() bool {\n return true;\n}\n
\n",
+
+ "``` c\n/* special & char < > \" escaping */\n```\n",
+ "/* special & char < > " escaping */\n
\n",
+
+ "``` c\nno *inline* processing ~~of text~~\n```\n",
+ "no *inline* processing ~~of text~~\n
\n",
+
+ "```\nNo language\n```\n",
+ "No language\n
\n",
+
+ "``` {ocaml}\nlanguage in braces\n```\n",
+ "language in braces\n
\n",
+
+ "``` {ocaml} \nwith extra whitespace\n```\n",
+ "with extra whitespace\n
\n",
+
+ "```{ ocaml }\nwith extra whitespace\n```\n",
+ "with extra whitespace\n
\n",
+
+ "~ ~~ java\nWith whitespace\n~~~\n",
+ "~ ~~ java\nWith whitespace\n~~~
\n", + + "~~\nonly two\n~~\n", + "~~\nonly two\n~~
\n", + + "```` python\nextra\n````\n", + "extra\n
\n",
+
+ "~~~ perl\nthree to start, four to end\n~~~~\n",
+ "~~~ perl\nthree to start, four to end\n~~~~
\n", + + "~~~~ perl\nfour to start, three to end\n~~~\n", + "~~~~ perl\nfour to start, three to end\n~~~
\n", + + "~~~ bash\ntildes\n~~~\n", + "tildes\n
\n",
+
+ "``` lisp\nno ending\n",
+ "``` lisp\nno ending
\n", + + "~~~ lisp\nend with language\n~~~ lisp\n", + "~~~ lisp\nend with language\n~~~ lisp
\n", + + "```\nmismatched begin and end\n~~~\n", + "```\nmismatched begin and end\n~~~
\n", + + "~~~\nmismatched begin and end\n```\n", + "~~~\nmismatched begin and end\n```
\n", + + " ``` oz\nleading spaces\n```\n", + "leading spaces\n
\n",
+
+ " ``` oz\nleading spaces\n ```\n",
+ "leading spaces\n
\n",
+
+ " ``` oz\nleading spaces\n ```\n",
+ "leading spaces\n
\n",
+
+ "``` oz\nleading spaces\n ```\n",
+ "leading spaces\n
\n",
+
+ " ``` oz\nleading spaces\n ```\n",
+ "``` oz\n
\n\nleading spaces
\n\n```\n
\n",
+ }
+ doTestsBlock(t, tests, EXTENSION_FENCED_CODE|EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)
+}
diff --git a/markdown.go b/markdown.go
index 86886830..77e93e88 100644
--- a/markdown.go
+++ b/markdown.go
@@ -28,16 +28,17 @@ const VERSION = "1.1"
// These are the supported markdown parsing extensions.
// OR these values together to select multiple extensions.
const (
- EXTENSION_NO_INTRA_EMPHASIS = 1 << iota // ignore emphasis markers inside words
- EXTENSION_TABLES // render tables
- EXTENSION_FENCED_CODE // render fenced code blocks
- EXTENSION_AUTOLINK // detect embedded URLs that are not explicitly marked
- EXTENSION_STRIKETHROUGH // strikethrough text using ~~test~~
- EXTENSION_LAX_HTML_BLOCKS // loosen up HTML block parsing rules
- EXTENSION_SPACE_HEADERS // be strict about prefix header rules
- EXTENSION_HARD_LINE_BREAK // translate newlines into line breaks
- EXTENSION_TAB_SIZE_EIGHT // expand tabs to eight spaces instead of four
- EXTENSION_FOOTNOTES // Pandoc-style footnotes
+ EXTENSION_NO_INTRA_EMPHASIS = 1 << iota // ignore emphasis markers inside words
+ EXTENSION_TABLES // render tables
+ EXTENSION_FENCED_CODE // render fenced code blocks
+ EXTENSION_AUTOLINK // detect embedded URLs that are not explicitly marked
+ EXTENSION_STRIKETHROUGH // strikethrough text using ~~test~~
+ EXTENSION_LAX_HTML_BLOCKS // loosen up HTML block parsing rules
+ EXTENSION_SPACE_HEADERS // be strict about prefix header rules
+ EXTENSION_HARD_LINE_BREAK // translate newlines into line breaks
+ EXTENSION_TAB_SIZE_EIGHT // expand tabs to eight spaces instead of four
+ EXTENSION_FOOTNOTES // Pandoc-style footnotes
+ EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK // No need to insert an empty line to start a (code, quote, order list, unorder list)block
)
// These are the possible flag values for the link renderer.
diff --git a/upskirtref/Hard-wrapped paragraphs with list-like lines no empty line before block.html b/upskirtref/Hard-wrapped paragraphs with list-like lines no empty line before block.html
new file mode 100644
index 00000000..fc253194
--- /dev/null
+++ b/upskirtref/Hard-wrapped paragraphs with list-like lines no empty line before block.html
@@ -0,0 +1,14 @@
+In Markdown 1.0.0 and earlier. Version
+ +Here's one with a bullet.
+ +