hiccdown 0.1.5 → 0.1.6

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hiccdown.rb +16 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16c4ed5aca3ab8d41ce52f8c000dbcd55fb632bfd9e823e6e3361e190df50932
4
- data.tar.gz: 39b3d65c94b89f7f9c458d65c8516ab66f9af318374d1d25fe86e276eb288d4f
3
+ metadata.gz: f7e0521cfa485c4b5a51cf7180d2dfe8767bfe08ef93e5fa2659a320d434460f
4
+ data.tar.gz: d07fe8ae11684464af83b5d70d06cdbd12ca6d621562f43e5683f6677aaef763
5
5
  SHA512:
6
- metadata.gz: c622f8c9c6a896ca87f34b9281834b0855b9690e5aeb7f74b506c2d7a54a413890d43caf71e054f6735a660057cd8b2049fc5df40dc7dd699a8b96d02aa50581
7
- data.tar.gz: 1a7a143ad64613f755e0e0aeef55763895a5b7009e4da65eef40aac3a5ac274d9586321dbef7fb3b3c98dea1564cd9244d2bf09c3cf78a7ad0c9bace0c4d9425
6
+ metadata.gz: b7a94dd07ce2f233c8669277769058ff6052ccd3149e3db0be4aead81eee5b41ae4f49633c288d3154cb1a7a32e7e7b7d66ac0a8b2d85d40fde823763e4f7a5c
7
+ data.tar.gz: 41191daf69473e1bc7f3d4165cf328013cd299ecd20e22ee80a30d6402b31304b82f37cee6a9e1e178ad72fb55a00f3c8f4eb8a50ec1523418bfcd1218fb04a3
data/lib/hiccdown.rb CHANGED
@@ -1,23 +1,25 @@
1
+ require 'cgi'
2
+
1
3
  module Hiccdown
2
4
  def self.standalone_tags
3
5
  Set.new([:area, :base, :br, :col, :command, :embed, :hr, :img, :input, :keygen, :link, :menuitem, :meta, :param, :source, :track, :wbr])
4
6
  end
5
7
 
6
- def self.to_html structure
8
+ def self.to_html structure, escape = true
7
9
  if structure.is_a? Hash
8
10
  structure.reduce([]) do |acc, (key, val)|
9
- acc + [[key.to_s, '="', val.to_s, '"'].join]
11
+ acc + [[key.to_s, '="', self.maybe_escape(val.to_s, escape), '"'].join]
10
12
  end.join(' ')
11
13
  elsif structure.is_a? Array
12
14
  if structure.first.is_a?(Array)
13
- return structure.map { |s| to_html s }.join
15
+ return structure.map { |s| to_html(s, escape) }.join
14
16
  end
15
17
 
16
18
  if structure[1].is_a? Hash
17
- tag, attrs, *children = structure.map { |s| to_html s }
19
+ tag, attrs, *children = structure.map { |s| to_html(s, escape) }
18
20
  tag_and_attrs = structure[1].any? ? [tag, ' ', attrs].join : tag
19
21
  else
20
- tag, *children = structure.map { |s| to_html s }
22
+ tag, *children = structure.map { |s| to_html(s, escape) }
21
23
  end
22
24
 
23
25
  if standalone_tags.include? tag.to_sym
@@ -26,7 +28,15 @@ module Hiccdown
26
28
  ['<', tag_and_attrs || tag, '>', children.join, '</', tag, '>'].join
27
29
  end
28
30
  else
29
- structure.to_s
31
+ self.maybe_escape(structure.to_s, escape)
32
+ end
33
+ end
34
+
35
+ def self.maybe_escape escapable, escape
36
+ if escape
37
+ CGI::escapeHTML(escapable)
38
+ else
39
+ escapable
30
40
  end
31
41
  end
32
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiccdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Hackethal