Skip to content

Commit

Permalink
New option :auto_dd_para to get automatic :p in :dd elements
Browse files Browse the repository at this point in the history
Without the new option, as is the default, the first paragraph in
a multi-paragraph dd entry is not marked as a :p block unless
explicitly requested with an empty line before the dd entry.

With the new option, having more than one paragraph in the dd
entry causes the first paragraph to be p-marked as well.
The explicit syntax with a preceding empty line remains available,
but is only necessary for single-paragraph items with this option.
  • Loading branch information
ccorn committed Jan 7, 2018
1 parent 535e3bd commit 12ac774
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc/_design.scss
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ body {
}

a:hover, a:link {
color: $link-color / 2;
color: darken($link-color, 50%);
}
}

Expand Down
2 changes: 1 addition & 1 deletion doc/parser/kramdown.page
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ option `html_to_native` to `true` to achieve this.

The kramdown parser supports the following options:

{options: {items: [parse_block_html, parse_span_html, html_to_native]}}
{options: {items: [auto_dd_para, parse_block_html, parse_span_html, html_to_native]}}


[PHP Markdown Extra]: http://michelf.com/projects/php-markdown/extra/
Expand Down
5 changes: 4 additions & 1 deletion doc/syntax.page
Original file line number Diff line number Diff line change
Expand Up @@ -732,13 +732,16 @@ paragraph otherwise:

definition term
: This definition will just be text because it would normally be a
paragraph and the there is no preceding blank line.
paragraph and there is no preceding blank line.

> although the definition contains other block-level elements

: This definition *will* be a paragraph since it is preceded by a
blank line.

To avoid the resulting mix of inline and block elements, you can use the `:auto_dd_para` option to
mark the first paragraph as such if it is followed by more blocks belonging to the same definition.

The rules about having any block-level element as first element in a list item also apply to a
definition.

Expand Down
19 changes: 19 additions & 0 deletions lib/kramdown/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,25 @@ def self.simple_hash_validator(val, name)
val
end

define(:auto_dd_para, Boolean, false, <<EOF)
Avoid creation of inline elements adjacent to block elements in
definitions (`:dd` elements).
Without this option, the first paragraph following a definition marker
is marked as a block only if the preceding source line is blank.
Subsequent paragraphs following the same definition marker are always
converted to block elements however. This can result in inline text
followed by block elements in HTML output.
With this option, the parser also checks if there is more than one
paragraph following the same definition marker. If so, the first
paragraph is marked as a block as well. This is roughly similar to how
other list types are handled.
Default: false
Used by: kramdown parser
EOF

define(:footnote_nr, Integer, 1, <<EOF)
The number of the first footnote
Expand Down
3 changes: 3 additions & 0 deletions lib/kramdown/parser/kramdown/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ def parse_definition_list
elsif @src.check(EOB_MARKER)
break
elsif (result = @src.scan(content_re)) || (!last_is_blank && (result = @src.scan(lazy_re)))
if @options[:auto_dd_para]
item.options[:first_as_para] ||= last_is_blank
end
result.sub!(/^(\t+)/) { " "*($1 ? 4*$1.length : 0) }
result.sub!(indent_re, '')
item.value << result
Expand Down
8 changes: 8 additions & 0 deletions test/testcases/block/13_definition_list/auto_dd_para.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<dl>
<dt>item</dt>
<dd>
<p>text</p>

<p>text</p>
</dd>
</dl>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:auto_dd_para: true
4 changes: 4 additions & 0 deletions test/testcases/block/13_definition_list/auto_dd_para.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
item
: text

text

0 comments on commit 12ac774

Please sign in to comment.