Skip to content

Commit

Permalink
resolves asciidoctor#755 enable "start inline" option when highlighti…
Browse files Browse the repository at this point in the history
…ng PHP

- enable "start inline" option when highlighting PHP by default
- disable setting if the mixed option is set on source block
  • Loading branch information
mojavelinux committed Feb 15, 2017
1 parent dbea982 commit 32eb0a6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/asciidoctor-pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,7 @@ def convert_listing_or_literal node
stripnl: false,
style: (style = (node.document.attr 'pygments-style') || 'pastie')
}
lexer_opts[:startinline] = !(node.option? 'mixed') if lexer.name == 'PHP'
# TODO enable once we support background color on spans
#if node.attr? 'highlight', nil, false
# unless (hl_lines = node.resolve_lines_to_highlight(node.attr 'highlight', nil, false)).empty?
Expand All @@ -1233,13 +1234,14 @@ def convert_listing_or_literal node
when 'rouge'
Helpers.require_library RougeRequirePath, 'rouge' unless defined? ::Rouge::Formatters::Prawn
lexer = ::Rouge::Lexer.find(node.attr 'language', 'text', false) || ::Rouge::Lexers::PlainText
lexer_opts = lexer.tag == 'php' ? { start_inline: !(node.option? 'mixed') } : {}
formatter = (@rouge_formatter ||= ::Rouge::Formatters::Prawn.new theme: (node.document.attr 'rouge-style'), line_gap: @theme.code_line_gap)
formatter_opts = (node.attr? 'linenums') ? { line_numbers: true, start_line: (node.attr 'start').to_i } : {}
# QUESTION allow border color to be set by theme for highlighted block?
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})), formatter_opts
fragments = formatter.format (lexer.lex %(#{source_string}#{LF}), lexer_opts), formatter_opts
# 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

0 comments on commit 32eb0a6

Please sign in to comment.