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
This makes the previously committed parser change optional
and off by default. Since the doc does not use this option (yet),
the previously committed CSS fix is hereby reverted.
  • Loading branch information
ccorn committed Jan 2, 2018
1 parent 26747c2 commit fd24716
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
6 changes: 1 addition & 5 deletions doc/_design.scss
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,13 @@ body {
font-weight: bold;
}

dd > p:first-child {
margin-top: 0;
}

a {
color: $link-color;
text-decoration: underline;
}

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
4 changes: 3 additions & 1 deletion lib/kramdown/parser/kramdown/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +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)))
item.options[:first_as_para] ||= last_is_blank
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

0 comments on commit fd24716

Please sign in to comment.