coradoc 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +1 -0
  3. data/.irbrc +1 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +5 -1
  6. data/.rubocop_todo.yml +179 -0
  7. data/Gemfile +11 -0
  8. data/README.adoc +5 -7
  9. data/coradoc.gemspec +5 -16
  10. data/exe/reverse_adoc +1 -1
  11. data/exe/w2a +1 -1
  12. data/flake.lock +114 -0
  13. data/flake.nix +135 -0
  14. data/lib/coradoc/cli.rb +1 -1
  15. data/lib/coradoc/converter.rb +4 -5
  16. data/lib/coradoc/element/attribute.rb +10 -1
  17. data/lib/coradoc/element/attribute_list.rb +4 -3
  18. data/lib/coradoc/element/audio.rb +1 -1
  19. data/lib/coradoc/element/author.rb +2 -2
  20. data/lib/coradoc/element/base.rb +14 -2
  21. data/lib/coradoc/element/bibliography.rb +1 -1
  22. data/lib/coradoc/element/bibliography_entry.rb +1 -1
  23. data/lib/coradoc/element/block/open.rb +1 -1
  24. data/lib/coradoc/element/block.rb +1 -1
  25. data/lib/coradoc/element/document_attributes.rb +8 -2
  26. data/lib/coradoc/element/image/block_image.rb +3 -2
  27. data/lib/coradoc/element/image/core.rb +5 -4
  28. data/lib/coradoc/element/inline/attribute_reference.rb +19 -0
  29. data/lib/coradoc/element/inline/cross_reference.rb +4 -3
  30. data/lib/coradoc/element/inline/footnote.rb +24 -0
  31. data/lib/coradoc/element/inline/small.rb +19 -0
  32. data/lib/coradoc/element/inline/span.rb +37 -0
  33. data/lib/coradoc/element/inline/underline.rb +19 -0
  34. data/lib/coradoc/element/inline.rb +5 -1
  35. data/lib/coradoc/element/list/core.rb +2 -2
  36. data/lib/coradoc/element/list/ordered.rb +1 -0
  37. data/lib/coradoc/element/list/unordered.rb +1 -0
  38. data/lib/coradoc/element/list_item.rb +19 -20
  39. data/lib/coradoc/element/table.rb +4 -2
  40. data/lib/coradoc/element/term.rb +1 -0
  41. data/lib/coradoc/element/text_element.rb +4 -1
  42. data/lib/coradoc/element/title.rb +1 -1
  43. data/lib/coradoc/element/video.rb +2 -2
  44. data/lib/coradoc/input/adoc.rb +20 -18
  45. data/lib/coradoc/input/docx.rb +25 -23
  46. data/lib/coradoc/input/html/README.adoc +1 -1
  47. data/lib/coradoc/input/html/cleaner.rb +121 -117
  48. data/lib/coradoc/input/html/config.rb +58 -56
  49. data/lib/coradoc/input/html/converters/a.rb +44 -39
  50. data/lib/coradoc/input/html/converters/aside.rb +12 -8
  51. data/lib/coradoc/input/html/converters/audio.rb +24 -20
  52. data/lib/coradoc/input/html/converters/base.rb +103 -99
  53. data/lib/coradoc/input/html/converters/blockquote.rb +18 -14
  54. data/lib/coradoc/input/html/converters/br.rb +11 -7
  55. data/lib/coradoc/input/html/converters/bypass.rb +77 -73
  56. data/lib/coradoc/input/html/converters/code.rb +18 -14
  57. data/lib/coradoc/input/html/converters/div.rb +15 -11
  58. data/lib/coradoc/input/html/converters/dl.rb +51 -44
  59. data/lib/coradoc/input/html/converters/drop.rb +21 -17
  60. data/lib/coradoc/input/html/converters/em.rb +16 -12
  61. data/lib/coradoc/input/html/converters/figure.rb +19 -15
  62. data/lib/coradoc/input/html/converters/h.rb +32 -30
  63. data/lib/coradoc/input/html/converters/head.rb +17 -13
  64. data/lib/coradoc/input/html/converters/hr.rb +11 -7
  65. data/lib/coradoc/input/html/converters/ignore.rb +15 -11
  66. data/lib/coradoc/input/html/converters/img.rb +98 -93
  67. data/lib/coradoc/input/html/converters/li.rb +13 -9
  68. data/lib/coradoc/input/html/converters/mark.rb +14 -10
  69. data/lib/coradoc/input/html/converters/markup.rb +22 -18
  70. data/lib/coradoc/input/html/converters/math.rb +26 -19
  71. data/lib/coradoc/input/html/converters/ol.rb +55 -50
  72. data/lib/coradoc/input/html/converters/p.rb +16 -12
  73. data/lib/coradoc/input/html/converters/pass_through.rb +12 -8
  74. data/lib/coradoc/input/html/converters/pre.rb +49 -45
  75. data/lib/coradoc/input/html/converters/q.rb +12 -8
  76. data/lib/coradoc/input/html/converters/strong.rb +15 -11
  77. data/lib/coradoc/input/html/converters/sub.rb +15 -11
  78. data/lib/coradoc/input/html/converters/sup.rb +15 -11
  79. data/lib/coradoc/input/html/converters/table.rb +21 -13
  80. data/lib/coradoc/input/html/converters/td.rb +64 -60
  81. data/lib/coradoc/input/html/converters/text.rb +24 -20
  82. data/lib/coradoc/input/html/converters/th.rb +13 -9
  83. data/lib/coradoc/input/html/converters/tr.rb +17 -13
  84. data/lib/coradoc/input/html/converters/video.rb +24 -20
  85. data/lib/coradoc/input/html/converters.rb +45 -43
  86. data/lib/coradoc/input/html/errors.rb +8 -6
  87. data/lib/coradoc/input/html/html_converter.rb +93 -90
  88. data/lib/coradoc/input/html/plugin.rb +104 -104
  89. data/lib/coradoc/input/html/plugins/plateau.rb +197 -190
  90. data/lib/coradoc/input/html/postprocessor.rb +188 -182
  91. data/lib/coradoc/input/html.rb +34 -32
  92. data/lib/coradoc/oscal.rb +18 -5
  93. data/lib/coradoc/output/adoc.rb +13 -11
  94. data/lib/coradoc/output/coradoc_tree_debug.rb +15 -13
  95. data/lib/coradoc/parser/asciidoc/admonition.rb +6 -6
  96. data/lib/coradoc/parser/asciidoc/attribute_list.rb +43 -27
  97. data/lib/coradoc/parser/asciidoc/base.rb +3 -6
  98. data/lib/coradoc/parser/asciidoc/bibliography.rb +5 -6
  99. data/lib/coradoc/parser/asciidoc/block.rb +30 -31
  100. data/lib/coradoc/parser/asciidoc/citation.rb +11 -29
  101. data/lib/coradoc/parser/asciidoc/content.rb +23 -33
  102. data/lib/coradoc/parser/asciidoc/document_attributes.rb +2 -3
  103. data/lib/coradoc/parser/asciidoc/header.rb +1 -2
  104. data/lib/coradoc/parser/asciidoc/inline.rb +165 -42
  105. data/lib/coradoc/parser/asciidoc/list.rb +27 -27
  106. data/lib/coradoc/parser/asciidoc/paragraph.rb +28 -19
  107. data/lib/coradoc/parser/asciidoc/section.rb +11 -17
  108. data/lib/coradoc/parser/asciidoc/table.rb +5 -5
  109. data/lib/coradoc/parser/asciidoc/term.rb +24 -8
  110. data/lib/coradoc/parser/asciidoc/text.rb +18 -21
  111. data/lib/coradoc/parser/base.rb +0 -3
  112. data/lib/coradoc/reverse_adoc.rb +3 -3
  113. data/lib/coradoc/transformer.rb +167 -137
  114. data/lib/coradoc/version.rb +1 -1
  115. data/lib/reverse_adoc.rb +1 -1
  116. data/utils/inspect_asciidoc.rb +29 -0
  117. data/utils/parser_analyzer.rb +14 -14
  118. data/utils/round_trip.rb +31 -15
  119. metadata +34 -137
  120. data/.hound.yml +0 -5
  121. data/lib/coradoc/element/inline/citation.rb +0 -24
  122. data/todo.md +0 -10
@@ -1,138 +1,142 @@
1
- module Coradoc::Input::HTML
2
- class Cleaner
3
- def tidy(string)
4
- if string.is_a? Hash
5
- return string.transform_values { |i| tidy(i) }
6
- end
7
-
8
- result = HtmlConverter.track_time "Removing inner whitespace" do
9
- remove_inner_whitespaces(String.new(string))
10
- end
11
- result = HtmlConverter.track_time "Removing newlines" do
12
- remove_newlines(result)
13
- end
14
- result = HtmlConverter.track_time "Removing leading newlines" do
15
- remove_leading_newlines(result)
16
- end
17
- result = HtmlConverter.track_time "Cleaning tag borders" do
18
- clean_tag_borders(result)
19
- end
20
- result = HtmlConverter.track_time "Cleaning punctuation characters" do
21
- clean_punctuation_characters(result)
22
- end
23
- result = remove_block_leading_newlines(result)
24
- result = remove_section_attribute_newlines(result)
25
- end
26
-
27
- def remove_block_leading_newlines(string)
28
- string.gsub("]\n****\n\n", "]\n****\n")
29
- end
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ class Cleaner
5
+ def tidy(string)
6
+ if string.is_a? Hash
7
+ return string.transform_values { |i| tidy(i) }
8
+ end
9
+
10
+ result = HtmlConverter.track_time "Removing inner whitespace" do
11
+ remove_inner_whitespaces(String.new(string))
12
+ end
13
+ result = HtmlConverter.track_time "Removing newlines" do
14
+ remove_newlines(result)
15
+ end
16
+ result = HtmlConverter.track_time "Removing leading newlines" do
17
+ remove_leading_newlines(result)
18
+ end
19
+ result = HtmlConverter.track_time "Cleaning tag borders" do
20
+ clean_tag_borders(result)
21
+ end
22
+ result = HtmlConverter.track_time "Cleaning punctuation characters" do
23
+ clean_punctuation_characters(result)
24
+ end
25
+ result = remove_block_leading_newlines(result)
26
+ result = remove_section_attribute_newlines(result)
27
+ end
30
28
 
31
- def remove_section_attribute_newlines(string)
32
- string.gsub("]\n\n==", "]\n==")
33
- end
29
+ def remove_block_leading_newlines(string)
30
+ string.gsub("]\n****\n\n", "]\n****\n")
31
+ end
34
32
 
35
- def remove_newlines(string)
36
- string.gsub(/\n{3,}/, "\n\n")
37
- end
33
+ def remove_section_attribute_newlines(string)
34
+ string.gsub("]\n\n==", "]\n==")
35
+ end
38
36
 
39
- def remove_leading_newlines(string)
40
- string.gsub(/\A\n+/, "")
41
- end
37
+ def remove_newlines(string)
38
+ string.gsub(/\n{3,}/, "\n\n")
39
+ end
42
40
 
43
- def remove_inner_whitespaces(string)
44
- unless string.nil?
45
- string.gsub!(/\n stem:\[/, "\nstem:[")
46
- string.gsub!(/(stem:\[([^\]]|\\\])*\])\n(?=\S)/, "\\1 ")
47
- string.gsub!(/(stem:\[([^\]]|\\\])*\])\s+(?=[\^-])/, "\\1")
48
- end
49
- result = +""
50
- string.each_line do |line|
51
- result << preserve_border_whitespaces(line) do
52
- line.strip.gsub(/[ \t]{2,}/, " ")
41
+ def remove_leading_newlines(string)
42
+ string.gsub(/\A\n+/, "")
53
43
  end
54
- end
55
- result
56
- end
57
44
 
58
- # Find non-asterisk content that is enclosed by two or
59
- # more asterisks. Ensure that only one whitespace occurs
60
- # in the border area.
61
- # Same for underscores and brackets.
62
- def clean_tag_borders(string)
63
- # result = string.gsub(/\s?\*{2,}.*?\*{2,}\s?/) do |match|
64
- # preserve_border_whitespaces(match, default_border: Coradoc::Input::HTML.config.tag_border) do
65
- # match.strip.sub("** ", "**").sub(" **", "**")
66
- # end
67
- # end
68
-
69
- # result = string.gsub(/\s?_{2,}.*?_{2,}\s?/) do |match|
70
- # preserve_border_whitespaces(match, default_border: Coradoc::Input::HTML.config.tag_border) do
71
- # match.strip.sub("__ ", "__").sub(" __", "__")
72
- # end
73
- # end
74
-
75
- result = string.gsub(/\s?~{2,}.*?~{2,}\s?/) do |match|
76
- preserve_border_whitespaces(match,
77
- default_border: Coradoc::Input::HTML.config.tag_border) do
78
- match.strip.sub("~~ ", "~~").sub(" ~~", "~~")
45
+ def remove_inner_whitespaces(string)
46
+ unless string.nil?
47
+ string.gsub!(/\n stem:\[/, "\nstem:[")
48
+ string.gsub!(/(stem:\[([^\]]|\\\])*\])\n(?=\S)/, "\\1 ")
49
+ string.gsub!(/(stem:\[([^\]]|\\\])*\])\s+(?=[\^-])/, "\\1")
50
+ end
51
+ result = +""
52
+ string.each_line do |line|
53
+ result << preserve_border_whitespaces(line) do
54
+ line.strip.gsub(/[ \t]{2,}/, " ")
55
+ end
56
+ end
57
+ result
79
58
  end
80
- end
81
59
 
82
- result.gsub(/\s?\[.*?\]\s?/) do |match|
83
- preserve_border_whitespaces(match) do
84
- match.strip.sub("[ ", "[").sub(" ]", "]")
60
+ # Find non-asterisk content that is enclosed by two or
61
+ # more asterisks. Ensure that only one whitespace occurs
62
+ # in the border area.
63
+ # Same for underscores and brackets.
64
+ def clean_tag_borders(string)
65
+ # result = string.gsub(/\s?\*{2,}.*?\*{2,}\s?/) do |match|
66
+ # preserve_border_whitespaces(match, default_border: Coradoc::Input::HTML.config.tag_border) do
67
+ # match.strip.sub("** ", "**").sub(" **", "**")
68
+ # end
69
+ # end
70
+
71
+ # result = string.gsub(/\s?_{2,}.*?_{2,}\s?/) do |match|
72
+ # preserve_border_whitespaces(match, default_border: Coradoc::Input::HTML.config.tag_border) do
73
+ # match.strip.sub("__ ", "__").sub(" __", "__")
74
+ # end
75
+ # end
76
+
77
+ result = string.gsub(/\s?~{2,}.*?~{2,}\s?/) do |match|
78
+ preserve_border_whitespaces(match,
79
+ default_border: Coradoc::Input::Html.config.tag_border) do
80
+ match.strip.sub("~~ ", "~~").sub(" ~~", "~~")
81
+ end
82
+ end
83
+
84
+ result.gsub(/\s?\[.*?\]\s?/) do |match|
85
+ preserve_border_whitespaces(match) do
86
+ match.strip.sub("[ ", "[").sub(" ]", "]")
87
+ end
88
+ end
85
89
  end
86
- end
87
- end
88
90
 
89
- def clean_punctuation_characters(string)
90
- string.gsub(/(\*\*|~~|__)\s([.!?'"])/, "\\1\\2")
91
- end
91
+ def clean_punctuation_characters(string)
92
+ string.gsub(/(\*\*|~~|__)\s([.!?'"])/, "\\1\\2")
93
+ end
92
94
 
93
- # preprocesses HTML, rather than postprocessing it
94
- def preprocess_word_html(string)
95
- clean_headings(scrub_whitespace(string.dup))
96
- end
95
+ # preprocesses HTML, rather than postprocessing it
96
+ def preprocess_word_html(string)
97
+ clean_headings(scrub_whitespace(string.dup))
98
+ end
97
99
 
98
- def scrub_whitespace(string)
99
- string.gsub!(/&nbsp;|&#xA0;|\u00a0/i, "&#xA0;") # HTML encoded spaces
100
- string = Coradoc.strip_unicode(string) # Strip document-level leading and trailing whitespace
101
- string.gsub!(/( +)$/, " ") # line trailing whitespace
102
- string.gsub!(/\n\n\n\n/, "\n\n") # Quadruple line breaks
103
- # string.delete!('?| ') # Unicode non-breaking spaces, injected as tabs
104
- string
105
- end
100
+ def scrub_whitespace(string)
101
+ string.gsub!(/&nbsp;|&#xA0;|\u00a0/i, "&#xA0;") # HTML encoded spaces
102
+ string = Coradoc.strip_unicode(string) # Strip document-level leading and trailing whitespace
103
+ string.gsub!(/( +)$/, " ") # line trailing whitespace
104
+ string.gsub!(/\n\n\n\n/, "\n\n") # Quadruple line breaks
105
+ # string.delete!('?| ') # Unicode non-breaking spaces, injected as tabs
106
+ string
107
+ end
106
108
 
107
- # following added by me
108
- def clean_headings(string)
109
- string.gsub!(%r{<h([1-9])[^>]*></h\1>}, " ")
110
- # I don't know why Libre Office is inserting them, but they need to go
111
- string.gsub!(%r{<h([1-9])[^>]* style="vertical-align: super;[^>]*>(.+?)</h\1>},
112
- "<sup>\\2</sup>")
113
- # I absolutely don't know why Libre Office is rendering superscripts as h1
114
- string
115
- end
109
+ # following added by me
110
+ def clean_headings(string)
111
+ string.gsub!(%r{<h([1-9])[^>]*></h\1>}, " ")
112
+ # I don't know why Libre Office is inserting them, but they need to go
113
+ string.gsub!(%r{<h([1-9])[^>]* style="vertical-align: super;[^>]*>(.+?)</h\1>},
114
+ "<sup>\\2</sup>")
115
+ # I absolutely don't know why Libre Office is rendering superscripts as h1
116
+ string
117
+ end
116
118
 
117
- private
119
+ private
118
120
 
119
- def preserve_border_whitespaces(string, options = {})
120
- return string if /\A\s*\Z/.match?(string)
121
+ def preserve_border_whitespaces(string, options = {})
122
+ return string if /\A\s*\Z/.match?(string)
121
123
 
122
- default_border = options.fetch(:default_border, "")
123
- # If the string contains part of a link so the characters [,],(,)
124
- # then don't add any extra spaces
125
- default_border = "" if /[\[(\])]/.match?(string)
126
- string_start = present_or_default(string[/\A\s*/], default_border)
127
- string_end = present_or_default(string[/\s*\Z/], default_border)
128
- result = yield
129
- string_start + result + string_end
130
- end
124
+ default_border = options.fetch(:default_border, "")
125
+ # If the string contains part of a link so the characters [,],(,)
126
+ # then don't add any extra spaces
127
+ default_border = "" if /[\[(\])]/.match?(string)
128
+ string_start = present_or_default(string[/\A\s*/], default_border)
129
+ string_end = present_or_default(string[/\s*\Z/], default_border)
130
+ result = yield
131
+ string_start + result + string_end
132
+ end
131
133
 
132
- def present_or_default(string, default)
133
- return default if string.nil? || string.empty?
134
+ def present_or_default(string, default)
135
+ return default if string.nil? || string.empty?
134
136
 
135
- string
137
+ string
138
+ end
139
+ end
136
140
  end
137
141
  end
138
142
  end
@@ -1,75 +1,77 @@
1
1
  require "tmpdir"
2
2
 
3
3
  module Coradoc
4
- module Input::HTML
5
- class Config
6
- def initialize
7
- @unknown_tags = :pass_through
8
- @input_format = :html
9
- @mathml2asciimath = false
10
- @external_images = false
4
+ module Input
5
+ module Html
6
+ class Config
7
+ def initialize
8
+ @unknown_tags = :pass_through
9
+ @input_format = :html
10
+ @mathml2asciimath = false
11
+ @external_images = false
11
12
 
12
- # Destination to save file and images
13
- @destination = nil
13
+ # Destination to save file and images
14
+ @destination = nil
14
15
 
15
- # Source of HTML
16
- # @sourcedir = nil
16
+ # Source of HTML
17
+ # @sourcedir = nil
17
18
 
18
- # Image counter, assuming there are max 999 images
19
- @image_counter = 1
20
- # pad with 0s
21
- @image_counter_pattern = "%03d"
19
+ # Image counter, assuming there are max 999 images
20
+ @image_counter = 1
21
+ # pad with 0s
22
+ @image_counter_pattern = "%03d"
22
23
 
23
- @em_delimiter = "_".freeze
24
- @strong_delimiter = "*".freeze
25
- @inline_options = {}
26
- @tag_border = " ".freeze
24
+ @em_delimiter = "_".freeze
25
+ @strong_delimiter = "*".freeze
26
+ @inline_options = {}
27
+ @tag_border = " ".freeze
27
28
 
28
- @split_sections = nil
29
+ @split_sections = nil
29
30
 
30
- # Document width - used to compute table sizes.
31
- # This is an assumption for screen size in input document.
32
- # If column widths are specified in absolute values, then we
33
- # have to convert them to relative values, as AsciiDoc only
34
- # supports those.
35
- @doc_width = 1000
31
+ # Document width - used to compute table sizes.
32
+ # This is an assumption for screen size in input document.
33
+ # If column widths are specified in absolute values, then we
34
+ # have to convert them to relative values, as AsciiDoc only
35
+ # supports those.
36
+ @doc_width = 1000
36
37
 
37
- # Plugin system
38
- @plugins = []
38
+ # Plugin system
39
+ @plugins = []
39
40
 
40
- # Debugging options
41
- @track_time = false
42
- end
41
+ # Debugging options
42
+ @track_time = false
43
+ end
43
44
 
44
- def with(options = {})
45
- old_options = @inline_options
46
- @inline_options = options
47
- result = yield
48
- @inline_options = old_options
49
- result
50
- end
45
+ def with(options = {})
46
+ old_options = @inline_options
47
+ @inline_options = options
48
+ result = yield
49
+ @inline_options = old_options
50
+ result
51
+ end
52
+
53
+ def self.declare_option(option)
54
+ define_method(option) do
55
+ @inline_options[option] || instance_variable_get(:"@#{option}")
56
+ end
51
57
 
52
- def self.declare_option(option)
53
- define_method(option) do
54
- @inline_options[option] || instance_variable_get(:"@#{option}")
58
+ attr_writer option
55
59
  end
56
60
 
57
- attr_writer option
61
+ declare_option :unknown_tags
62
+ declare_option :tag_border
63
+ declare_option :mathml2asciimath
64
+ declare_option :external_images
65
+ declare_option :destination
66
+ declare_option :sourcedir
67
+ declare_option :image_counter
68
+ declare_option :image_counter_pattern
69
+ declare_option :input_format
70
+ declare_option :split_sections
71
+ declare_option :doc_width
72
+ declare_option :plugins
73
+ declare_option :track_time
58
74
  end
59
-
60
- declare_option :unknown_tags
61
- declare_option :tag_border
62
- declare_option :mathml2asciimath
63
- declare_option :external_images
64
- declare_option :destination
65
- declare_option :sourcedir
66
- declare_option :image_counter
67
- declare_option :image_counter_pattern
68
- declare_option :input_format
69
- declare_option :split_sections
70
- declare_option :doc_width
71
- declare_option :plugins
72
- declare_option :track_time
73
75
  end
74
76
  end
75
77
  end
@@ -1,47 +1,52 @@
1
1
  require "coradoc"
2
2
 
3
- module Coradoc::Input::HTML
4
- module Converters
5
- class A < Base
6
- def to_coradoc(node, state = {})
7
- name = treat_children(node, state)
8
-
9
- href = node["href"]
10
- title = extract_title(node)
11
- id = node["id"] || node["name"]
12
-
13
- id = id&.gsub(/\s/, "")&.gsub(/__+/, "_")
14
- id = nil if id&.empty?
15
-
16
- return "" if /^_Toc\d+$|^_GoBack$/.match?(id)
17
-
18
- return Coradoc::Element::Inline::Anchor.new(id) if id
19
-
20
- if href.to_s.start_with?("#")
21
- href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
22
- return Coradoc::Element::Inline::CrossReference.new(href, name)
3
+ module Coradoc
4
+ module Input
5
+ module Html
6
+ module Converters
7
+ class A < Base
8
+ def to_coradoc(node, state = {})
9
+ name = treat_children(node, state)
10
+
11
+ href = node["href"]
12
+ title = extract_title(node)
13
+ id = node["id"] || node["name"]
14
+
15
+ id = id&.gsub(/\s/, "")&.gsub(/__+/, "_")
16
+ id = nil if id&.empty?
17
+
18
+ return "" if /^_Toc\d+$|^_GoBack$/.match?(id)
19
+
20
+ return Coradoc::Element::Inline::Anchor.new(id) if id
21
+
22
+ if href.to_s.start_with?("#")
23
+ href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
24
+ return Coradoc::Element::Inline::CrossReference.new(href, name)
25
+ end
26
+
27
+ return name if href.to_s.empty?
28
+
29
+ ambigous_characters = /[\w.?&#=%;\[\u{ff}-\u{10ffff}]/
30
+ if name&.strip == href
31
+ name = ""
32
+ right_constrain = textnode_after_start_with?(node,
33
+ ambigous_characters)
34
+ end
35
+
36
+ out = []
37
+ out << " " if textnode_before_end_with?(node, ambigous_characters)
38
+ out << Coradoc::Element::Inline::Link.new(
39
+ path: href,
40
+ name: name.strip,
41
+ title: title.strip,
42
+ right_constrain: right_constrain,
43
+ )
44
+ out
45
+ end
23
46
  end
24
47
 
25
- return name if href.to_s.empty?
26
-
27
- ambigous_characters = /[\w.?&#=%;\[\u{ff}-\u{10ffff}]/
28
- if name&.strip == href
29
- name = ""
30
- right_constrain = textnode_after_start_with?(node, ambigous_characters)
31
- end
32
-
33
- out = []
34
- out << " " if textnode_before_end_with?(node, ambigous_characters)
35
- out << Coradoc::Element::Inline::Link.new(
36
- path: href,
37
- name: name.strip,
38
- title: title.strip,
39
- right_constrain: right_constrain,
40
- )
41
- out
48
+ register :a, A.new
42
49
  end
43
50
  end
44
-
45
- register :a, A.new
46
51
  end
47
52
  end
@@ -1,12 +1,16 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Aside < Base
4
- def to_coradoc(node, state = {})
5
- content = treat_children(node, state)
6
- Coradoc::Element::Block::Side.new(lines: content.lines)
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Aside < Base
6
+ def to_coradoc(node, state = {})
7
+ content = treat_children(node, state)
8
+ Coradoc::Element::Block::Side.new(lines: content.lines)
9
+ end
10
+ end
11
+
12
+ register :aside, Aside.new
7
13
  end
8
14
  end
9
-
10
- register :aside, Aside.new
11
15
  end
12
16
  end
@@ -1,25 +1,29 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Audio < Base
4
- def to_coradoc(node, _state = {})
5
- src = node["src"]
6
- id = node["id"]
7
- title = extract_title(node)
8
- attributes = Coradoc::Element::AttributeList.new
9
- options = options(node)
10
- attributes.add_named("options", options) if options.any?
11
- Coradoc::Element::Audio.new(title, id: id, src: src,
12
- attributes: attributes)
13
- end
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Audio < Base
6
+ def to_coradoc(node, _state = {})
7
+ src = node["src"]
8
+ id = node["id"]
9
+ title = extract_title(node)
10
+ attributes = Coradoc::Element::AttributeList.new
11
+ options = options(node)
12
+ attributes.add_named("options", options) if options.any?
13
+ Coradoc::Element::Audio.new(title, id: id, src: src,
14
+ attributes: attributes)
15
+ end
16
+
17
+ def options(node)
18
+ autoplay = node["autoplay"]
19
+ loop_attr = node["loop"]
20
+ controls = node["controls"]
21
+ [autoplay, loop_attr, controls].compact
22
+ end
23
+ end
14
24
 
15
- def options(node)
16
- autoplay = node["autoplay"]
17
- loop_attr = node["loop"]
18
- controls = node["controls"]
19
- [autoplay, loop_attr, controls].compact
25
+ register :audio, Audio.new
20
26
  end
21
27
  end
22
-
23
- register :audio, Audio.new
24
28
  end
25
29
  end