docco 0.1.1 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc8e122cfc342c995aafcd7f252fd4bf40c40e93954b8d53893cb4b1bc542b97
4
- data.tar.gz: 7559ebddafbb6294e31650ce213a3526a32ed18bd065def3b396b713898255f9
3
+ metadata.gz: 2b1c6900d2f698b784960def013b7695b41e8c4e03fe7564e38170e10dc4a5d6
4
+ data.tar.gz: d1023be9573eff8363bafb83041a153f70abe24ee5554ba265ffb91e6db1bbad
5
5
  SHA512:
6
- metadata.gz: c01036732ff4b2b6db81ae86d1794c4200590fb222d6bdaa3a72a59681032ac8a402a0afb27ce25a27cd44b5cd96adaec5b389d6ba1c3071d85789eed53e6c79
7
- data.tar.gz: eb4237fe63017abaccb95faf6f2edc003ee07a8cf7fa31693af18372e9d293316a7ffdb01e046ede9db1348176eebb793daeb4d5b60001445c676ca35eea8d62
6
+ metadata.gz: a53396c5bf038b7b5a98ba6113b0f460c615d3f97101bfed05b93ff68bc90911942e52b57b50d9e85569a1da9f0c4071ec80c37184aafb23bbd0a5b7b5c986ac
7
+ data.tar.gz: 9abc9c091fc9cd92800e9ebca77aae21a8bd32eadcf810f76fa5db2b1246b4afe4bfa9fb0db1078e52211a4fe96f5c55b55ffbf2ca3f08bb39922cb00b2215ab
@@ -3,17 +3,14 @@
3
3
  module Docco
4
4
  class Parser
5
5
  class ContentNode
6
- def initialize(converter, node)
7
- @converter = converter
6
+ def initialize(node, html)
8
7
  @node = node
8
+ @html = html
9
9
  end
10
10
 
11
11
  def inspect = %(<#{self.class}:#{@node.type} [#{@node.children}]>)
12
12
  def section? = false
13
-
14
- def to_html
15
- @to_html ||= @converter.convert(@node, 0)
16
- end
13
+ def to_html = @html
17
14
  end
18
15
  end
19
16
  end
@@ -5,8 +5,7 @@ module Docco
5
5
  class Root
6
6
  attr_reader :nodes, :level
7
7
 
8
- def initialize(converter)
9
- @converter = converter
8
+ def initialize
10
9
  @nodes = []
11
10
  @level = 0
12
11
  end
@@ -18,8 +17,8 @@ module Docco
18
17
  @nodes << section
19
18
  end
20
19
 
21
- def add_content(node)
22
- @nodes << ContentNode.new(@converter, node)
20
+ def add_content(node, html)
21
+ @nodes << ContentNode.new(node, html)
23
22
  end
24
23
 
25
24
  def to_html
@@ -7,9 +7,9 @@ module Docco
7
7
 
8
8
  attr_reader :id, :options, :nodes
9
9
 
10
- def initialize(converter:, node:)
11
- @converter = converter
10
+ def initialize(node:, html:)
12
11
  @node = node
12
+ @title_html = html
13
13
  @id = node.attr['id']
14
14
  @options = node.options
15
15
  @nodes = []
@@ -24,20 +24,18 @@ module Docco
24
24
  @nodes << section
25
25
  end
26
26
 
27
- def add_content(node)
28
- @nodes << ContentNode.new(@converter, node)
27
+ def add_content(node, html)
28
+ @nodes << ContentNode.new(node, html)
29
29
  end
30
30
 
31
- def title_html
32
- @to_html ||= @converter.convert(@node, 0)
33
- end
31
+ def title_html = @title_html
34
32
 
35
33
  def title
36
- @title ||= title_html.match(HEADING_EXP)[2]
34
+ @title ||= @title_html.match(HEADING_EXP)[2]
37
35
  end
38
36
 
39
37
  def to_html
40
- @nodes.reduce(title_html) do |str, node|
38
+ @nodes.reduce(+title_html) do |str, node|
41
39
  str << "\n" << node.to_html
42
40
  end
43
41
  end
data/lib/docco/parser.rb CHANGED
@@ -4,6 +4,31 @@ require 'kramdown'
4
4
 
5
5
  module Docco
6
6
  class Parser
7
+ # Subclasses Kramdown's HTML converter so we can capture each top-level
8
+ # child's rendered HTML during a single top-down walk. Overriding only
9
+ # convert_root lets Kramdown drive the recursion normally (so @stack,
10
+ # @footnotes, @used_ids, etc. behave as designed); we just replace the
11
+ # root-level concatenation step with a per-child capture into a hash
12
+ # keyed by Kramdown element identity.
13
+ class Renderer < Kramdown::Converter::Html
14
+ attr_reader :per_element_html
15
+
16
+ def initialize(root, options)
17
+ super
18
+ @per_element_html = {}
19
+ end
20
+
21
+ def convert_root(el, indent)
22
+ @stack.push(el)
23
+ indent += @indent
24
+ el.children.each do |child|
25
+ @per_element_html[child] = send(@dispatcher[child.type], child, indent)
26
+ end
27
+ @stack.pop
28
+ ''
29
+ end
30
+ end
31
+
7
32
  def initialize(text, input: 'GFM')
8
33
  @text = text
9
34
  @input = input
@@ -14,26 +39,26 @@ module Docco
14
39
  end
15
40
 
16
41
  private
17
- # cc = Kramdown::Converter::Html.send(:new, doc.root, doc.options)
18
- # cc.convert doc.children[0], 1 # <= 1 is indent and it's needed
42
+
19
43
  def build
20
44
  doc = Kramdown::Document.new(@text, input: @input, auto_ids: true)
21
- converter = Kramdown::Converter::Html.send(:new, doc.root, doc.options)
22
- root = Root.new(converter)
45
+ renderer = Renderer.send(:new, doc.root, doc.options)
46
+ renderer.convert(doc.root)
47
+
48
+ root = Root.new
23
49
  last_section = root
24
50
  levels = Hash.new { |h, k| h[k] = [] }
25
- levels[last_section.level] << last_section # root
51
+ levels[root.level] << root
26
52
 
27
53
  doc.root.children.each do |child|
54
+ html = renderer.per_element_html.fetch(child)
28
55
  if child.type == :header
29
- section = Section.new(converter:, node: child)
56
+ section = Section.new(node: child, html: html)
30
57
  levels[section.level] << section
31
- if (parent = levels[section.level - 1].last)
32
- parent << section
33
- end
58
+ levels[section.level - 1].last&.<<(section)
34
59
  last_section = section
35
- else # not a section. Content belonging to last section, or directly to root
36
- last_section.add_content child
60
+ else
61
+ last_section.add_content(child, html)
37
62
  end
38
63
  end
39
64
 
@@ -379,6 +379,46 @@ li {
379
379
  font-weight: bold;
380
380
  }
381
381
 
382
+ /* Tables */
383
+ table {
384
+ width: 100%;
385
+ margin: 1.5rem 0;
386
+ border-collapse: collapse;
387
+ background-color: var(--content-bg);
388
+ border: 1px solid var(--border-color);
389
+ border-radius: 6px;
390
+ box-shadow: var(--shadow);
391
+ overflow: hidden;
392
+ font-size: 0.95em;
393
+ }
394
+
395
+ thead {
396
+ background-color: var(--bg-color);
397
+ }
398
+
399
+ th {
400
+ text-align: left;
401
+ font-weight: 600;
402
+ color: var(--text-color);
403
+ padding: 0.75rem 1rem;
404
+ border-bottom: 1px solid var(--border-color);
405
+ }
406
+
407
+ td {
408
+ padding: 0.75rem 1rem;
409
+ border-bottom: 1px solid var(--border-color);
410
+ vertical-align: top;
411
+ line-height: 1.6;
412
+ }
413
+
414
+ tbody tr:last-child td {
415
+ border-bottom: none;
416
+ }
417
+
418
+ tbody tr:hover {
419
+ background-color: var(--bg-color);
420
+ }
421
+
382
422
  /* Code Blocks */
383
423
  code {
384
424
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
data/lib/docco/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Docco
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis