markdown_extension 0.1.5 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/markdown_extension/page.rb +7 -3
- data/lib/markdown_extension/summary.rb +21 -9
- data/lib/markdown_extension/version.rb +1 -1
- metadata +3 -5
- data/lib/markdown_extension/config.rb +0 -65
- data/lib/markdown_extension/site.rb +0 -111
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b376e1ac02eebca5b99b6baa165b64506440b424340e10a537372355d5e44255
|
4
|
+
data.tar.gz: 239b364368c6daaa07076ec97963fd5d1f324a5c8344e7231d1e6890a7709f8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c669e10efe4737eef8edf1d8e8622cf3864391a79e7cb3cd2271927b45d9034713233fd8db296c11a8951137bf5df9ab5409867178f99c1a3c85a37fe1dfc3bf
|
7
|
+
data.tar.gz: e38652c2bca74950b7dcb298768dd02fca03f824fa26882c448e4a1065c1c8b1f0210c1c65d477058169593c3fde9493e6bc75365c5f7a90532dbd63340301d2
|
@@ -4,11 +4,11 @@ require "tomlrb"
|
|
4
4
|
|
5
5
|
module MarkdownExtension
|
6
6
|
class Page
|
7
|
-
attr_accessor :site, :markdown, :meta, :item_name, :ctime, :mtime
|
7
|
+
attr_accessor :site, :markdown, :meta, :path, :item_name, :ctime, :mtime
|
8
8
|
|
9
|
-
def initialize(file, site)
|
9
|
+
def initialize(file, site, lang=nil)
|
10
10
|
@site = site
|
11
|
-
if File.
|
11
|
+
if File.exist?(file)
|
12
12
|
@markdown = File.read(file)
|
13
13
|
else
|
14
14
|
@markdown = ""
|
@@ -18,6 +18,7 @@ module MarkdownExtension
|
|
18
18
|
@meta = mds[1]
|
19
19
|
@markdown = mds[2..-1].join("---\n")
|
20
20
|
end
|
21
|
+
@path = file.gsub(site.config.src+lang+"/","").gsub(".md","")
|
21
22
|
@item_name = file.split("/")[-1].gsub(".md","")
|
22
23
|
@ctime = File::ctime(file)
|
23
24
|
@mtime = File::mtime(file)
|
@@ -69,6 +70,9 @@ module MarkdownExtension
|
|
69
70
|
end
|
70
71
|
@site.citations.get_inner_citation(id)
|
71
72
|
end
|
73
|
+
@markdown = @markdown.split("\n").collect {|line|
|
74
|
+
(line.strip.index("id:: ") && line.strip.length==41)? nil : line
|
75
|
+
}.compact.join("\n")
|
72
76
|
end
|
73
77
|
end
|
74
78
|
|
@@ -3,28 +3,40 @@ require "kramdown-parser-gfm"
|
|
3
3
|
|
4
4
|
module MarkdownExtension
|
5
5
|
class Summary
|
6
|
-
attr_accessor :config, :markdown
|
7
|
-
def initialize(config)
|
6
|
+
attr_accessor :config, :raw_md, :markdown
|
7
|
+
def initialize(config, lang=nil)
|
8
8
|
@config = config
|
9
|
-
|
10
|
-
|
11
|
-
@markdown = File.read(file)
|
9
|
+
if lang
|
10
|
+
file = config.src+"/"+lang+"/summary.md"
|
12
11
|
else
|
13
|
-
|
12
|
+
file = config.src+"/summary.md"
|
13
|
+
end
|
14
|
+
if File.exist?(file)
|
15
|
+
@raw_md = File.read(file)
|
16
|
+
else
|
17
|
+
@raw_md = ""
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
17
|
-
def pre_processing
|
21
|
+
def pre_processing(dir)
|
22
|
+
@markdown = @raw_md
|
18
23
|
if @config.preprocessing["backlinks"]
|
19
24
|
@markdown = @markdown.gsub(/\[\[(.*)\]\]/) do |s|
|
20
25
|
s = s[2..-3]
|
21
26
|
"[#{s}](#{s}.html)"
|
22
27
|
end
|
23
28
|
end
|
29
|
+
unless dir.empty?
|
30
|
+
@markdown = @markdown.gsub(/\[.*\]\((.*)\)/) do |s|
|
31
|
+
url = Regexp.last_match[1]
|
32
|
+
pn = Pathname.new(url)
|
33
|
+
s.gsub(url, "./"+pn.relative_path_from(dir+"/").to_s)
|
34
|
+
end
|
35
|
+
end
|
24
36
|
end
|
25
37
|
|
26
|
-
def html
|
27
|
-
pre_processing()
|
38
|
+
def html(dir=nil)
|
39
|
+
pre_processing(dir)
|
28
40
|
return Kramdown::Document.new(@markdown, input: 'GFM').to_html
|
29
41
|
end
|
30
42
|
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.
|
4
|
+
version: 0.1.7
|
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-
|
11
|
+
date: 2023-02-17 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.
|
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
|