markdown_extension 0.1.6 → 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 +3 -2
- data/lib/markdown_extension/summary.rb +20 -8
- data/lib/markdown_extension/version.rb +1 -1
- metadata +2 -2
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,9 +4,9 @@ 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
11
|
if File.exist?(file)
|
12
12
|
@markdown = File.read(file)
|
@@ -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)
|
@@ -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
|
-
|
9
|
+
if lang
|
10
|
+
file = config.src+"/"+lang+"/summary.md"
|
11
|
+
else
|
12
|
+
file = config.src+"/summary.md"
|
13
|
+
end
|
10
14
|
if File.exist?(file)
|
11
|
-
@
|
15
|
+
@raw_md = File.read(file)
|
12
16
|
else
|
13
|
-
@
|
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-02-
|
11
|
+
date: 2023-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tomlrb
|