markdown_extension 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bab0fc1cbab47458d317c5444ed844e94c29c46e6f0c4875f0f7dab3a7a1ac0
4
- data.tar.gz: c7d700171cbe05cb754cd4b25f8822eb2d5542f68372f4fab465e4e096b647ec
3
+ metadata.gz: b3a4927b1f203ac6382d61c3b5661157b41e43fd285dcd807abe5d312148598b
4
+ data.tar.gz: 838fbfa9f13025b11ba0418b2fe650e67e33ebb840c74db486a2507fafaf696e
5
5
  SHA512:
6
- metadata.gz: 8efaa59df86d779cec7024b8a29252f67188c5355bb946fe7b3107adda604af9f123d5561ab217f6a1b1fed2b6fe04b1485c001619e1fbe32f316b0a0356dab6
7
- data.tar.gz: ef70615088430a67706d6406298e70635e647827c27181175732d919adc4ebfc4dd4e873f7fae6fce29a840e272b0833a1044655c0895e2adda2f11a8a932b7c
6
+ metadata.gz: b979e7bd361b1f5987ac414e5d185f1a37584b54c3dabc8ff4579d2e3251e3e4260ab2aa95332c8adf6eb0f8b1837071a113d6bd8328c0380d2c7556f08dfad0
7
+ data.tar.gz: 490f49add269f2a7e5561d47786d6424382c2187a2582aea11d9f9b86a81b2e19c4a43daf014d48eede912492d4da591125ba8267795a0c7150ccea0f6c1e93b
@@ -8,7 +8,7 @@ module MarkdownExtension
8
8
 
9
9
  def initialize(file, site)
10
10
  @site = site
11
- if File.exists?(file)
11
+ if File.exist?(file)
12
12
  @markdown = File.read(file)
13
13
  else
14
14
  @markdown = ""
@@ -69,6 +69,9 @@ module MarkdownExtension
69
69
  end
70
70
  @site.citations.get_inner_citation(id)
71
71
  end
72
+ @markdown = @markdown.split("\n").collect {|line|
73
+ (line.strip.index("id:: ") && line.strip.length==41)? nil : line
74
+ }.compact.join("\n")
72
75
  end
73
76
  end
74
77
 
@@ -7,7 +7,7 @@ module MarkdownExtension
7
7
  def initialize(config)
8
8
  @config = config
9
9
  file = config.src+"/summary.md"
10
- if File.exists?(file)
10
+ if File.exist?(file)
11
11
  @markdown = File.read(file)
12
12
  else
13
13
  @markdown = ""
@@ -1,3 +1,3 @@
1
1
  module MarkdownExtension
2
- Version = '0.1.5'
2
+ Version = '0.1.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_extension
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
  - Zhuang Biaowei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-13 00:00:00.000000000 Z
11
+ date: 2023-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb
@@ -61,9 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - lib/markdown_extension.rb
63
63
  - lib/markdown_extension/citations.rb
64
- - lib/markdown_extension/config.rb
65
64
  - lib/markdown_extension/page.rb
66
- - lib/markdown_extension/site.rb
67
65
  - lib/markdown_extension/summary.rb
68
66
  - lib/markdown_extension/version.rb
69
67
  homepage: https://github.com/markdown-world/markdown_extension
@@ -85,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
83
  - !ruby/object:Gem::Version
86
84
  version: '0'
87
85
  requirements: []
88
- rubygems_version: 3.3.5
86
+ rubygems_version: 3.4.6
89
87
  signing_key:
90
88
  specification_version: 4
91
89
  summary: A markdown extension for generating HTML in order to support a wider variety
@@ -1,65 +0,0 @@
1
- require "tomlrb"
2
-
3
- module MarkdownExtension
4
- class Config
5
- attr_accessor :raw_config, :file, :type
6
-
7
- def load_file(file)
8
- @raw_config = begin
9
- Tomlrb.load_file(file)
10
- rescue
11
- {}
12
- end
13
- end
14
-
15
- def initialize(file, type)
16
- @file = file
17
- @type = type
18
- load_file(file)
19
- return self
20
- end
21
-
22
- def get_base_info(name)
23
- if @raw_config
24
- if @raw_config[@type.to_s]
25
- return @raw_config[@type.to_s][name]
26
- end
27
- end
28
- ""
29
- end
30
-
31
- def title
32
- get_base_info("title")
33
- end
34
-
35
- def src
36
- get_base_info("src")
37
- end
38
-
39
- def pages
40
- get_base_info("pages")
41
- end
42
-
43
- def journals
44
- get_base_info("journals")
45
- end
46
-
47
- def preprocessing
48
- if @raw_config
49
- return @raw_config["preprocessing"]
50
- end
51
- end
52
-
53
- def giscus
54
- if @raw_config
55
- return @raw_config["giscus"]
56
- end
57
- end
58
-
59
- def citation
60
- if @raw_config
61
- return @raw_config["citation"]
62
- end
63
- end
64
- end
65
- end
@@ -1,111 +0,0 @@
1
- require "json"
2
-
3
- module MarkdownExtension
4
- class Site
5
- attr_accessor :config, :summary, :pages, :journals, :references, :reverse_references
6
- attr_accessor :nodes, :links, :citations
7
-
8
- def initialize(config, type)
9
- @config = MarkdownExtension::Config.new(config, type)
10
- @citations = MarkdownExtension::Citations.new(@config, type)
11
- unless type == :logseq
12
- @summary = MarkdownExtension::Summary.new(@config)
13
- end
14
- @references = {}
15
- @reverse_references = {}
16
- @nodes = []
17
- @links = []
18
- load_source_files()
19
- gen_nodes_links()
20
- end
21
-
22
- def load_source_files
23
- @pages = []
24
- @journals = []
25
- if @config
26
- if @config.type == :logseq
27
- journal_files = Dir.glob(@config.journals + "/*.md")
28
- journal_files.each do |file|
29
- page = MarkdownExtension::Page.new(file, self)
30
- @journals << page
31
- end
32
- pages_path = @config.pages
33
- else
34
- pages_path = @config.src
35
- end
36
- files = Dir.glob(pages_path + "/*.md")
37
- files.each do |file|
38
- unless file == pages_path + "/summary.md"
39
- if file.index("hls_")
40
- @citations.add_inner_citation(file)
41
- else
42
- @citations.add_embed_citation(file)
43
- end
44
- end
45
- end
46
- files.each do |file|
47
- unless file == pages_path + "/summary.md"
48
- unless file.index("hls_")
49
- page = MarkdownExtension::Page.new(file, self)
50
- @pages << page
51
- gen_references(file , page.markdown)
52
- end
53
- end
54
- end
55
- end
56
- end
57
-
58
- def gen_references(file, text)
59
- text.gsub(/\[\[([^\]]+)\]\]/) do |s|
60
- s = s[2..-3]
61
- item_name = file.split("/")[-1].gsub(".md","")
62
- if @references[s]
63
- @references[s] << item_name
64
- else
65
- @references[s] = [item_name]
66
- end
67
- if @reverse_references[item_name]
68
- @reverse_references[item_name] << s
69
- else
70
- @reverse_references[item_name] = [s]
71
- end
72
- end
73
- end
74
-
75
- def gen_nodes_links
76
- @references.each do |k,v|
77
- val = @references[k] ? @references[k].size+1 : 1
78
- val = 5 if val > 5
79
- @nodes << {
80
- "id" => k,
81
- "name" => k,
82
- "color" => "blue",
83
- "val" => val
84
- }
85
- v.each do |item|
86
- val = @references[item] ? @references[item].size+1 : 1
87
- val = 5 if val > 5
88
- @nodes << {
89
- "id" => item,
90
- "name" => item,
91
- "color" => "blue",
92
- "val" => val
93
- }
94
- @links << {
95
- "source" => item,
96
- "target" => k
97
- }
98
- end
99
- end
100
- @nodes = @nodes.uniq
101
- @links = @links.uniq
102
- end
103
-
104
- def write_data_json(file)
105
- data = {"nodes"=>@nodes, "links"=>@links}
106
- f = File.new(file, "w")
107
- f.puts JSON.generate(data)
108
- f.close
109
- end
110
- end
111
- end