Class: MarkdownExtension::Citations

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_extension/citations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, type) ⇒ Citations

Returns a new instance of Citations.



4
5
6
7
8
9
10
11
# File 'lib/markdown_extension/citations.rb', line 4

def initialize(config, type)
    @config = config
    @type = type
    @inner_citations = {}
    if config.citation
        init_citation()
    end
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/markdown_extension/citations.rb', line 3

def config
  @config
end

#inner_citationsObject

Returns the value of attribute inner_citations.



3
4
5
# File 'lib/markdown_extension/citations.rb', line 3

def inner_citations
  @inner_citations
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/markdown_extension/citations.rb', line 3

def type
  @type
end

Instance Method Details

#add_embed_citation(file) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/markdown_extension/citations.rb', line 31

def add_embed_citation(file)
    text = File.read(file)
    text.gsub!("\t", "    ")
    temp_id = ""
    temp_context = ""
    prev_line = ""
    space = 0
    if text.index("id:: ")
        text.split("\n").each do |line|
            if temp_space = line.index("id:: ")
                temp_id = line.split("id:: ")[1]
                temp_context = prev_line + "\n"
                space = temp_space
                next
            end
            if line.strip == "collapsed:: true"
                next
            end
            if line.length - line.lstrip.length > space
                temp_context = temp_context + line + "\n"
            else
                unless temp_id==""
                    @inner_citations[temp_id] = temp_context
                end
            end
            prev_line = line
        end
    end
end

#add_inner_citation(file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/markdown_extension/citations.rb', line 16

def add_inner_citation(file)
    text = File.read(file)
    lines = text.split("\n")[4..-1]
    if lines
        i = 0
        while(i < lines.size) do
            content = lines[i][2..-1]
            page_no = lines[i+2].split("hl-page:: ")[1]
            id = lines[i+3].split("id:: ")[1]
            @inner_citations[id] = "P#{page_no} #{content}"
            i = i + 4
        end
    end
end

#get_inner_citation(id) ⇒ Object



61
62
63
# File 'lib/markdown_extension/citations.rb', line 61

def get_inner_citation(id)
    return @inner_citations[id]
end

#init_citationObject



13
14
# File 'lib/markdown_extension/citations.rb', line 13

def init_citation()
end