Skip to content

Commit

Permalink
resolves asciidoctor#752 implement start line number for source listi…
Browse files Browse the repository at this point in the history
…ng (rouge)
  • Loading branch information
mojavelinux committed Feb 13, 2017
1 parent 34411c2 commit f31fe3d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/asciidoctor-pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,9 @@ def convert_listing_or_literal node
bg_color_override = formatter.background_color
source_string, conum_mapping = extract_conums source_string
# NOTE trailing endline is added to address https://github.com/jneen/rouge/issues/279
fragments = formatter.format (lexer.lex %(#{source_string}#{LF})), line_numbers: (node.attr? 'linenums')
fragments = formatter.format (lexer.lex %(#{source_string}#{LF})),
line_numbers: (node.attr? 'linenums'),
start_line: (node.attr 'start').to_i
# NOTE cleanup trailing endline (handled in rouge_ext/formatters/prawn instead)
#fragments.last[:text] == LF ? fragments.pop : fragments.last[:text].chop!
conum_mapping ? (restore_conums fragments, conum_mapping) : fragments
Expand Down
5 changes: 3 additions & 2 deletions lib/asciidoctor-pdf/rouge_ext/formatters/prawn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def format tokens, opts = {}

def stream tokens, opts = {}
if opts[:line_numbers]
# TODO implement line number start (offset)
linenum = 0
if (linenum = opts[:start_line]) > 0
linenum -= 1
end
fragments = []
fragments << (create_linenum_fragment linenum += 1)
tokens.each do |tok, val|
Expand Down

0 comments on commit f31fe3d

Please sign in to comment.