Skip to content

Commit

Permalink
Restore inline formating in list items (fix #52)
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgramFan committed Aug 22, 2019
1 parent 01219a3 commit 1e78e55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/asciidoctor-bibtex/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ def process(document)
# Second pass: replace citations with citation texts.
prose_blocks.each do |block|
if block.context == :list_item || block.context == :table_cell
line = block.text
line = processor.replace_citation_macros(line)
block.text = line
# NOTE: we access the instance variable @text directly to prevent
# asciidoctor from changing the raw texts.
line = block.instance_variable_get(:@text)
if !line.empty?
line = processor.replace_citation_macros(line)
block.instance_variable_set(:@text, line)

This comment has been minimized.

Copy link
@mojavelinux

mojavelinux Aug 22, 2019

Member

You don't need to use instance_variable_set to assign the text. You only need to use the low-level operation to read it. So this line can be changed back to:

block.text = line

This comment has been minimized.

Copy link
@ProgramFan

ProgramFan Aug 23, 2019

Author Contributor

Yes, Dan. But The code uses instance_variable_set intentionally to indicate that it shall not change the text other than adding citations. The paired use of instance_variable_get and instance_variable_set makes the intention clear and precise, and ensures the intention regardless of how the text property reader and writer are implemented.

This comment has been minimized.

Copy link
@mojavelinux

mojavelinux Aug 23, 2019

Member

I understand. But I still think that the assignment is overstated. The substitutions always happen on read, not write. So there's no reason to give the impression that the write method must be avoided.

This comment has been minimized.

Copy link
@ProgramFan

ProgramFan Aug 23, 2019

Author Contributor

Given that guarantee, it makes sense to use the writer. This is a good point.

end
else
block.lines.each_with_index do |line, index|
line = processor.replace_citation_macros(line)
Expand Down
2 changes: 1 addition & 1 deletion samples/all-in-one/sample.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ prevent problems with a2x.

References can be inserted in lists, too:

1. See cite:[Lane12a].
1. This is a complex *item* with _formats_. See cite:[Lane12a].
2. See cite:[Anderson98].
3. See cite:[Anderson04].

Expand Down

0 comments on commit 1e78e55

Please sign in to comment.