Class: MarkdownExtension::Citations
- Inherits:
-
Object
- Object
- MarkdownExtension::Citations
- Defined in:
- lib/markdown_extension/citations.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#inner_citations ⇒ Object
Returns the value of attribute inner_citations.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_embed_citation(file) ⇒ Object
- #add_inner_citation(file) ⇒ Object
- #get_inner_citation(id) ⇒ Object
- #init_citation ⇒ Object
-
#initialize(config, type) ⇒ Citations
constructor
A new instance of Citations.
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
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/markdown_extension/citations.rb', line 3 def config @config end |
#inner_citations ⇒ Object
Returns the value of attribute inner_citations.
3 4 5 |
# File 'lib/markdown_extension/citations.rb', line 3 def inner_citations @inner_citations end |
#type ⇒ Object
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 (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_citation ⇒ Object
13 14 |
# File 'lib/markdown_extension/citations.rb', line 13 def init_citation() end |