asciidoctor-latex 1.5.0.5.dev → 1.5.0.7.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/data/asciidoc_tex_macros.tex +3 -1
  3. data/data/extras.css +125 -5
  4. data/doc/Asciidoctor.html +19 -4
  5. data/doc/Asciidoctor/Block.html +1074 -426
  6. data/doc/Asciidoctor/Converter/Html5Converter.html +28 -4
  7. data/doc/Asciidoctor/Document.html +73 -89
  8. data/doc/Asciidoctor/Inline.html +154 -134
  9. data/doc/Asciidoctor/LaTeX.html +5 -5
  10. data/doc/Asciidoctor/LaTeX/Chem.html +2 -2
  11. data/doc/Asciidoctor/LaTeX/ChemInlineMacro.html +7 -5
  12. data/doc/Asciidoctor/LaTeX/ClickBlock.html +13 -7
  13. data/doc/Asciidoctor/LaTeX/ClickStyleInsert.html +10 -9
  14. data/doc/Asciidoctor/LaTeX/Converter.html +33 -22
  15. data/doc/Asciidoctor/LaTeX/Dollar.html +2 -2
  16. data/doc/Asciidoctor/LaTeX/EntToUni.html +2 -2
  17. data/doc/Asciidoctor/LaTeX/EnvironmentBlock.html +26 -12
  18. data/doc/Asciidoctor/LaTeX/HTMLPostprocessor.html +15 -9
  19. data/doc/Asciidoctor/LaTeX/Html5ConverterExtensions.html +701 -180
  20. data/doc/Asciidoctor/LaTeX/InjectHTML.html +3 -3
  21. data/doc/Asciidoctor/LaTeX/MacroInsert.html +2 -2
  22. data/doc/Asciidoctor/LaTeX/TeXBlock.html +2 -2
  23. data/doc/Asciidoctor/LaTeX/TeXPostProcess.html +49 -49
  24. data/doc/Asciidoctor/LaTeX/TeXPreprocessor.html +93 -22
  25. data/doc/Asciidoctor/LaTeX/TexPostprocessor.html +8 -4
  26. data/doc/Asciidoctor/List.html +54 -116
  27. data/doc/Asciidoctor/Section.html +23 -19
  28. data/doc/Asciidoctor/Table.html +25 -25
  29. data/doc/PreambleProcessor.html +2 -2
  30. data/doc/String.html +257 -4
  31. data/doc/_index.html +54 -5
  32. data/doc/class_list.html +1 -1
  33. data/doc/file.LICENSE.html +2 -2
  34. data/doc/file.README.html +113 -51
  35. data/doc/file_list.html +3 -0
  36. data/doc/index.html +113 -51
  37. data/doc/method_list.html +253 -55
  38. data/doc/top-level-namespace.html +25 -4
  39. data/lib/asciidoctor/latex/converter.rb +171 -45
  40. data/lib/asciidoctor/latex/{css.rb → css_doc_info.rb} +0 -0
  41. data/lib/asciidoctor/latex/environment_block.rb +137 -0
  42. data/lib/asciidoctor/latex/inject_html.rb +25 -13
  43. data/lib/asciidoctor/latex/inline_macros.rb +44 -2
  44. data/lib/asciidoctor/latex/macro_preprocessor.rb +28 -0
  45. data/lib/asciidoctor/latex/node_processors.rb +23 -2
  46. data/lib/asciidoctor/latex/sectnumoffset-treeprocessor.rb +43 -0
  47. data/lib/asciidoctor/latex/tex_postprocessor.rb +1 -1
  48. data/lib/asciidoctor/latex/tex_preprocessor.rb +2 -2
  49. data/lib/asciidoctor/latex/version.rb +1 -1
  50. data/spec/make_index_spec.rb +104 -0
  51. data/test/examples/tex/block_preamble.tex +0 -4
  52. metadata +8 -4
@@ -10,7 +10,7 @@ module Asciidoctor::LaTeX
10
10
  class InjectHTML < Asciidoctor::Extensions::Postprocessor
11
11
 
12
12
  def process document, output
13
- output = output.gsub('</head>', $click_insertion)
13
+ output.gsub('</head>', $click_insertion)
14
14
  end
15
15
 
16
16
  end
@@ -23,24 +23,36 @@ module Asciidoctor::LaTeX
23
23
  </style>
24
24
 
25
25
 
26
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
26
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
27
27
 
28
28
  <script>
29
29
 
30
- $(document).ready(function(){
31
- $('.openblock.click').click( function() { $(this).find('.content').slideToggle('200');
32
- $.reloadMathJax() } )
33
- $('.openblock.click').find('.content').hide()
34
- });
35
30
 
36
- $(document).ready(function(){
37
- $('.listingblock.click').click( function() { $(this).find('.content').slideToggle('200') } )
38
- $('.listingblock.click').find('.content').hide()
39
- });
31
+
32
+ var ready2;
33
+
34
+ ready2 = function() {
35
+
36
+ $(document).ready(function(){
37
+
38
+ $('.openblock.click').click( function() { $(this).find('.content').slideToggle('200'); } )
39
+ $('.openblock.click').find('.content').hide()
40
+
41
+
42
+ $('.listingblock.click').click( function() { $(this).find('.content').slideToggle('200') } )
43
+ $('.listingblock.click').find('.content').hide()
44
+
45
+ });
46
+
47
+ }
48
+
49
+
50
+
51
+
52
+ $(document).ready(ready2);
53
+ $(document).on('page:load', ready2);
40
54
 
41
55
 
42
- $(document).ready(ready);
43
- $(document).on('page:load', ready);
44
56
  </script>
45
57
 
46
58
  </head>
@@ -12,8 +12,50 @@ module Asciidoctor::LaTeX
12
12
  use_dsl
13
13
  named :chem
14
14
  def process parent, target, attributes
15
- text = attributes.values * ', ' # iky!
16
- %(\\(\\ce{ #{text} }\\))
15
+ # text = attributes.values * ', ' # iky!
16
+ array = attributes.values
17
+ %(\\(\\ce{ #{array[0]} }\\))
18
+ end
19
+ end
20
+
21
+ # MODEL: <a href=#gloss_entry_cammin class=glossterm id=glossterm_cammin >cammin</a>
22
+ class GlossInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
23
+ use_dsl
24
+ named :glossterm
25
+
26
+ def glossterm(term)
27
+ identifier = term.gsub(' ', '_').gsub(/\W/, '')
28
+ id = 'glossterm_' + identifier
29
+ css_class = 'glossterm'
30
+ href = '#glossentry_' + identifier
31
+ "<a href=#{href} class=#{css_class} id=#{id} >#{term}</a>"
32
+ end
33
+
34
+ def process parent, target, attributes
35
+ term = attributes.values[0]
36
+ glossterm(term)
37
+ end
38
+ end
39
+
40
+ class IndexTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
41
+ use_dsl
42
+ named :index_term
43
+ def process parent, target, attributes
44
+ array = attributes.values
45
+ css = array.pop
46
+ index = array.pop
47
+ reference_array = array.pop.split(',')
48
+ if reference_array.count == 1
49
+ reference = reference_array.pop
50
+ else
51
+ reference = ''
52
+ end
53
+ reference ||= ''
54
+ if css == 'invisible'
55
+ "<span class='invisible' id='index_term_#{index}'>#{reference}</span>"
56
+ else
57
+ "<span class='index_term' id='index_term_#{index}'>#{reference}</span>"
58
+ end
17
59
  end
18
60
  end
19
61
 
@@ -0,0 +1,28 @@
1
+ require 'asciidoctor'
2
+ require 'asciidoctor/extensions'
3
+
4
+
5
+ module Asciidoctor::LaTeX
6
+ class MacroPreprocessor < Asciidoctor::Extensions::Preprocessor
7
+
8
+
9
+ def process document, reader
10
+ regex = /{{(.*?)}}/
11
+ return reader if reader.eof?
12
+ replacement_lines = reader.read_lines.map do |line|
13
+ if line.include? '{{'
14
+ scan = line.scan regex
15
+ scan.each do |match|
16
+ target = match[0]
17
+ puts "target: #{target}".red
18
+ line = line.gsub("{{#{target}}}", "glossterm::[#{target}]")
19
+ end
20
+ end
21
+ line
22
+ end
23
+ reader.unshift_lines replacement_lines
24
+ reader
25
+ end
26
+
27
+ end
28
+ end
@@ -161,7 +161,7 @@ module Asciidoctor
161
161
  doc << processed_content
162
162
 
163
163
  unless embedded?
164
- # Now write the defnitions of the new environments
164
+ # Now write the definitions of the new environments
165
165
  # discovered to file
166
166
  definitions = ""
167
167
 
@@ -476,12 +476,32 @@ module Asciidoctor
476
476
  handle_box
477
477
  when 'texmacro'
478
478
  handle_texmacro
479
+ when 'include_latex'
480
+ handle_include_latex
479
481
  else
480
482
  handle_plain(env)
481
483
  end
482
484
  end
483
485
 
484
486
  def handle_texmacro
487
+ "%% User tex macros:\n#{self.content}\n%% end of user macros\n"
488
+ end
489
+
490
+ # Example:
491
+ # [env.include_latex]
492
+ # --
493
+ # \nput abc.text
494
+ # \usepackage{def}
495
+ # --
496
+ # Nothing appears in the HTML,
497
+ # bu lines
498
+ # \nput abc.text
499
+ # \usepackage{def}
500
+ # appear in the generated tex file.
501
+ def handle_include_latex
502
+ puts "Hi Boss, it's me again!"
503
+ puts self.content
504
+ puts "---------------"
485
505
  self.content
486
506
  end
487
507
 
@@ -680,7 +700,8 @@ module Asciidoctor
680
700
  end
681
701
 
682
702
  def preamble_process
683
- "\\begin\{preamble\}\n#{self.content}\n\\end\{preamble\}\n"
703
+ # "\\begin\{preamble\}\n%% HO HO HO!\n#{self.content}\n\\end\{preamble\}\n"
704
+ self.content
684
705
  end
685
706
 
686
707
 
@@ -0,0 +1,43 @@
1
+ require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
2
+
3
+ include ::Asciidoctor
4
+
5
+ Extensions.register do
6
+ # A treeprocessor that increments each level-1 section number by the value of
7
+ # the `sectnumoffset` attribute.
8
+ #
9
+ # In addition, if `subsectnumoffset` is defined and greater than zero,
10
+ # the numbers of subsections in the first section encountered will
11
+ # be incremented by the offset.
12
+ #
13
+ # The numbers of all subsections will be
14
+ # incremented automatically since those values are calculated dynamically.
15
+ #
16
+ # Run using:
17
+ #
18
+ # asciidoctor -r ./lib/sectnumoffset-treeprocessor.rb -a sectnums -a sectnumoffset=1 lib/sectnumoffset-treeprocessor/sample.adoc
19
+ #
20
+ #
21
+ treeprocessor do
22
+ process do |document|
23
+ if (document.attr? 'sectnums') && (sectnumoffset = (document.attr 'sectnumoffset', 0).to_i) > 0
24
+ subsectnumoffset = (document.attr 'subsectnumoffset', 0).to_i
25
+ warn "subsectnumoffset: #{subsectnumoffset}".red if $VERBOSE
26
+ section_count = 0
27
+ if subsectnumoffset > 0
28
+ warn "Insert parent section at 'head' of document with offset #{sectnumoffset}".cyan if $VERBOSE
29
+ end
30
+ ((document.find_by context: :section) || []).each do |sect|
31
+ next unless sect.level <= 2
32
+ if sect.level == 1
33
+ section_count += 1
34
+ sect.number += sectnumoffset
35
+ elsif sect.level == 2 && section_count == 1
36
+ sect.number += subsectnumoffset
37
+ end
38
+ end
39
+ end
40
+ nil
41
+ end
42
+ end
43
+ end
@@ -42,7 +42,7 @@ module Asciidoctor::LaTeX
42
42
  # if match_data
43
43
  # output = output.gsub(match_data[0], match_data[1])
44
44
  # end
45
- output = output.gsub('!!!BACKSLASH', '\\')
45
+ output.gsub('!!!BACKSLASH', '\\')
46
46
  # output.gsub('%', '\%') This messes up the html bigtimw
47
47
  end
48
48
 
@@ -73,14 +73,14 @@ module Asciidoctor::LaTeX
73
73
  # end
74
74
  # if line =~ /\&/
75
75
  # line = line.gsub('&', '\\\&')
76
- # end
76
+ # en
77
77
  # We do need to make this substitution, but ONLY ouutside
78
78
  # of mathematical text.
79
79
  # Please $FIXME!
80
80
  #
81
81
  # We would like to ensure that underscores in names,
82
82
  # e.g., MACRO_NAME, do not cause LaTeX bugs. However,
83
- # the code below introduces a more serious bug: expressons
83
+ # the code below introduces a more serious bug: expressions
84
84
  # lik4 $\int_0^1 x^n dx$ are mapped to $\int\_0^1 x^n dx$.
85
85
  # I'm not sure this problem can be solved using regex's:
86
86
  # we need to apply a substitution to a line when there is a match
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module LaTeX
3
- VERSION = '1.5.0.5.dev'
3
+ VERSION = '1.5.0.7.dev'
4
4
  end
5
5
  end
@@ -0,0 +1,104 @@
1
+ require_relative '../add_ons/make_index'
2
+
3
+ describe TextIndex do
4
+
5
+
6
+
7
+ before :each do
8
+
9
+ @text = <<EOF
10
+ This is a test of ((Foo)).
11
+ That is to say, we went to the ((bar)).
12
+ However, ((Foo)) was nowhere to be found!
13
+ EOF
14
+
15
+
16
+
17
+ end
18
+
19
+ it 'can be initialized from a string', :string_setup do
20
+ ti = TextIndex.new(string: @text)
21
+ expect(ti.lines.count).to eq(3)
22
+ end
23
+
24
+ it 'can be initialized from a file', :file_setup do
25
+ ti = TextIndex.new(string: @text)
26
+ expect(ti.lines.count).to eq(3)
27
+ end
28
+
29
+ it 'scans the array lines, producing an array of index terms', :scan do
30
+
31
+ ti = TextIndex.new(string: @text)
32
+ ti.scan
33
+ expect(ti.term_array).to eq(["Foo", "bar", "Foo"])
34
+
35
+
36
+ end
37
+
38
+ it 'scans a string, producing and array of its terms', :scan_string do
39
+ terms = TextIndex.scan_string('This is a test of ((Foo)). Afterwards we will go to the ((bar)).')
40
+ expect(terms).to eq(["Foo", "bar"])
41
+ end
42
+
43
+ it 'produces a list of index terms from a piece of text' , :index_map do
44
+ ti = TextIndex.new(string: @text)
45
+ ti.scan
46
+ ti.make_index_map
47
+ expect(ti.index_map).to be_instance_of(Hash)
48
+ expect(ti.index_map["Foo"]).to eq([0,2])
49
+ expect(ti.index_map["bar"]).to eq([1])
50
+ end
51
+
52
+ it 'transforms a string, replacing terms with the corresponding asciidoc element', :transform_line do
53
+ input = 'This is a test of ((Foo)). Afterwards we will go to the ((bar)).'
54
+ ti = TextIndex.new(string: input)
55
+ ti.scan
56
+ ti.make_index_map
57
+ output = ti.transform_line(input)
58
+ expected_output = 'This is a test of index_term::[Foo, 0].'
59
+ expected_output << ' Afterwards we will go to the index_term::[bar, 1].'
60
+ expect(output).to eq(expected_output)
61
+ end
62
+
63
+
64
+ it 'transforms an array of lines, writing the output to a file', :transform_lines do
65
+ ti = TextIndex.new(string: @text)
66
+ ti.scan
67
+ ti.make_index_map
68
+ ti.transform_lines('out.adoc')
69
+ output = File.read('out.adoc')
70
+ expected_output = <<EOF
71
+ This is a test of index_term::[Foo, 0].
72
+ That is to say, we went to the index_term::[bar, 1].
73
+ However, index_term::[Foo, 2] was nowhere to be found!
74
+ EOF
75
+ expect(output).to eq(expected_output)
76
+ end
77
+
78
+ it 'creates the data structure for the index', :index_array do
79
+ ti = TextIndex.new(string: @text)
80
+ ti.scan
81
+ ti.make_index_map
82
+ expected_index_array = [['bar', [1]], ['Foo', [0,2]]]
83
+ expect(ti.index_array).to eq(expected_index_array)
84
+
85
+ end
86
+
87
+ it 'creates an Asciidoc version of the index', :ad_version do
88
+ ti = TextIndex.new(string: @text)
89
+ ti.scan
90
+ ti.make_index_map
91
+ ti.make_index
92
+ expected_index_text = "<<index_term_1, bar>> +\n<<index_term_0, Foo>>, <<index_term_2, 2>> +\n"
93
+ expect(ti.index).to eq(expected_index_text)
94
+ end
95
+
96
+ it 'transforms the marked index terms and appends an index to the generated asciidoc file', :preprocess do
97
+ ti = TextIndex.new(string: @text)
98
+ ti.preprocess('out.adoc')
99
+ output = File.read('out.adoc')
100
+ expected_output = "This is a test of index_term::[Foo, 0].\nThat is to say, we went to the index_term::[bar, 1].\nHowever, index_term::[Foo, 2] was nowhere to be found!\n\n\n== Index\n\n<<index_term_1, bar>> +\n<<index_term_0, Foo>>, <<index_term_2, 2>> +\n"
101
+ expect(output).to eq(expected_output)
102
+ end
103
+
104
+ end
@@ -1,15 +1,11 @@
1
1
  %== .basic ==%
2
- \begin{preamble}
3
2
  This journey begins on a bleary Monday morning.
4
3
  Our intrepid team is in desperate need of double shot mochas, but the milk expired eight days ago.
5
- \end{preamble}
6
4
  \hypertarget{x-cavern-glow}{\section*{Cavern Glow}}
7
5
  The river rages through the cavern, rattling its content.
8
6
 
9
7
  %== .toc_placement_preamble ==%
10
- \begin{preamble}
11
8
  This journey begins on a bleary Monday morning.
12
9
  Our intrepid team is in desperate need of double shot mochas, but the milk expired eight days ago.
13
- \end{preamble}
14
10
  \hypertarget{x-cavern-glow}{\section*{Cavern Glow}}
15
11
  The river rages through the cavern, rattling its content.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-latex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0.5.dev
4
+ version: 1.5.0.7.dev
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Carlson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-07-22 00:00:00.000000000 Z
13
+ date: 2016-05-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: asciidoctor
@@ -171,20 +171,23 @@ files:
171
171
  - lib/asciidoctor/latex/converter.rb
172
172
  - lib/asciidoctor/latex/core_ext/colored_string.rb
173
173
  - lib/asciidoctor/latex/core_ext/utility.rb
174
- - lib/asciidoctor/latex/css.rb
174
+ - lib/asciidoctor/latex/css_doc_info.rb
175
175
  - lib/asciidoctor/latex/dollar.rb
176
176
  - lib/asciidoctor/latex/ent_to_uni.rb
177
177
  - lib/asciidoctor/latex/environment_block.rb
178
178
  - lib/asciidoctor/latex/inject_html.rb
179
179
  - lib/asciidoctor/latex/inline_macros.rb
180
180
  - lib/asciidoctor/latex/macro_insert.rb
181
+ - lib/asciidoctor/latex/macro_preprocessor.rb
181
182
  - lib/asciidoctor/latex/node_processors.rb
182
183
  - lib/asciidoctor/latex/prepend_processor.rb
183
184
  - lib/asciidoctor/latex/preprocess.rb
185
+ - lib/asciidoctor/latex/sectnumoffset-treeprocessor.rb
184
186
  - lib/asciidoctor/latex/tex_block.rb
185
187
  - lib/asciidoctor/latex/tex_postprocessor.rb
186
188
  - lib/asciidoctor/latex/tex_preprocessor.rb
187
189
  - lib/asciidoctor/latex/version.rb
190
+ - spec/make_index_spec.rb
188
191
  - test/examples/adoc/ampersand.adoc
189
192
  - test/examples/adoc/block_olist.adoc
190
193
  - test/examples/adoc/block_ulist.adoc
@@ -315,11 +318,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
318
  version: 1.3.1
316
319
  requirements: []
317
320
  rubyforge_project:
318
- rubygems_version: 2.4.8
321
+ rubygems_version: 2.6.2
319
322
  signing_key:
320
323
  specification_version: 4
321
324
  summary: Converts AsciiDoc documents to LaTeX, provides LaTeX extensions to Asciidoc
322
325
  test_files:
326
+ - spec/make_index_spec.rb
323
327
  - test/examples/adoc/ampersand.adoc
324
328
  - test/examples/adoc/block_olist.adoc
325
329
  - test/examples/adoc/block_ulist.adoc