pagehub-markdown 0.2.1 → 0.2.2

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: 478a609aac01d1802ed6ba5a87e3be8b0557e547
4
- data.tar.gz: d0ec48d0a10ae0c09e137730fd17ccd93f979b44
3
+ metadata.gz: 3d2b257204a340509b9903c8406fd82d53509f3a
4
+ data.tar.gz: 6f2ea7eec011c05e1a9d3ee33bc3ba80fd2682de
5
5
  SHA512:
6
- metadata.gz: 757bde84e9c73ddf110eadbc9bc2638a06a3ce66c50b51b5c76737a8b6cac14fdc5542fa171bc50b1b0ecd61e46732b901035aacdb509ff7b1dbb1270fb6f212
7
- data.tar.gz: a0f0c11ebd6cf88d5a882ef62b2eb5d484bf9170b8a7e1874e60b6af89f925c75d635a8acf978f1b1af88f86493737c7b5da10d6bd9eebe430568617e4f8d9d3
6
+ metadata.gz: 61c6d380d800cb0f4cf0ca1abda6e8f3cbab41921bb933c41ca7c8dfa7e157a7dfa178d36f39cf1543d784f6a5f34ff620fa1e67de209b4b45403f26b11d32fb
7
+ data.tar.gz: fcf95ae5b487efba0aced8907917478f5cfc7e321e0a72ad4f593db0cff62a96575c825ab21a42274eeddfba7a3a2ebfdb3944708b8a4319bda32f53d1165cc3
@@ -25,11 +25,22 @@ module Markdown
25
25
  headings = []
26
26
  current = []
27
27
  toc_index = 0
28
+ html_renderer = Redcarpet::Render::HTML.new({
29
+ filter_html: false,
30
+ no_images: true,
31
+ no_links: true,
32
+ no_styles: true,
33
+ safe_links_only: false,
34
+ with_toc_data: true,
35
+ hard_wrap: false,
36
+ xhtml: false,
37
+ })
38
+ markdown = Redcarpet::Markdown.new(html_renderer, {})
28
39
  content.gsub(FENCED_CODE_BLOCKS, '').scan(pattern).each { |l, t|
29
40
  level,title = formatter.call(l, t)
30
41
 
31
42
  if level <= threshold
32
- h = Heading.new(title, level, toc_index)
43
+ h = Heading.new(title, level, toc_index, markdown)
33
44
  headings << h
34
45
  current[level] = h
35
46
  toc_index += 1 # toc_index is used for hyperlinking
@@ -53,11 +64,12 @@ module Markdown
53
64
  class Heading
54
65
  attr_accessor :level, :title, :children, :parent, :index
55
66
 
56
- def initialize(title, level, index)
67
+ def initialize(title, level, index, renderer)
57
68
  @title = title
58
69
  @level = level
59
70
  @index = index
60
71
  @parent = nil
72
+ @renderer = renderer
61
73
  @children = []
62
74
  super()
63
75
  end
@@ -88,7 +100,8 @@ module Markdown
88
100
  private
89
101
 
90
102
  def header_anchor(title)
91
- CGI.escapeHTML(title.downcase.gsub(/\s+/, '-'))
103
+ @renderer.render("# #{title}").chomp.match(/id="([^"]+)"/)[1]
104
+ # CGI.escapeHTML(title.downcase.gsub(/\s+/, '-'))
92
105
  end
93
106
  end
94
107
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagehub-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmad Amireh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-28 00:00:00.000000000 Z
11
+ date: 2016-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet