Skip to content

Commit

Permalink
Allow using an IAL for definition terms
Browse files Browse the repository at this point in the history
IALs are already allowed for normal list items as well as the
definitions of a definition list. Now they can also be used for the
definition terms.
  • Loading branch information
gettalong committed Aug 7, 2016
1 parent e600c06 commit 2db48a6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
13 changes: 12 additions & 1 deletion doc/syntax.page
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@ then the first part of the definition. The line with the definition marker may o
separated from the preceding paragraph by a blank line. The leading tabs or spaces are stripped away
from this first line of the definition to allow for a nice alignment with the following definition
content. Each line of the preceding paragraph is taken to be a term and the lines separately parsed
as span-level elements.
as span-level elements. Each such term may optionally start with an [IAL](#inline-attribute-lists)
that should be applied to the term.

The following is a simple definition list:

Expand Down Expand Up @@ -737,6 +738,16 @@ paragraph otherwise:
The rules about having any block-level element as first element in a list item also apply to a
definition.

As mentioned at the beginning, an optional IAL for applying attributes to a term or a definition can
be used:

{:#term} Term with id="term"
: {:.cls} Definition with class "cls"

{:#term1} First term
{:#term2} Second term
: {:.cls} Definition


## Tables

Expand Down
8 changes: 6 additions & 2 deletions lib/kramdown/converter/kramdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize(root, options)

def convert(el, opts = {:indent => 0})
res = send("convert_#{el.type}", el, opts)
if ![:html_element, :li, :dd, :td].include?(el.type) && (ial = ial_for_element(el))
if ![:html_element, :li, :dt, :dd, :td].include?(el.type) && (ial = ial_for_element(el))
res << ial
res << "\n\n" if Element.category(el) == :block
elsif [:ul, :dl, :ol, :codeblock].include?(el.type) && opts[:next] &&
Expand Down Expand Up @@ -174,7 +174,11 @@ def convert_dd(el, opts)
end

def convert_dt(el, opts)
inner(el, opts) << "\n"
result = ''
if ial = ial_for_element(el)
result << ial << " "
end
result << inner(el, opts) << "\n"
end

HTML_TAGS_WITH_BODY=['div', 'script', 'iframe', 'textarea']
Expand Down
5 changes: 5 additions & 0 deletions lib/kramdown/parser/kramdown/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ def parse_definition_list
deflist.options[:location] = para.options[:location] # take location from preceding para which is the first definition term
para.children.first.value.split(/\n/).each do |term|
el = Element.new(:dt, nil, nil, :location => @src.current_line_number)
term.sub!(self.class::LIST_ITEM_IAL) do
parse_attribute_list($1, el.options[:ial] ||= {})
''
end
el.options[:raw_text] = term
el.children << Element.new(:raw_text, term)
deflist.children << el
end
Expand Down
5 changes: 5 additions & 0 deletions test/testcases/block/13_definition_list/item_ial.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
</dd>
<dd class="cls">IAL at last
no code bc of text</dd>
<dt class="class">term</dt>
<dd>definition</dd>
<dt class="class1">term1</dt>
<dt class="class2">term2</dt>
<dd>definition</dd>
</dl>
8 changes: 8 additions & 0 deletions test/testcases/block/13_definition_list/item_ial.text
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ item
code
: {:.cls} IAL at last
no code bc of text


{:.class} term
: definition

{:.class1} term1
{:.class2} term2
: definition

0 comments on commit 2db48a6

Please sign in to comment.