inkmark 0.1.0
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 +7 -0
- data/CHANGELOG.md +3 -0
- data/Cargo.lock +940 -0
- data/Cargo.toml +27 -0
- data/LICENSE.txt +21 -0
- data/NOTICE +16 -0
- data/README.md +1166 -0
- data/ext/inkmark/Cargo.toml +31 -0
- data/ext/inkmark/build.rs +5 -0
- data/ext/inkmark/extconf.rb +6 -0
- data/ext/inkmark/src/autolink.rs +167 -0
- data/ext/inkmark/src/chunks_by_heading.rs +325 -0
- data/ext/inkmark/src/chunks_by_size.rs +302 -0
- data/ext/inkmark/src/document.rs +411 -0
- data/ext/inkmark/src/emoji.rs +197 -0
- data/ext/inkmark/src/handler.rs +758 -0
- data/ext/inkmark/src/heading.rs +262 -0
- data/ext/inkmark/src/highlight.rs +202 -0
- data/ext/inkmark/src/image.rs +284 -0
- data/ext/inkmark/src/lib.rs +54 -0
- data/ext/inkmark/src/link.rs +291 -0
- data/ext/inkmark/src/options.rs +231 -0
- data/ext/inkmark/src/plain_text.rs +445 -0
- data/ext/inkmark/src/scheme_filter.rs +319 -0
- data/ext/inkmark/src/stats.rs +453 -0
- data/ext/inkmark/src/tag_filter.rs +226 -0
- data/ext/inkmark/src/toc.rs +221 -0
- data/ext/inkmark/src/truncate.rs +267 -0
- data/ext/inkmark/src/url_match.rs +178 -0
- data/lib/inkmark/event.rb +342 -0
- data/lib/inkmark/native.rb +8 -0
- data/lib/inkmark/options.rb +698 -0
- data/lib/inkmark/toc.rb +40 -0
- data/lib/inkmark/version.rb +6 -0
- data/lib/inkmark.rb +711 -0
- data/sig/inkmark.rbs +219 -0
- metadata +208 -0
data/lib/inkmark/toc.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Inkmark
|
|
4
|
+
# A rendered table of contents, carrying both Markdown and HTML
|
|
5
|
+
# renderings. Returned by {Inkmark#toc} when the +toc: true+,
|
|
6
|
+
# +statistics: true+, or +extract: { headings: true }+ option is
|
|
7
|
+
# set; +nil+ otherwise.
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# g = Inkmark.new(source, options: { toc: true })
|
|
11
|
+
# g.toc.to_markdown # => "- [Intro](#intro)\n - [Goals](#goals)\n"
|
|
12
|
+
# g.toc.to_html # => "<ul>\n<li><a href=\"#intro\">...</a>..."
|
|
13
|
+
# g.toc.to_s # => same as to_markdown (String coercion)
|
|
14
|
+
# puts g.toc # prints the markdown form
|
|
15
|
+
#
|
|
16
|
+
# Immutable value object: the instance is frozen at construction, and
|
|
17
|
+
# +==+ / +eql?+ / +hash+ implement value-equality over the two fields.
|
|
18
|
+
class Toc
|
|
19
|
+
attr_reader :markdown, :html
|
|
20
|
+
alias_method :to_markdown, :markdown
|
|
21
|
+
alias_method :to_html, :html
|
|
22
|
+
|
|
23
|
+
def initialize(markdown:, html:)
|
|
24
|
+
@markdown = markdown
|
|
25
|
+
@html = html
|
|
26
|
+
freeze
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def to_s = @markdown
|
|
30
|
+
|
|
31
|
+
def ==(other)
|
|
32
|
+
other.is_a?(Toc) && other.markdown == @markdown && other.html == @html
|
|
33
|
+
end
|
|
34
|
+
alias_method :eql?, :==
|
|
35
|
+
|
|
36
|
+
def hash
|
|
37
|
+
[self.class, @markdown, @html].hash
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|