mdn_query 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 755325c7f45bdc963b9c6aa60fdddd23be5a73f4
4
- data.tar.gz: 103295f249a9cdb8daa01dccbcb24de5b18ffb0d
3
+ metadata.gz: fd1d8b69910ca50cf0d617c37cd233d1eaaafa36
4
+ data.tar.gz: f7d59f60c90d1739934b4e16cb0d2baf3ae2fe74
5
5
  SHA512:
6
- metadata.gz: 678e20a9c3157a4a9ec72fba31d5442cfd440021cc8e9a3e37f7ec5f46ae53f81c6ccfdf429858ee415bee5e0df52d9b5eec8c83ae0bcfb9e461294c553e1483
7
- data.tar.gz: f3742027b799b16b8971bb9c1fda599e803296cce71c3a28663c0ac90aab5772f203db0d44a79ca7fb61b7f20002ede96a362c3d241504a4a842f4e4df7f18af
6
+ metadata.gz: 754edf7072c37268f916f66649eeeb451e00da6568d2595c402be4a3954c2f88b5d0505da98b03dd5230c86f20cb618f7814780c1ac6d2f9c677d30cf69d2197
7
+ data.tar.gz: bf2596bd82fe8ec5fd0a9e4a38cf203b51094624e7e0b7d102a4fd0cab1601793bf4f815a43d3a29e743037ffa18eb0f358a838604492b3ea39eb47e577d0593
@@ -23,7 +23,7 @@ module MdnQuery
23
23
  # @param parent [MdnQuery::Section] the parent section
24
24
  # @return [MdnQuery::Section]
25
25
  def initialize(name, level: 1, parent: nil)
26
- @name = name
26
+ @name = escape_html_tags(name)
27
27
  @level = level
28
28
  @parent = parent
29
29
  @text = []
@@ -48,8 +48,9 @@ module MdnQuery
48
48
  # @param text [String] the text segment to append
49
49
  # @return [void]
50
50
  def append_text(text)
51
- trimmed_text = text.gsub(/\n[[:blank:]]+|[[:blank:]]+\n/, "\n")
52
- @text << trimmed_text unless text_empty?(trimmed_text)
51
+ trimmed = text.gsub(/\n[[:blank:]]+|[[:blank:]]+\n/, "\n")
52
+ escaped = escape_html_tags(trimmed)
53
+ @text << escaped unless text_empty?(escaped)
53
54
  end
54
55
 
55
56
  # Appends a code segment to the section.
@@ -83,6 +84,10 @@ module MdnQuery
83
84
 
84
85
  private
85
86
 
87
+ def escape_html_tags(text)
88
+ text.gsub(/(<\w+>)/, '`\1`')
89
+ end
90
+
86
91
  def join_text
87
92
  text.join("\n")
88
93
  end
@@ -90,7 +90,18 @@ module MdnQuery
90
90
  when 'dl'
91
91
  @current_section.append_text(convert_description(child))
92
92
  when 'pre'
93
- @current_section.append_code(child.text, language: 'javascript')
93
+ if child[:class].nil?
94
+ @current_section.append_code(child.text)
95
+ next
96
+ end
97
+ match = child[:class].match(/brush:\s*(?<lang>\w+)/)
98
+ if match.nil?
99
+ @current_section.append_code(child.text)
100
+ else
101
+ lang = match[:lang]
102
+ lang = 'javascript' if lang == 'js'
103
+ @current_section.append_code(child.text, language: lang)
104
+ end
94
105
  when /\Ah(?<level>\d)\z/
95
106
  level = $LAST_MATCH_INFO[:level].to_i
96
107
  create_child(level, child[:id].tr('_', ' '))
@@ -143,7 +154,7 @@ module MdnQuery
143
154
  if child.name == 'dl'
144
155
  convert_description(child)
145
156
  elsif child.name == 'dt'
146
- "\n**#{child.text}**\n"
157
+ "\n**#{child.text.strip}**\n"
147
158
  else
148
159
  "\n#{child.text}\n"
149
160
  end
@@ -161,7 +172,7 @@ module MdnQuery
161
172
  extract_table_row(head_row)
162
173
  end
163
174
  table = MdnQuery::Table.new(head, *body)
164
- table.to_s
175
+ "\n#{table}\n"
165
176
  end
166
177
 
167
178
  def extract_table_row(tr)
@@ -1,4 +1,4 @@
1
1
  module MdnQuery
2
2
  # The version of the gem
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdn_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Jungo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-09 00:00:00.000000000 Z
11
+ date: 2016-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: launchy