mdocs_kramdown 0.1.2.70320 → 0.1.2.70482

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
  SHA256:
3
- metadata.gz: 261462c6de58fd30d0be141e1b079323447a1cbe37cb5a727bf9212cf4067ac1
4
- data.tar.gz: 0a6d47d0ca489b120e664c405b668cbe73045ffc690aa272e2a1c696dd4e7471
3
+ metadata.gz: cd2a495be39459521396c9034cb9664178a3d82ea2d710bf4e682b975b5271a9
4
+ data.tar.gz: 3d739f1df808ce4106aa01cb887a84dc23055a184a51e4a4a4d8165ed27fea23
5
5
  SHA512:
6
- metadata.gz: f89f5bf9e9f1c8fed5e2fa5a7d7044dd921d8e530cb8fc95275e23d23121eb7c570ed547010ebde6098849ca393269b09adafde49a3129d6ae2642052cd169e2
7
- data.tar.gz: 96bcece466a4423a3b4e9f304377d582129f6c305268d7d8b91f3e7bdcb25cd612dbe49ad02b3e3cfc520321876fec2d7bddeb40879ba3dd8381ca4b0a2efa64
6
+ metadata.gz: 3e61bb221ffe05931740c08c5ab6d64acce133e0e6ba0a4cd1f69a671df5a67cb66a77be0eee49a993bf9d9c608c82ab7bfb3d70d0bfe085108711f13f9e1829
7
+ data.tar.gz: fd06f37954f8651de7320223fe63e52e4d9434816413fd89015d89d4e807bc1ddb6a599c1d5bdb94ba8eb40eadaddd361780a1818b60d725e68008589c5579cc
@@ -4,11 +4,13 @@ module Kramdown
4
4
  module Parser
5
5
  class MdocsKramdown < ::Kramdown::Parser::GitlabKramdown
6
6
  include ::MdocsKramdown::Parser::FencedAdmonitions
7
+ include ::MdocsKramdown::Parser::FencedCollapsibleAdmonitions
7
8
 
8
9
  def initialize(source, options)
9
10
  super
10
11
 
11
12
  prepend_block_parsers(:fenced_admonitions)
13
+ prepend_block_parsers(:fenced_collapsible_admonitions)
12
14
  end
13
15
  end
14
16
  end
@@ -10,13 +10,27 @@ module MdocsKramdown
10
10
 
11
11
  classes = el.attr[:types]
12
12
  title = el.attr[:title]
13
+
14
+ if el.options[:collapsible]
15
+ element_id = Digest::MD5.hexdigest el.inspect
16
+
17
+ format_as_indented_block_html('div', { class: "card #{classes.join(' ')} collapsible" },
18
+ (title ? format_as_indented_block_html('div', { class: 'card-header collapsed', 'data-bs-toggle'=>'collapse','data-bs-target'=>"#collapse-#{element_id}"}, title.strip, indent + 2) : '') +
19
+ format_as_indented_block_html('div', { class: 'collapse', id: "collapse-#{element_id}" },
20
+ format_as_indented_block_html('div', { class: 'card-body' },
21
+ format_as_indented_block_html('div', { class: 'card-text' }, inner(el, indent + 2), indent + 2),
22
+ indent + 1),
23
+ indent + 1),
24
+ indent)
13
25
 
14
- format_as_indented_block_html('div', { class: "card #{classes.join(' ')}" },
15
- (title ? format_as_indented_block_html('div', { class: 'card-header' }, title.strip, indent + 2) : '') +
16
- format_as_indented_block_html('div', { class: 'card-body' },
17
- format_as_indented_block_html('div', { class: 'card-text' }, inner(el, indent + 2), indent + 2),
18
- indent + 1),
19
- indent)
26
+ else
27
+ format_as_indented_block_html('div', { class: "card #{classes.join(' ')}" },
28
+ (title ? format_as_indented_block_html('div', { class: 'card-header' }, title.strip, indent + 2) : '') +
29
+ format_as_indented_block_html('div', { class: 'card-body' },
30
+ format_as_indented_block_html('div', { class: 'card-text' }, inner(el, indent + 2), indent + 2),
31
+ indent + 1),
32
+ indent)
33
+ end
20
34
  end
21
35
 
22
36
  def convert_table(el, indent)
@@ -4,7 +4,7 @@ module MdocsKramdown
4
4
  FENCED_ADMONITIONS_START = /^\s{0,}!{3}/x.freeze
5
5
 
6
6
  FENCED_ADMONITIONS_MATCH = %r{
7
- \s{0,}*(?<delimeter>!{3}) # line must start with [0..] spacing and !!!
7
+ \s{0,}*(?<delimiter>!{3}) # line must start with [0..] spacing and !!!
8
8
  \s?
9
9
  (?<type>[^\s]+)? # type of admoniation any except space. Ex: info,class1
10
10
  \s?
@@ -0,0 +1,42 @@
1
+ module MdocsKramdown
2
+ module Parser
3
+ module FencedCollapsibleAdmonitions
4
+ FENCED_COLLAPSIBLE_ADMONITIONS_START = /^\s{0,}\?{3}/x.freeze
5
+
6
+ FENCED_COLLAPSIBLE_ADMONITIONS_MATCH = %r{
7
+ \s{0,}*(?<delimiter>\?{3}) # line must start with [0..] spacing and !!!
8
+ \s?
9
+ (?<type>[^\s]+)? # type of admoniation any except space. Ex: info,class1
10
+ \s?
11
+ ("(?<title>[^\n]+)")? # title of the admoniation
12
+ \n
13
+ (?<content>(\s{4}.+)+) # content must starts with 4 spaces
14
+ \n}x.freeze
15
+
16
+ def self.included(klass)
17
+ klass.define_parser(:fenced_collapsible_admonitions, FENCED_COLLAPSIBLE_ADMONITIONS_START)
18
+ end
19
+
20
+ def parse_fenced_collapsible_admonitions
21
+ if @src.check(FENCED_COLLAPSIBLE_ADMONITIONS_MATCH)
22
+ start_line_number = @src.current_line_number
23
+ @src.pos += @src.matched_size
24
+
25
+ el = new_block_el(:blockquote, nil, { types: @src[:type].to_s.split(','), title: @src[:title] }, location: start_line_number, admonition: true, collapsible: true)
26
+
27
+ content = parse_inner_alert_content(@src[:content].gsub(/^\s{4}/, ''))
28
+ el.children = content
29
+ @tree.children << el
30
+ true
31
+ else
32
+ false
33
+ end
34
+ end
35
+
36
+ def parse_inner_alert_content(content)
37
+ parsed = ::Kramdown::Parser::MdocsKramdown.parse(content, @options)
38
+ parsed[0].children
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,6 @@
1
1
  module MdocsKramdown
2
2
  module Parser
3
3
  autoload :FencedAdmonitions, 'mdocs_kramdown/parser/fenced_admonitions'
4
+ autoload :FencedCollapsibleAdmonitions, 'mdocs_kramdown/parser/fenced_collapsible_admonitions'
4
5
  end
5
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdocs_kramdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.70320
4
+ version: 0.1.2.70482
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samoilenko Yuri
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-14 00:00:00.000000000 Z
11
+ date: 2021-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab_kramdown
@@ -165,6 +165,7 @@ files:
165
165
  - lib/mdocs_kramdown/converter/mdocs_html.rb
166
166
  - lib/mdocs_kramdown/parser.rb
167
167
  - lib/mdocs_kramdown/parser/fenced_admonitions.rb
168
+ - lib/mdocs_kramdown/parser/fenced_collapsible_admonitions.rb
168
169
  - lib/mdocs_kramdown/version.rb
169
170
  homepage: https://br.rnds.pro/ruby/mdocs_kramdown
170
171
  licenses: