markdown_extension 0.1.0 → 0.1.1
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 +4 -4
- data/lib/markdown_extension/citations.rb +35 -0
- data/lib/markdown_extension/config.rb +6 -0
- data/lib/markdown_extension/page.rb +24 -16
- data/lib/markdown_extension/site.rb +15 -5
- data/lib/markdown_extension/version.rb +1 -1
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 50bb6063bec2d619b87dddd8d941635acaeb2e2f95899e8ca74c213bf017664e
         | 
| 4 | 
            +
              data.tar.gz: 288f5dc792f1169d89dd41d0efaa2e2a6714b17f2b046b41ce3ba976365b17d5
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 076606e9de4f65f96152d76e5a281cb821424d67554b93039493ef870e2eaef2debbc5fb2ba8f9634906e0a0f6a2733aa07aa3aac1094aeaef56ba98cc6ba4bf
         | 
| 7 | 
            +
              data.tar.gz: 7e6eeb642e42bf0220b2e4d455591583d34a1ed3eb89488042ca100bdfdf04424b0465de6d6085fed13f969e173be195509ca4a1d815845e8cfe912622c1e560
         | 
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            module MarkdownExtension
         | 
| 2 | 
            +
                class Citations
         | 
| 3 | 
            +
                    attr_accessor :config, :type, :inner_citations
         | 
| 4 | 
            +
                    def initialize(config, type)
         | 
| 5 | 
            +
                        @config = config
         | 
| 6 | 
            +
                        @type = type
         | 
| 7 | 
            +
                        @inner_citations = {}            
         | 
| 8 | 
            +
                        if config.citation
         | 
| 9 | 
            +
                            init_citation()
         | 
| 10 | 
            +
                        end
         | 
| 11 | 
            +
                    end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    def init_citation()
         | 
| 14 | 
            +
                    end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    def add_inner_citation(file)
         | 
| 17 | 
            +
                        text = File.read(file)
         | 
| 18 | 
            +
                        lines = text.split("\n")[4..-1]
         | 
| 19 | 
            +
                        if lines
         | 
| 20 | 
            +
                            i = 0
         | 
| 21 | 
            +
                            while(i < lines.size) do
         | 
| 22 | 
            +
                                content = lines[i][2..-1]
         | 
| 23 | 
            +
                                page_no = lines[i+2].split("hl-page:: ")[1]
         | 
| 24 | 
            +
                                id = lines[i+3].split("id:: ")[1]
         | 
| 25 | 
            +
                                @inner_citations[id] = "P#{page_no} #{content}"
         | 
| 26 | 
            +
                                i = i + 4
         | 
| 27 | 
            +
                            end
         | 
| 28 | 
            +
                        end            
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    def get_inner_citation(id)
         | 
| 32 | 
            +
                        return @inner_citations[id]
         | 
| 33 | 
            +
                    end
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
            end
         | 
| @@ -18,22 +18,7 @@ module MarkdownExtension | |
| 18 18 | 
             
                            @meta = mds[1]
         | 
| 19 19 | 
             
                            @markdown = mds[2..-1].join("---\n")
         | 
| 20 20 | 
             
                        end
         | 
| 21 | 
            -
                         | 
| 22 | 
            -
                            @markdown.gsub!(/\t/, "    ")
         | 
| 23 | 
            -
                            if @markdown[-1]=="-"
         | 
| 24 | 
            -
                                @markdown = @markdown[0..-2]
         | 
| 25 | 
            -
                            end
         | 
| 26 | 
            -
                            @markdown.gsub!("(../assets/", "(./assets/")
         | 
| 27 | 
            -
                            @markdown.gsub!(/(.+)collapsed:: true\n/, "")
         | 
| 28 | 
            -
                            @markdown = @markdown.gsub(/.+(- )[0-9]+\./) do |s|
         | 
| 29 | 
            -
                                s.gsub("- ","")
         | 
| 30 | 
            -
                            end
         | 
| 31 | 
            -
                            while (i = @markdown.index(":LOGBOOK:")) do 
         | 
| 32 | 
            -
                                j = @markdown.index(":END:", i)
         | 
| 33 | 
            -
                                @markdown=@markdown[0..i-4] + @markdown[j+5..-1]
         | 
| 34 | 
            -
                            end
         | 
| 35 | 
            -
                        end
         | 
| 36 | 
            -
                        @item_name = file.split("/")[-1].gsub(".md","")
         | 
| 21 | 
            +
                        @item_name = file.split("/")[-1].gsub(".md","")            
         | 
| 37 22 | 
             
                    end
         | 
| 38 23 |  | 
| 39 24 | 
             
                    def pre_processing
         | 
| @@ -56,6 +41,29 @@ module MarkdownExtension | |
| 56 41 | 
             
                                end
         | 
| 57 42 | 
             
                            end
         | 
| 58 43 | 
             
                        end
         | 
| 44 | 
            +
                        if @site.config.type == :logseq
         | 
| 45 | 
            +
                            @markdown.gsub!(/\t/, "    ")
         | 
| 46 | 
            +
                            if @markdown[-1]=="-"
         | 
| 47 | 
            +
                                @markdown = @markdown[0..-2]
         | 
| 48 | 
            +
                            end
         | 
| 49 | 
            +
                            @markdown.gsub!("(../assets/", "(./assets/")
         | 
| 50 | 
            +
                            @markdown.gsub!(/(.+)collapsed:: true\n/, "")
         | 
| 51 | 
            +
                            @markdown = @markdown.gsub(/.+(- )[0-9]+\./) do |s|
         | 
| 52 | 
            +
                                s.gsub("- ","")
         | 
| 53 | 
            +
                            end
         | 
| 54 | 
            +
                            while (i = @markdown.index(":LOGBOOK:")) do 
         | 
| 55 | 
            +
                                j = @markdown.index(":END:", i)
         | 
| 56 | 
            +
                                @markdown=@markdown[0..i-4] + @markdown[j+5..-1]
         | 
| 57 | 
            +
                            end
         | 
| 58 | 
            +
                            @markdown = @markdown.gsub(/\(\([^\)]+\)\)/) do |s|
         | 
| 59 | 
            +
                                if s.index(":")
         | 
| 60 | 
            +
                                    id = s
         | 
| 61 | 
            +
                                else
         | 
| 62 | 
            +
                                    id = s[2..-3]                        
         | 
| 63 | 
            +
                                end
         | 
| 64 | 
            +
                                @site.citations.get_inner_citation(id)
         | 
| 65 | 
            +
                            end
         | 
| 66 | 
            +
                        end
         | 
| 59 67 | 
             
                    end
         | 
| 60 68 |  | 
| 61 69 | 
             
                    def html
         | 
| @@ -3,10 +3,11 @@ require "json" | |
| 3 3 | 
             
            module MarkdownExtension
         | 
| 4 4 | 
             
                class Site
         | 
| 5 5 | 
             
                    attr_accessor :config, :summary, :pages, :journals, :references, :reverse_references
         | 
| 6 | 
            -
                    attr_accessor :nodes, :links
         | 
| 6 | 
            +
                    attr_accessor :nodes, :links, :citations
         | 
| 7 7 |  | 
| 8 8 | 
             
                    def initialize(config, type)
         | 
| 9 9 | 
             
                        @config = MarkdownExtension::Config.new(config, type)
         | 
| 10 | 
            +
                        @citations = MarkdownExtension::Citations.new(@config, type)
         | 
| 10 11 | 
             
                        unless type == :logseq
         | 
| 11 12 | 
             
                            @summary = MarkdownExtension::Summary.new(@config)
         | 
| 12 13 | 
             
                        end
         | 
| @@ -34,10 +35,19 @@ module MarkdownExtension | |
| 34 35 | 
             
                            end
         | 
| 35 36 | 
             
                            files = Dir.glob(pages_path + "/*.md")
         | 
| 36 37 | 
             
                            files.each do |file|
         | 
| 37 | 
            -
                                unless file ==  | 
| 38 | 
            -
                                     | 
| 39 | 
            -
             | 
| 40 | 
            -
                                     | 
| 38 | 
            +
                                unless file == pages_path + "/summary.md"
         | 
| 39 | 
            +
                                    if file.index("hls_")
         | 
| 40 | 
            +
                                        @citations.add_inner_citation(file)
         | 
| 41 | 
            +
                                    end
         | 
| 42 | 
            +
                                end
         | 
| 43 | 
            +
                            end
         | 
| 44 | 
            +
                            files.each do |file|
         | 
| 45 | 
            +
                                unless file == pages_path + "/summary.md"
         | 
| 46 | 
            +
                                    unless file.index("hls_")
         | 
| 47 | 
            +
                                        page = MarkdownExtension::Page.new(file, self)
         | 
| 48 | 
            +
                                        @pages << page
         | 
| 49 | 
            +
                                        gen_references(file , page.markdown)
         | 
| 50 | 
            +
                                    end
         | 
| 41 51 | 
             
                                end
         | 
| 42 52 | 
             
                            end
         | 
| 43 53 | 
             
                        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.1
         | 
| 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- | 
| 11 | 
            +
            date: 2023-01-07 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: tomlrb
         | 
| @@ -60,6 +60,7 @@ extensions: [] | |
| 60 60 | 
             
            extra_rdoc_files: []
         | 
| 61 61 | 
             
            files:
         | 
| 62 62 | 
             
            - lib/markdown_extension.rb
         | 
| 63 | 
            +
            - lib/markdown_extension/citations.rb
         | 
| 63 64 | 
             
            - lib/markdown_extension/config.rb
         | 
| 64 65 | 
             
            - lib/markdown_extension/page.rb
         | 
| 65 66 | 
             
            - lib/markdown_extension/site.rb
         |