markdown_extension 0.1.6 → 0.1.8

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: b3a4927b1f203ac6382d61c3b5661157b41e43fd285dcd807abe5d312148598b
4
- data.tar.gz: 838fbfa9f13025b11ba0418b2fe650e67e33ebb840c74db486a2507fafaf696e
3
+ metadata.gz: a8d4001e3e40c922319a6d0b2c00be6df4eea2b74b5b5b20a750bf035464e3c7
4
+ data.tar.gz: 1d43328253be594468dfcb53df1c7ce363915e9b8782f179c3f2c128044b3ec0
5
5
  SHA512:
6
- metadata.gz: b979e7bd361b1f5987ac414e5d185f1a37584b54c3dabc8ff4579d2e3251e3e4260ab2aa95332c8adf6eb0f8b1837071a113d6bd8328c0380d2c7556f08dfad0
7
- data.tar.gz: 490f49add269f2a7e5561d47786d6424382c2187a2582aea11d9f9b86a81b2e19c4a43daf014d48eede912492d4da591125ba8267795a0c7150ccea0f6c1e93b
6
+ metadata.gz: c60591d3bbd5c50f4b7428493aefce4dc0357bc7d50d97c3eabc092020894199ab66312f83c5db9f212ed339b9603ae3dce3e418e20ed1fdf13176faa522115e
7
+ data.tar.gz: b95b64b1e930bf987d224cf023d3ff3d2749177cd8328678d2fa88fb7401339798bb35fd54b21a7dc9006a404323e617050482dd37fb79f64b7ebde598f66939
@@ -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.pages_path+lang.to_s+"/","").gsub(".md","")
21
22
  @item_name = file.split("/")[-1].gsub(".md","")
22
23
  @ctime = File::ctime(file)
23
24
  @mtime = File::mtime(file)
@@ -82,6 +83,7 @@ module MarkdownExtension
82
83
  end
83
84
 
84
85
  def meta_html
86
+ return nil unless @meta
85
87
  meta_data = Tomlrb.parse(@meta)
86
88
  html = ""
87
89
  meta_data.each do |title, values|
@@ -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
- file = config.src+"/summary.md"
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
- @markdown = File.read(file)
15
+ @raw_md = File.read(file)
12
16
  else
13
- @markdown = ""
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
@@ -1,3 +1,3 @@
1
1
  module MarkdownExtension
2
- Version = '0.1.6'
2
+ Version = '0.1.8'
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.6
4
+ version: 0.1.8
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-05 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb