asciidoctor 2.0.15 → 2.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +86 -11
- data/LICENSE +1 -1
- data/README-de.adoc +9 -12
- data/README-fr.adoc +9 -12
- data/README-jp.adoc +10 -13
- data/README-zh_CN.adoc +9 -12
- data/README.adoc +33 -18
- data/asciidoctor.gemspec +2 -9
- data/data/locale/attributes-fr.adoc +2 -2
- data/data/locale/attributes-th.adoc +23 -0
- data/data/locale/attributes-vi.adoc +23 -0
- data/data/stylesheets/asciidoctor-default.css +54 -53
- data/data/stylesheets/coderay-asciidoctor.css +9 -9
- data/lib/asciidoctor/abstract_block.rb +11 -9
- data/lib/asciidoctor/abstract_node.rb +9 -8
- data/lib/asciidoctor/block.rb +6 -6
- data/lib/asciidoctor/cli/invoker.rb +1 -2
- data/lib/asciidoctor/cli/options.rb +25 -25
- data/lib/asciidoctor/convert.rb +1 -0
- data/lib/asciidoctor/converter/docbook5.rb +20 -22
- data/lib/asciidoctor/converter/html5.rb +112 -94
- data/lib/asciidoctor/converter/manpage.rb +61 -52
- data/lib/asciidoctor/converter/template.rb +12 -13
- data/lib/asciidoctor/converter.rb +6 -4
- data/lib/asciidoctor/core_ext/hash/merge.rb +1 -1
- data/lib/asciidoctor/document.rb +39 -41
- data/lib/asciidoctor/extensions.rb +20 -12
- data/lib/asciidoctor/list.rb +2 -6
- data/lib/asciidoctor/load.rb +10 -9
- data/lib/asciidoctor/logging.rb +10 -8
- data/lib/asciidoctor/parser.rb +172 -189
- data/lib/asciidoctor/path_resolver.rb +3 -3
- data/lib/asciidoctor/reader.rb +71 -72
- data/lib/asciidoctor/rx.rb +3 -2
- data/lib/asciidoctor/section.rb +7 -0
- data/lib/asciidoctor/substitutors.rb +101 -103
- data/lib/asciidoctor/syntax_highlighter/coderay.rb +2 -1
- data/lib/asciidoctor/syntax_highlighter/highlightjs.rb +1 -1
- data/lib/asciidoctor/syntax_highlighter/pygments.rb +14 -5
- data/lib/asciidoctor/syntax_highlighter/rouge.rb +2 -1
- data/lib/asciidoctor/syntax_highlighter.rb +8 -11
- data/lib/asciidoctor/table.rb +18 -20
- data/lib/asciidoctor/timings.rb +3 -3
- data/lib/asciidoctor/version.rb +1 -1
- data/lib/asciidoctor.rb +7 -7
- data/man/asciidoctor.1 +26 -28
- data/man/asciidoctor.adoc +33 -27
- metadata +8 -62
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Asciidoctor
|
3
3
|
# Public: Methods to perform substitutions on lines of AsciiDoc text. This module
|
4
|
-
# is
|
4
|
+
# is intended to be mixed-in to Section and Block to provide operations for performing
|
5
5
|
# the necessary substitutions.
|
6
6
|
module Substitutors
|
7
7
|
SpecialCharsRx = /[<&>]/
|
@@ -330,13 +330,13 @@ module Substitutors
|
|
330
330
|
# NOTE for convenience, map content (unparsed attrlist) to target when format is short
|
331
331
|
target ||= ext_config[:format] == :short ? content : target
|
332
332
|
end
|
333
|
-
if
|
333
|
+
if Inline === (replacement = extension.process_method[self, target, attributes])
|
334
334
|
if (inline_subs = replacement.attributes.delete 'subs') && (inline_subs = expand_subs inline_subs, 'custom inline macro')
|
335
335
|
replacement.text = apply_subs replacement.text, inline_subs
|
336
336
|
end
|
337
337
|
replacement.convert
|
338
338
|
elsif replacement
|
339
|
-
logger.info %(expected substitution value for custom inline macro to be of type Inline; got #{replacement.class}: #{match})
|
339
|
+
logger.info { %(expected substitution value for custom inline macro to be of type Inline; got #{replacement.class}: #{match}) }
|
340
340
|
replacement
|
341
341
|
else
|
342
342
|
''
|
@@ -445,23 +445,16 @@ module Substitutors
|
|
445
445
|
# indexterm:[Tigers,Big cats]
|
446
446
|
if (attrlist = normalize_text $2, true, true).include? '='
|
447
447
|
if (primary = (attrs = (AttributeList.new attrlist, self).parse)[1])
|
448
|
-
attrs['terms'] =
|
449
|
-
if (secondary = attrs[2])
|
450
|
-
terms << secondary
|
451
|
-
if (tertiary = attrs[3])
|
452
|
-
terms << tertiary
|
453
|
-
end
|
454
|
-
end
|
448
|
+
attrs['terms'] = [primary]
|
455
449
|
if (see_also = attrs['see-also'])
|
456
450
|
attrs['see-also'] = (see_also.include? ',') ? (see_also.split ',').map {|it| it.lstrip } : [see_also]
|
457
451
|
end
|
458
452
|
else
|
459
|
-
attrs = { 'terms' =>
|
453
|
+
attrs = { 'terms' => attrlist }
|
460
454
|
end
|
461
455
|
else
|
462
|
-
attrs = { 'terms' => (
|
456
|
+
attrs = { 'terms' => (split_simple_csv attrlist) }
|
463
457
|
end
|
464
|
-
#doc.register :indexterms, terms
|
465
458
|
(Inline.new self, :indexterm, nil, attributes: attrs).convert
|
466
459
|
when 'indexterm2'
|
467
460
|
# honor the escape
|
@@ -474,34 +467,33 @@ module Substitutors
|
|
474
467
|
attrs['see-also'] = (see_also.include? ',') ? (see_also.split ',').map {|it| it.lstrip } : [see_also]
|
475
468
|
end
|
476
469
|
end
|
477
|
-
#doc.register :indexterms, [term]
|
478
470
|
(Inline.new self, :indexterm, term, attributes: attrs, type: :visible).convert
|
479
471
|
else
|
480
|
-
|
472
|
+
encl_text = $3
|
481
473
|
# honor the escape
|
482
474
|
if $&.start_with? RS
|
483
475
|
# escape concealed index term, but process nested flow index term
|
484
|
-
if (
|
485
|
-
|
476
|
+
if (encl_text.start_with? '(') && (encl_text.end_with? ')')
|
477
|
+
encl_text = encl_text.slice 1, encl_text.length - 2
|
486
478
|
visible, before, after = true, '(', ')'
|
487
479
|
else
|
488
480
|
next $&.slice 1, $&.length
|
489
481
|
end
|
490
482
|
else
|
491
483
|
visible = true
|
492
|
-
if
|
493
|
-
if
|
494
|
-
|
484
|
+
if encl_text.start_with? '('
|
485
|
+
if encl_text.end_with? ')'
|
486
|
+
encl_text, visible = (encl_text.slice 1, encl_text.length - 2), false
|
495
487
|
else
|
496
|
-
|
488
|
+
encl_text, before, after = (encl_text.slice 1, encl_text.length), '(', ''
|
497
489
|
end
|
498
|
-
elsif
|
499
|
-
|
490
|
+
elsif encl_text.end_with? ')'
|
491
|
+
encl_text, before, after = encl_text.chop, '', ')'
|
500
492
|
end
|
501
493
|
end
|
502
494
|
if visible
|
503
495
|
# ((Tigers))
|
504
|
-
if (term = normalize_text
|
496
|
+
if (term = normalize_text encl_text, true).include? ';&'
|
505
497
|
if term.include? ' >> '
|
506
498
|
term, _, see = term.partition ' >> '
|
507
499
|
attrs = { 'see' => see }
|
@@ -510,12 +502,11 @@ module Substitutors
|
|
510
502
|
attrs = { 'see-also' => see_also }
|
511
503
|
end
|
512
504
|
end
|
513
|
-
#doc.register :indexterms, [term]
|
514
505
|
subbed_term = (Inline.new self, :indexterm, term, attributes: attrs, type: :visible).convert
|
515
506
|
else
|
516
507
|
# (((Tigers,Big cats)))
|
517
508
|
attrs = {}
|
518
|
-
if (terms = normalize_text
|
509
|
+
if (terms = normalize_text encl_text, true).include? ';&'
|
519
510
|
if terms.include? ' >> '
|
520
511
|
terms, _, see = terms.partition ' >> '
|
521
512
|
attrs['see'] = see
|
@@ -524,8 +515,7 @@ module Substitutors
|
|
524
515
|
attrs['see-also'] = see_also
|
525
516
|
end
|
526
517
|
end
|
527
|
-
attrs['terms'] =
|
528
|
-
#doc.register :indexterms, terms
|
518
|
+
attrs['terms'] = split_simple_csv terms
|
529
519
|
subbed_term = (Inline.new self, :indexterm, nil, attributes: attrs).convert
|
530
520
|
end
|
531
521
|
before ? %(#{before}#{subbed_term}#{after}) : subbed_term
|
@@ -545,7 +535,7 @@ module Substitutors
|
|
545
535
|
# NOTE if $4 is set, we're looking at a formal macro (e.g., https://example.org[])
|
546
536
|
if $4
|
547
537
|
prefix = '' if prefix == 'link:'
|
548
|
-
|
538
|
+
link_text = nil if (link_text = $4).empty?
|
549
539
|
else
|
550
540
|
# invalid macro syntax (link: prefix w/o trailing square brackets or enclosed in double quotes)
|
551
541
|
# FIXME we probably shouldn't even get here when the link: prefix is present; the regex is doing too much
|
@@ -553,7 +543,6 @@ module Substitutors
|
|
553
543
|
when 'link:', ?", ?'
|
554
544
|
next $&
|
555
545
|
end
|
556
|
-
text = ''
|
557
546
|
case $3
|
558
547
|
when ')', '?', '!'
|
559
548
|
target = target.chop
|
@@ -593,27 +582,37 @@ module Substitutors
|
|
593
582
|
end
|
594
583
|
|
595
584
|
attrs, link_opts = nil, { type: :link }
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
585
|
+
|
586
|
+
if link_text
|
587
|
+
new_link_text = link_text = link_text.gsub ESC_R_SB, R_SB if link_text.include? R_SB
|
588
|
+
if !doc.compat_mode && (link_text.include? '=')
|
589
|
+
# NOTE if an equals sign (=) is present, extract attributes from link text
|
590
|
+
link_text, attrs = extract_attributes_from_text link_text, ''
|
591
|
+
new_link_text = link_text
|
601
592
|
link_opts[:id] = attrs['id']
|
602
593
|
end
|
603
594
|
|
604
|
-
if
|
605
|
-
|
595
|
+
if link_text.end_with? '^'
|
596
|
+
new_link_text = link_text = link_text.chop
|
606
597
|
if attrs
|
607
598
|
attrs['window'] ||= '_blank'
|
608
599
|
else
|
609
600
|
attrs = { 'window' => '_blank' }
|
610
601
|
end
|
611
602
|
end
|
612
|
-
end
|
613
603
|
|
614
|
-
|
604
|
+
if new_link_text && new_link_text.empty?
|
605
|
+
# NOTE it's not possible for the URI scheme to be bare in this case
|
606
|
+
link_text = (doc_attrs.key? 'hide-uri-scheme') ? (target.sub UriSniffRx, '') : target
|
607
|
+
bare = true
|
608
|
+
end
|
609
|
+
else
|
615
610
|
# NOTE it's not possible for the URI scheme to be bare in this case
|
616
|
-
|
611
|
+
link_text = (doc_attrs.key? 'hide-uri-scheme') ? (target.sub UriSniffRx, '') : target
|
612
|
+
bare = true
|
613
|
+
end
|
614
|
+
|
615
|
+
if bare
|
617
616
|
if attrs
|
618
617
|
attrs['role'] = (attrs.key? 'role') ? %(bare #{attrs['role']}) : 'bare'
|
619
618
|
else
|
@@ -623,7 +622,7 @@ module Substitutors
|
|
623
622
|
|
624
623
|
doc.register :links, (link_opts[:target] = target)
|
625
624
|
link_opts[:attributes] = attrs if attrs
|
626
|
-
%(#{prefix}#{(Inline.new self, :anchor,
|
625
|
+
%(#{prefix}#{(Inline.new self, :anchor, link_text, link_opts).convert}#{suffix})
|
627
626
|
end
|
628
627
|
end
|
629
628
|
|
@@ -639,12 +638,12 @@ module Substitutors
|
|
639
638
|
target = $2
|
640
639
|
end
|
641
640
|
attrs, link_opts = nil, { type: :link }
|
642
|
-
unless (
|
643
|
-
|
641
|
+
unless (link_text = $3).empty?
|
642
|
+
link_text = link_text.gsub ESC_R_SB, R_SB if link_text.include? R_SB
|
644
643
|
if mailto
|
645
|
-
if !doc.compat_mode && (
|
646
|
-
# NOTE if a comma (,) is present, extract attributes from text
|
647
|
-
|
644
|
+
if !doc.compat_mode && (link_text.include? ',')
|
645
|
+
# NOTE if a comma (,) is present, extract attributes from link text
|
646
|
+
link_text, attrs = extract_attributes_from_text link_text, ''
|
648
647
|
link_opts[:id] = attrs['id']
|
649
648
|
if attrs.key? 2
|
650
649
|
if attrs.key? 3
|
@@ -654,14 +653,14 @@ module Substitutors
|
|
654
653
|
end
|
655
654
|
end
|
656
655
|
end
|
657
|
-
elsif !doc.compat_mode && (
|
658
|
-
# NOTE if an equals sign (=) is present, extract attributes from text
|
659
|
-
|
656
|
+
elsif !doc.compat_mode && (link_text.include? '=')
|
657
|
+
# NOTE if an equals sign (=) is present, extract attributes from link text
|
658
|
+
link_text, attrs = extract_attributes_from_text link_text, ''
|
660
659
|
link_opts[:id] = attrs['id']
|
661
660
|
end
|
662
661
|
|
663
|
-
if
|
664
|
-
|
662
|
+
if link_text.end_with? '^'
|
663
|
+
link_text = link_text.chop
|
665
664
|
if attrs
|
666
665
|
attrs['window'] ||= '_blank'
|
667
666
|
else
|
@@ -670,17 +669,17 @@ module Substitutors
|
|
670
669
|
end
|
671
670
|
end
|
672
671
|
|
673
|
-
if
|
672
|
+
if link_text.empty?
|
674
673
|
# mailto is a special case, already processed
|
675
674
|
if mailto
|
676
|
-
|
675
|
+
link_text = mailto_text
|
677
676
|
else
|
678
677
|
if doc_attrs.key? 'hide-uri-scheme'
|
679
|
-
if (
|
680
|
-
|
678
|
+
if (link_text = target.sub UriSniffRx, '').empty?
|
679
|
+
link_text = target
|
681
680
|
end
|
682
681
|
else
|
683
|
-
|
682
|
+
link_text = target
|
684
683
|
end
|
685
684
|
if attrs
|
686
685
|
attrs['role'] = (attrs.key? 'role') ? %(bare #{attrs['role']}) : 'bare'
|
@@ -693,7 +692,7 @@ module Substitutors
|
|
693
692
|
# QUESTION should a mailto be registered as an e-mail address?
|
694
693
|
doc.register :links, (link_opts[:target] = target)
|
695
694
|
link_opts[:attributes] = attrs if attrs
|
696
|
-
Inline.new(self, :anchor,
|
695
|
+
Inline.new(self, :anchor, link_text, link_opts).convert
|
697
696
|
end
|
698
697
|
end
|
699
698
|
|
@@ -740,15 +739,17 @@ module Substitutors
|
|
740
739
|
|
741
740
|
attrs = {}
|
742
741
|
if (refid = $1)
|
743
|
-
|
744
|
-
|
742
|
+
if refid.include? ','
|
743
|
+
refid, _, link_text = refid.partition ','
|
744
|
+
link_text = nil if (link_text = link_text.lstrip).empty?
|
745
|
+
end
|
745
746
|
else
|
746
747
|
macro = true
|
747
748
|
refid = $2
|
748
|
-
if (
|
749
|
-
|
750
|
-
# NOTE if an equals sign (=) is present, extract attributes from text
|
751
|
-
|
749
|
+
if (link_text = $3)
|
750
|
+
link_text = link_text.gsub ESC_R_SB, R_SB if link_text.include? R_SB
|
751
|
+
# NOTE if an equals sign (=) is present, extract attributes from link text
|
752
|
+
link_text, attrs = extract_attributes_from_text link_text if !doc.compat_mode && (link_text.include? '=')
|
752
753
|
end
|
753
754
|
end
|
754
755
|
|
@@ -827,7 +828,7 @@ module Substitutors
|
|
827
828
|
attrs['path'] = path
|
828
829
|
attrs['fragment'] = fragment
|
829
830
|
attrs['refid'] = refid
|
830
|
-
Inline.new(self, :anchor,
|
831
|
+
Inline.new(self, :anchor, link_text, type: :xref, target: target, attributes: attrs).convert
|
831
832
|
end
|
832
833
|
end
|
833
834
|
|
@@ -839,7 +840,7 @@ module Substitutors
|
|
839
840
|
# footnoteref
|
840
841
|
if $1
|
841
842
|
if $3
|
842
|
-
id,
|
843
|
+
id, content = $3.split ',', 2
|
843
844
|
logger.warn %(found deprecated footnoteref macro: #{$&}; use footnote macro with target instead) unless doc.compat_mode
|
844
845
|
else
|
845
846
|
next $&
|
@@ -847,31 +848,31 @@ module Substitutors
|
|
847
848
|
# footnote
|
848
849
|
else
|
849
850
|
id = $2
|
850
|
-
|
851
|
+
content = $3
|
851
852
|
end
|
852
853
|
|
853
854
|
if id
|
854
855
|
if (footnote = doc.footnotes.find {|candidate| candidate.id == id })
|
855
|
-
index,
|
856
|
+
index, content = footnote.index, footnote.text
|
856
857
|
type, target, id = :xref, id, nil
|
857
|
-
elsif
|
858
|
-
|
858
|
+
elsif content
|
859
|
+
content = restore_passthroughs(normalize_text content, true, true)
|
859
860
|
index = doc.counter('footnote-number')
|
860
|
-
doc.register(:footnotes, Document::Footnote.new(index, id,
|
861
|
+
doc.register(:footnotes, Document::Footnote.new(index, id, content))
|
861
862
|
type, target = :ref, nil
|
862
863
|
else
|
863
864
|
logger.warn %(invalid footnote reference: #{id})
|
864
|
-
type, target,
|
865
|
+
type, target, content, id = :xref, id, id, nil
|
865
866
|
end
|
866
|
-
elsif
|
867
|
-
|
867
|
+
elsif content
|
868
|
+
content = restore_passthroughs(normalize_text content, true, true)
|
868
869
|
index = doc.counter('footnote-number')
|
869
|
-
doc.register(:footnotes, Document::Footnote.new(index, id,
|
870
|
+
doc.register(:footnotes, Document::Footnote.new(index, id, content))
|
870
871
|
type = target = nil
|
871
872
|
else
|
872
873
|
next $&
|
873
874
|
end
|
874
|
-
Inline.new(self, :footnote,
|
875
|
+
Inline.new(self, :footnote, content, attributes: { 'index' => index }, id: id, target: target, type: type).convert
|
875
876
|
end
|
876
877
|
end
|
877
878
|
|
@@ -939,7 +940,7 @@ module Substitutors
|
|
939
940
|
# process_callouts - a Boolean flag indicating whether callout marks should be located and substituted
|
940
941
|
#
|
941
942
|
# Returns the highlighted source code, if a syntax highlighter is defined on the document, otherwise the source with
|
942
|
-
# verbatim
|
943
|
+
# verbatim substitutions applied
|
943
944
|
def highlight_source source, process_callouts
|
944
945
|
# NOTE the call to highlight? is a defensive check since, normally, we wouldn't arrive here unless it returns true
|
945
946
|
return sub_source source, process_callouts unless (syntax_hl = @document.syntax_highlighter) && syntax_hl.highlight?
|
@@ -948,8 +949,9 @@ module Substitutors
|
|
948
949
|
|
949
950
|
doc_attrs = @document.attributes
|
950
951
|
syntax_hl_name = syntax_hl.name
|
951
|
-
if (linenums_mode = (attr? 'linenums') ? (doc_attrs[%(#{syntax_hl_name}-linenums-mode)] || :table).to_sym : nil)
|
952
|
-
|
952
|
+
if (linenums_mode = (attr? 'linenums') ? (doc_attrs[%(#{syntax_hl_name}-linenums-mode)] || :table).to_sym : nil) &&
|
953
|
+
(start_line_number = (attr 'start', 1).to_i) < 1
|
954
|
+
start_line_number = 1
|
953
955
|
end
|
954
956
|
highlight_lines = resolve_lines_to_highlight source, (attr 'highlight'), start_line_number if attr? 'highlight'
|
955
957
|
|
@@ -986,7 +988,7 @@ module Substitutors
|
|
986
988
|
negate = true
|
987
989
|
end
|
988
990
|
if (delim = (entry.include? '..') ? '..' : ((entry.include? '-') ? '-' : nil))
|
989
|
-
from,
|
991
|
+
from, _, to = entry.partition delim
|
990
992
|
to = (source.count LF) + 1 if to.empty? || (to = to.to_i) < 0
|
991
993
|
if negate
|
992
994
|
lines -= (from.to_i..to).to_a
|
@@ -1008,7 +1010,7 @@ module Substitutors
|
|
1008
1010
|
|
1009
1011
|
# Public: Extract the passthrough text from the document for reinsertion after processing.
|
1010
1012
|
#
|
1011
|
-
# text - The String from which to extract passthrough
|
1013
|
+
# text - The String from which to extract passthrough fragments
|
1012
1014
|
#
|
1013
1015
|
# Returns the String text with passthrough regions substituted with placeholders
|
1014
1016
|
def extract_passthroughs text
|
@@ -1215,7 +1217,7 @@ module Substitutors
|
|
1215
1217
|
end
|
1216
1218
|
end
|
1217
1219
|
return unless candidates
|
1218
|
-
# weed out invalid options and remove duplicates (order is preserved; first
|
1220
|
+
# weed out invalid options and remove duplicates (order is preserved; first occurrence wins)
|
1219
1221
|
resolved = candidates & SUB_OPTIONS[type]
|
1220
1222
|
unless (candidates - resolved).empty?
|
1221
1223
|
invalid = candidates - resolved
|
@@ -1241,9 +1243,10 @@ module Substitutors
|
|
1241
1243
|
#
|
1242
1244
|
# Returns a Symbol Array of substitutions to pass to apply_subs or nil if no substitutions were resolved.
|
1243
1245
|
def expand_subs subs, subject = nil
|
1244
|
-
|
1246
|
+
case subs
|
1247
|
+
when ::Symbol
|
1245
1248
|
subs == :none ? nil : SUB_GROUPS[subs] || [subs]
|
1246
|
-
|
1249
|
+
when ::Array
|
1247
1250
|
expanded_subs = []
|
1248
1251
|
subs.each do |key|
|
1249
1252
|
unless key == :none
|
@@ -1481,26 +1484,21 @@ module Substitutors
|
|
1481
1484
|
if (str = str.strip).empty?
|
1482
1485
|
{}
|
1483
1486
|
elsif (str.start_with? '.', '#') && Compliance.shorthand_property_syntax
|
1484
|
-
|
1485
|
-
|
1486
|
-
if
|
1487
|
-
|
1487
|
+
before, _, after = str.partition '#'
|
1488
|
+
attrs = {}
|
1489
|
+
if after.empty?
|
1490
|
+
attrs['role'] = (before.tr '.', ' ').lstrip if before.length > 1
|
1488
1491
|
else
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
roles.concat more_roles
|
1492
|
+
id, _, roles = after.partition '.'
|
1493
|
+
attrs['id'] = id unless id.empty?
|
1494
|
+
if roles.empty?
|
1495
|
+
attrs['role'] = (before.tr '.', ' ').lstrip if before.length > 1
|
1496
|
+
elsif before.length > 1
|
1497
|
+
attrs['role'] = ((before + '.' + roles).tr '.', ' ').lstrip
|
1498
|
+
else
|
1499
|
+
attrs['role'] = roles.tr '.', ' '
|
1500
|
+
end
|
1499
1501
|
end
|
1500
|
-
|
1501
|
-
attrs = {}
|
1502
|
-
attrs['id'] = id if id
|
1503
|
-
attrs['role'] = roles.join ' ' unless roles.empty?
|
1504
1502
|
attrs
|
1505
1503
|
else
|
1506
1504
|
{ 'role' => str }
|
@@ -1534,7 +1532,7 @@ module Substitutors
|
|
1534
1532
|
case c
|
1535
1533
|
when ','
|
1536
1534
|
if quote_open
|
1537
|
-
accum
|
1535
|
+
accum += c
|
1538
1536
|
else
|
1539
1537
|
values << accum.strip
|
1540
1538
|
accum = ''
|
@@ -1542,7 +1540,7 @@ module Substitutors
|
|
1542
1540
|
when '"'
|
1543
1541
|
quote_open = !quote_open
|
1544
1542
|
else
|
1545
|
-
accum
|
1543
|
+
accum += c
|
1546
1544
|
end
|
1547
1545
|
end
|
1548
1546
|
values << accum.strip
|
@@ -78,7 +78,8 @@ class SyntaxHighlighter::CodeRayAdapter < SyntaxHighlighter::Base
|
|
78
78
|
end
|
79
79
|
|
80
80
|
extend Styles # exports static methods
|
81
|
-
include
|
81
|
+
include Styles # adds methods to instance
|
82
|
+
include Loader # adds methods to instance
|
82
83
|
|
83
84
|
CodeCellStartTagCs = '<td class="code"><pre>'
|
84
85
|
|
@@ -9,7 +9,7 @@ class SyntaxHighlighter::HighlightJsAdapter < SyntaxHighlighter::Base
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def format node, lang, opts
|
12
|
-
super node, lang, (opts.merge transform: proc {|_, code| code['class'] = %(language-#{lang || 'none'} hljs) }
|
12
|
+
super node, lang, (opts.merge transform: proc {|_, code| code['class'] = %(language-#{lang || 'none'} hljs) })
|
13
13
|
end
|
14
14
|
|
15
15
|
def docinfo? location
|
@@ -36,7 +36,13 @@ class SyntaxHighlighter::PygmentsAdapter < SyntaxHighlighter::Base
|
|
36
36
|
node.sub_source source, false # handles nil response from ::Pygments::Lexer#highlight
|
37
37
|
end
|
38
38
|
elsif (highlighted = lexer.highlight source, options: highlight_opts)
|
39
|
-
|
39
|
+
if linenos
|
40
|
+
if noclasses
|
41
|
+
highlighted = highlighted.gsub StyledLinenoSpanTagRx, LinenoSpanTagCs
|
42
|
+
elsif highlighted.include? LegacyLinenoSpanStartTagCs
|
43
|
+
highlighted = highlighted.gsub LegacyLinenoSpanTagRx, LinenoSpanTagCs
|
44
|
+
end
|
45
|
+
end
|
40
46
|
highlighted.sub WrapperTagRx, '\1'
|
41
47
|
else
|
42
48
|
node.sub_source source, false # handles nil response from ::Pygments::Lexer#highlight
|
@@ -114,6 +120,7 @@ class SyntaxHighlighter::PygmentsAdapter < SyntaxHighlighter::Base
|
|
114
120
|
end
|
115
121
|
@@stylesheet_cache = ::Hash.new do |cache, key|
|
116
122
|
if (stylesheet = ::Pygments.css BASE_SELECTOR, classprefix: TOKEN_CLASS_PREFIX, style: key)
|
123
|
+
stylesheet = stylesheet.slice (stylesheet.index BASE_SELECTOR), stylesheet.length unless stylesheet.start_with? BASE_SELECTOR
|
117
124
|
@@stylesheet_cache = cache.merge key => stylesheet
|
118
125
|
stylesheet
|
119
126
|
end
|
@@ -122,18 +129,20 @@ class SyntaxHighlighter::PygmentsAdapter < SyntaxHighlighter::Base
|
|
122
129
|
DEFAULT_STYLE = 'default'
|
123
130
|
BASE_SELECTOR = 'pre.pygments'
|
124
131
|
TOKEN_CLASS_PREFIX = 'tok-'
|
125
|
-
|
126
132
|
BaseStyleRx = /^#{BASE_SELECTOR.gsub '.', '\\.'} +\{([^}]+?)\}/
|
127
133
|
|
128
134
|
private_constant :BASE_SELECTOR, :TOKEN_CLASS_PREFIX, :BaseStyleRx
|
129
135
|
end
|
130
136
|
|
131
137
|
extend Styles # exports static methods
|
132
|
-
include
|
138
|
+
include Styles # adds methods to instance
|
139
|
+
include Loader # adds methods to instance
|
133
140
|
|
134
141
|
CodeCellStartTagCs = '<td class="code">'
|
142
|
+
LegacyLinenoSpanStartTagCs = '<span class="lineno">'
|
143
|
+
LegacyLinenoSpanTagRx = %r(#{LegacyLinenoSpanStartTagCs}( *\d+) ?</span>)
|
135
144
|
LinenoColumnStartTagsCs = '<td class="linenos"><div class="linenodiv"><pre>'
|
136
|
-
LinenoSpanTagCs = '<span class="
|
145
|
+
LinenoSpanTagCs = '<span class="linenos">\1</span>'
|
137
146
|
PreTagCs = '<pre>\1</pre>'
|
138
147
|
StyledLinenoColumnStartTagsRx = /<td><div class="linenodiv" style="[^"]+?"><pre style="[^"]+?">/
|
139
148
|
StyledLinenoSpanTagRx = %r((?<=^|<span></span>)<span style="[^"]+">( *\d+) ?</span>)
|
@@ -143,6 +152,6 @@ class SyntaxHighlighter::PygmentsAdapter < SyntaxHighlighter::Base
|
|
143
152
|
# NOTE initial <span></span> preserves leading blank lines
|
144
153
|
WrapperTagRx = %r(<div class="#{WRAPPER_CLASS}"><pre\b[^>]*?>(.*)</pre></div>\n*)m
|
145
154
|
|
146
|
-
private_constant :CodeCellStartTagCs, :LinenoColumnStartTagsCs, :LinenoSpanTagCs, :PreTagCs, :StyledLinenoColumnStartTagsRx, :StyledLinenoSpanTagRx, :WrapperTagRx, :WRAPPER_CLASS
|
155
|
+
private_constant :CodeCellStartTagCs, :LegacyLinenoSpanStartTagCs, :LegacyLinenoSpanTagRx, :LinenoColumnStartTagsCs, :LinenoSpanTagCs, :PreTagCs, :StyledLinenoColumnStartTagsRx, :StyledLinenoSpanTagRx, :WrapperTagRx, :WRAPPER_CLASS
|
147
156
|
end
|
148
157
|
end
|
@@ -133,7 +133,8 @@ class SyntaxHighlighter::RougeAdapter < SyntaxHighlighter::Base
|
|
133
133
|
end
|
134
134
|
|
135
135
|
extend Styles # exports static methods
|
136
|
-
include
|
136
|
+
include Styles # adds methods to instance
|
137
|
+
include Loader # adds methods to instance
|
137
138
|
|
138
139
|
CodeCellStartTagCs = '<td class="code">'
|
139
140
|
|
@@ -99,9 +99,10 @@ module SyntaxHighlighter
|
|
99
99
|
raise ::NotImplementedError, %(#{SyntaxHighlighter} subclass #{self.class} must implement the ##{__method__} method since #write_stylesheet? returns true)
|
100
100
|
end
|
101
101
|
|
102
|
-
|
102
|
+
def self.included into
|
103
103
|
into.extend Config
|
104
|
-
end
|
104
|
+
end
|
105
|
+
private_class_method :included # use separate declaration for Ruby 2.0.x
|
105
106
|
|
106
107
|
module Config
|
107
108
|
# Public: Statically register the current class in the registry for the specified names.
|
@@ -152,7 +153,7 @@ module SyntaxHighlighter
|
|
152
153
|
end
|
153
154
|
|
154
155
|
private
|
155
|
-
|
156
|
+
|
156
157
|
def registry
|
157
158
|
raise ::NotImplementedError, %(#{Factory} subclass #{self.class} must implement the ##{__method__} method)
|
158
159
|
end
|
@@ -166,19 +167,17 @@ module SyntaxHighlighter
|
|
166
167
|
end
|
167
168
|
|
168
169
|
private
|
169
|
-
|
170
|
-
|
171
|
-
@registry
|
172
|
-
end
|
170
|
+
|
171
|
+
attr_reader :registry
|
173
172
|
end
|
174
173
|
|
175
174
|
module DefaultFactory
|
176
175
|
include Factory
|
177
176
|
|
178
|
-
private
|
179
|
-
|
180
177
|
@@registry = {}
|
181
178
|
|
179
|
+
private
|
180
|
+
|
182
181
|
def registry
|
183
182
|
@@registry
|
184
183
|
end
|
@@ -216,8 +215,6 @@ module SyntaxHighlighter
|
|
216
215
|
'rouge' => %(#{__dir__}/syntax_highlighter/rouge),
|
217
216
|
}
|
218
217
|
|
219
|
-
private
|
220
|
-
|
221
218
|
@@mutex = ::Mutex.new
|
222
219
|
end
|
223
220
|
end
|