.*)\]/
+ end
+
def headline
/^\*+\s+/
end
diff --git a/lib/org-ruby/markdown_output_buffer.rb b/lib/org-ruby/markdown_output_buffer.rb
index 62dc891..f149ec3 100644
--- a/lib/org-ruby/markdown_output_buffer.rb
+++ b/lib/org-ruby/markdown_output_buffer.rb
@@ -69,11 +69,6 @@ def inline_formatting(input)
input
end
- # TODO: Implement this
- def output_footnotes!
- return false
- end
-
# Flushes the current buffer
def flush!
return false if @buffer.empty? and @output_type != :blank
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index d81a122..4bc9594 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -7,14 +7,14 @@ module Orgmode
# add a newline character prior emitting the output.
class OutputBuffer
# This is the overall output buffer
- attr_reader :output, :mode_stack, :list_indent_stack
+ attr_reader :output, :mode_stack, :list_indent_stack, :document
# This is the current type of output being accumulated.
attr_accessor :output_type, :headline_number_stack, :custom_blocktags
# Creates a new OutputBuffer object that is bound to an output object.
# The output will get flushed to =output=.
- def initialize(output)
+ def initialize(output, document = nil)
# This is the accumulation buffer. It's a holding pen so
# consecutive lines of the right type can get stuck together
# without intervening newlines.
@@ -29,6 +29,7 @@ def initialize(output)
@list_indent_stack = []
@mode_stack = []
@custom_blocktags = []
+ @document = document
# regexp module
@re_help = RegexpHelper.new
@@ -169,6 +170,10 @@ def no_custom_markup_file_exist
nil
end
+ def output_footnotes!
+ # Implement in output buffers
+ end
+
protected
attr_reader :block_lang
@@ -257,10 +262,6 @@ def add_headline_id(line)
# Implement this in output buffers
end
- def output_footnotes!
- false
- end
-
# Tests if the current line should be accumulated in the current
# output buffer.
def should_accumulate_output?(line)
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 9f5cc71..d1e4c5e 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -57,7 +57,7 @@ def export_todo?
# Returns true if we are to export footnotes
def export_footnotes?
- "t" == @options["f"]
+ "nil" != @options["f"]
end
# Returns true if we are to export heading numbers.
@@ -97,14 +97,15 @@ def initialize_lines(lines)
# I can construct a parser object either with an array of lines
# or with a single string that I will split along \n boundaries.
def initialize(lines, parser_options = {})
- @lines = initialize_lines lines
+ @lines = initialize_lines(lines)
@custom_keywords = []
- @headlines = []
@current_headline = nil
- @header_lines = []
+ @document = Orgmode::Elements::Document.new
@in_buffer_settings = {}
- @options = {}
+ @headlines = []
+ @header_lines = []
@link_abbrevs = {}
+ @options = {}
@parser_options = parser_options
#
@@ -170,6 +171,9 @@ def parse_lines(lines)
@link_abbrevs[link_abbrev_data[0]] = link_abbrev_data[1]
end
+ # Store footnotes
+ document.store_footnote(line)
+
if (line.end_block? && [line.paragraph_type, :comment].include?(mode)) ||
(line.property_drawer_end_block? && (mode == :property_drawer))
mode = :normal
@@ -309,12 +313,13 @@ def self.load(fname, _opts = {})
# Saves the loaded orgmode file as a textile file.
def to_textile
output = ''
- output_buffer = TextileOutputBuffer.new(output)
+ output_buffer = TextileOutputBuffer.new(output, document)
translate(@header_lines, output_buffer)
@headlines.each do |headline|
translate(headline.body_lines, output_buffer)
end
+ output_buffer.output_footnotes!
output
end
@@ -339,8 +344,8 @@ def to_html
decorate_title: in_buffer_settings['TITLE'],
export_heading_number: export_heading_number?,
export_todo: export_todo?,
- use_sub_superscripts: use_sub_superscripts?,
export_footnotes: export_footnotes?,
+ use_sub_superscripts: use_sub_superscripts?,
link_abbrevs: @link_abbrevs,
skip_syntax_highlight: @parser_options[:skip_syntax_highlight],
markup_file: @parser_options[:markup_file],
@@ -350,8 +355,7 @@ def to_html
}
export_options[:skip_tables] = true unless export_tables?
output = ''
- output_buffer = HtmlOutputBuffer.new(output, export_options)
-
+ output_buffer = HtmlOutputBuffer.new(output, document, export_options)
if title?
# If we're given a new title, then just create a new line
# for that title.
@@ -379,7 +383,10 @@ def title
in_buffer_settings['TITLE']
end
- ######################################################################
+ protected
+
+ attr_reader :document
+
private
def translate_headlines(headlines, output_buffer)
@@ -391,6 +398,7 @@ def translate_headlines(headlines, output_buffer)
translate(headline.body_lines, output_buffer)
end
end
+ output_buffer.output_footnotes!
end
# Converts an array of lines to the appropriate format.
@@ -400,7 +408,6 @@ def translate(lines, output_buffer)
lines.each { |line| output_buffer.insert(line) }
output_buffer.flush!
output_buffer.pop_mode while output_buffer.current_mode
- output_buffer.output_footnotes!
output_buffer.output
end
diff --git a/lib/org-ruby/regexp_helper.rb b/lib/org-ruby/regexp_helper.rb
index 4ecc286..ddad892 100644
--- a/lib/org-ruby/regexp_helper.rb
+++ b/lib/org-ruby/regexp_helper.rb
@@ -108,14 +108,16 @@ def rewrite_subp(str)
# rewrite footnotes
def rewrite_footnote(str)
- str.gsub!(org_footnote_regexp) do |_match|
- yield Regexp.last_match(1), Regexp.last_match(3)
+ str.gsub!(RegexpHelper.footnote_reference) do |_match|
+ match = Regexp.last_match
+ yield match[:label], match[:contents]
end
end
- def rewrite_footnote_definition(str)
- str.gsub!(org_footnote_def_regexp) do |_match|
- yield Regexp.last_match(1), Regexp.last_match(5)
+ def capture_footnote_definition(str)
+ str.gsub!(RegexpHelper.footnote_definition) do |_match|
+ match = Regexp.last_match
+ yield match[:label], match[:contents]
end
end
diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb
index c6914ff..3f977f8 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -1,20 +1,18 @@
require 'stringio'
module Orgmode
-
class TextileOutputBuffer < OutputBuffer
- def initialize(output)
- super(output)
+ def initialize(output, document = nil)
+ super(output, document)
@add_paragraph = true
@support_definition_list = true # TODO this should be an option
- @footnotes = []
end
def push_mode(mode, indent, properties={})
super(mode, indent, properties)
@output << "bc. " if mode_is_code? mode
- if mode == :center or mode == :quote
+ if mode == :center || mode == :quote
@add_paragraph = false
@output << "\n"
end
@@ -23,7 +21,7 @@ def push_mode(mode, indent, properties={})
def pop_mode
m = super
@list_indent_stack.pop
- if m == :center or m == :quote
+ if m == :center || m == :quote
@add_paragraph = true
@output << "\n"
end
@@ -46,13 +44,15 @@ def inline_formatting(input)
m = TextileMap[marker]
"#{m}#{body}#{m}"
end
+
@re_help.rewrite_subp input do |type, text|
- if type == "_" then
+ if type == "_"
"~#{text}~"
- elsif type == "^" then
+ elsif type == "^"
"^#{text}^"
end
end
+
@re_help.rewrite_links input do |link, defi|
[link, defi].compact.each do |text|
# We don't support search links right now. Get rid of it.
@@ -78,35 +78,33 @@ def inline_formatting(input)
"!#{link}(#{link})!"
end
end
- @re_help.rewrite_footnote input do |name, definition|
+
+ @re_help.capture_footnote_definition(input) do |_label, _content|
+ # Capture definition and replace it with nil
+ nil
+ end
+
+ @re_help.rewrite_footnote(input) do |label, content|
# textile only support numerical names, so we need to do some conversion
# Try to find the footnote and use its index
- footnote = @footnotes.select {|f| f[:name] == name }.first
- if footnote
- # The latest definition overrides other ones
- footnote[:definition] = definition if definition and not footnote[:definition]
- else
- # There is no footnote with the current name so we add it
- footnote = { :name => name, :definition => definition }
- @footnotes << footnote
+ footnote = document.footnotes.find do |footnote|
+ footnote[:label] == label || footnote[:content] == content
end
- "[#{@footnotes.index(footnote)}]"
+ "[#{footnote[:index]}]"
end
+
Orgmode.special_symbols_to_textile(input)
input = @re_help.restore_code_snippets input
input
end
def output_footnotes!
- return false if @footnotes.empty?
+ return if document.footnotes.empty?
- @footnotes.each do |footnote|
- index = @footnotes.index(footnote)
- @output << "\nfn#{index}. #{footnote[:definition] || 'DEFINITION NOT FOUND' }\n"
+ document.footnotes.each do |footnote|
+ @output << "\nfn#{footnote[:index]}. #{footnote[:content].lstrip || 'DEFINITION NOT FOUND' }\n"
end
-
- return true
end
# Flushes the current buffer
@@ -150,5 +148,5 @@ def flush!
def add_line_attributes headline
@output << "h#{headline.level}. "
end
- end # class TextileOutputBuffer
-end # module Orgmode
+ end
+end
diff --git a/lib/orgmode/elements.rb b/lib/orgmode/elements.rb
new file mode 100644
index 0000000..d4a2889
--- /dev/null
+++ b/lib/orgmode/elements.rb
@@ -0,0 +1,4 @@
+module Orgmode
+ module Elements
+ end
+end
diff --git a/lib/orgmode/elements/document.rb b/lib/orgmode/elements/document.rb
new file mode 100644
index 0000000..86c1efe
--- /dev/null
+++ b/lib/orgmode/elements/document.rb
@@ -0,0 +1,34 @@
+module Orgmode
+ module Elements
+ class Document
+ attr_reader :footnotes
+
+ def initialize
+ @footnotes = []
+ end
+
+ def store_footnote(line)
+ return unless line.footnote?
+
+ if RegexpHelper.footnote_definition.match(line.to_s)
+ match = Regexp.last_match
+ label = match[:label]
+ content = match[:contents]
+ elsif RegexpHelper.footnote_reference.match(line.to_s)
+ match = Regexp.last_match
+ label = match[:label]
+ content = match[:contents]
+ end
+ footnote = @footnotes.find { |footnote| footnote[:label] == label }
+
+ if footnote.nil?
+ footnote_index = @footnotes.length + 1
+ footnote = { index: footnote_index, label: label, content: content }
+ @footnotes.push(footnote)
+ else
+ footnote[:content] = content
+ end
+ end
+ end
+ end
+end
diff --git a/spec/html_examples/footnotes.html b/spec/html_examples/footnotes.html
index 15b295c..82450b3 100644
--- a/spec/html_examples/footnotes.html
+++ b/spec/html_examples/footnotes.html
@@ -1,111 +1,33 @@
Footnotes
-Using letters and not defined in the footnote
-Defined in the footnote itself with markup
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
-Using letters and defined in the footnote
+Using letters and not defined in the footnote
+Defined in the footnote itself with markup
+Some example paragraph , with text at the end.
+Some example paragraph , with text at the end.
+Some example paragraph , with text at the end.
+Some example paragraph , with text at the end.
+Some example paragraph , with text at the end.
+Some example paragraph , with text at the end.
+Some example paragraph , with text at the end.
+Some example paragraph , with text at the end.
+
+
+
+
+
+
+Using letters and defined in the footnote
diff --git a/spec/html_examples/footnotes.org b/spec/html_examples/footnotes.org
index 15ceeac..1dfc57f 100644
--- a/spec/html_examples/footnotes.org
+++ b/spec/html_examples/footnotes.org
@@ -9,200 +9,29 @@ Some example paragraph [fn:1], with text at the end.
Some example paragraph [fn:2], with text at the end.
-Some example paragraph [fn:3], with text at the end.
+Some example paragraph [fn:3:fifth footnote label 3], with text at the end.
-Some example paragraph [fn:4], with text at the end.
-
-Some example paragraph [fn:5], with text at the end.
-
-Some example paragraph [fn:6], with text at the end.
-
-Some example paragraph [fn:7], with text at the end.
-
-Some example paragraph [fn:8], with text at the end.
-
-Some example paragraph [fn:9], with text at the end.
-
-Some example paragraph [fn:10], with text at the end.
-
-Some example paragraph [fn:11], with text at the end.
+Some example paragraph [fn::a footnote], with text at the end.
Some example paragraph [fn:12], with text at the end.
-Some example paragraph [fn:13], with text at the end.
+Some example paragraph [fn:unamed], with text at the end.
Some example paragraph [fn:14], with text at the end.
-Some example paragraph [fn:15], with text at the end.
-
-Some example paragraph [fn:16], with text at the end.
-
-Some example paragraph [fn:17], with text at the end.
-
-Some example paragraph [fn:18], with text at the end.
-
-Some example paragraph [fn:19], with text at the end.
-
-Some example paragraph [fn:20], with text at the end.
-
-Some example paragraph [fn:21], with text at the end.
-
-Some example paragraph [fn:22], with text at the end.
-
-Some example paragraph [fn:23], with text at the end.
-
-Some example paragraph [fn:24], with text at the end.
-
-Some example paragraph [fn:25], with text at the end.
-
-Some example paragraph [fn:26], with text at the end.
-
-Some example paragraph [fn:27], with text at the end.
-
-Some example paragraph [fn:28], with text at the end.
-
-Some example paragraph [fn:29], with text at the end.
-
-Some example paragraph [fn:30], with text at the end.
+Some example paragraph [fn:last], with text at the end.
-Some example paragraph [fn:31], with text at the end.
-
-Some example paragraph [fn:32], with text at the end.
-
-Some example paragraph [fn:33], with text at the end.
-
-Some example paragraph [fn:34], with text at the end.
-
-Some example paragraph [fn:35], with text at the end.
-
-Some example paragraph [fn:36], with text at the end.
-
-Some example paragraph [fn:37], with text at the end.
-
-Some example paragraph [fn:38], with text at the end.
-
-Some example paragraph [fn:39], with text at the end.
-
-Some example paragraph [fn:40], with text at the end.
-
-Some example paragraph [fn:41], with text at the end.
-
-Some example paragraph [fn:42], with text at the end.
-
-Some example paragraph [fn:43], with text at the end.
-
-Some example paragraph [fn:44], with text at the end.
-
-Some example paragraph [fn:45], with text at the end.
-
-Some example paragraph [fn:46], with text at the end.
-
-Some example paragraph [fn:47], with text at the end.
-
-Some example paragraph [fn:48], with text at the end.
-
-Some example paragraph [fn:49], with text at the end.
-
-Some example paragraph [fn:50], with text at the end.
-
-[fn:1] And some example footnote
+[fn:1] And some example footnote definition
[fn:2] And some example footnote
-[fn:3] And some example footnote
-
-[fn:4] And some example footnote
-
-[fn:5] And some example footnote
-
-[fn:6] And some example footnote
-
-[fn:7] And some example footnote
-
-[fn:8] And some example footnote
-
-[fn:9] And some example footnote
-
-[fn:10] And some example footnote
-
-[fn:11] And some example footnote
-
[fn:12] And some example footnote
-[fn:13] And some example footnote
+[fn:unamed] And some example footnote label
[fn:14] And some example footnote
-[fn:15] And some example footnote
-
-[fn:16] And some example footnote
-
-[fn:17] And some example footnote
-
-[fn:18] And some example footnote
-
-[fn:19] And some example footnote
-
-[fn:20] And some example footnote
-
-[fn:21] And some example footnote
-
-[fn:22] And some example footnote
-
-[fn:23] And some example footnote
-
-[fn:24] And some example footnote
-
-[fn:25] And some example footnote
-
-[fn:26] And some example footnote
-
-[fn:27] And some example footnote
-
-[fn:28] And some example footnote
-
-[fn:29] And some example footnote
-
-[fn:30] And some example footnote
-
-[fn:31] And some example footnote
-
-[fn:32] And some example footnote
-
-[fn:33] And some example footnote
-
-[fn:34] And some example footnote
-
-[fn:35] And some example footnote
-
-[fn:36] And some example footnote
-
-[fn:37] And some example footnote
-
-[fn:38] And some example footnote
-
-[fn:39] And some example footnote
-
-[fn:40] And some example footnote
-
-[fn:41] And some example footnote
-
-[fn:42] And some example footnote
-
-[fn:43] And some example footnote
-
-[fn:44] And some example footnote
-
-[fn:45] And some example footnote
-
-[fn:46] And some example footnote
-
-[fn:47] And some example footnote
-
-[fn:48] And some example footnote
-
-[fn:49] And some example footnote
+[fn:last] And some example footnote
-[fn:50] And some example footnote
Using letters and defined in the footnote [fn:abc:definition of abc]
diff --git a/spec/html_examples/footnotes_title.html b/spec/html_examples/footnotes_title.html
deleted file mode 100644
index bd563b7..0000000
--- a/spec/html_examples/footnotes_title.html
+++ /dev/null
@@ -1,111 +0,0 @@
-Footnotes
-Using letters and not defined in the footnote
-Defined in the footnote itself with markup
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
-Some example paragraph , with text at the end.
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
- And some example footnote
-Using letters and defined in the footnote
-
diff --git a/spec/line_spec.rb b/spec/line_spec.rb
index dc1b086..02cd072 100644
--- a/spec/line_spec.rb
+++ b/spec/line_spec.rb
@@ -30,6 +30,26 @@
end
end
+ describe "footnote?" do
+ let(:line) { Orgmode::Line.new(footnote) }
+
+ context "when it's a definition footnotes" do
+ let(:footnote) { "[fn:label] An its definition" }
+
+ it { expect(line.footnote?).to be_truthy }
+ end
+
+ context "when it's a reference footnote" do
+ let(:footnote) { "This line has [fn:a:footnote:with definition]" }
+ it { expect(line.footnote?).to be_truthy }
+ end
+
+ context "recognize anonymous footnotes" do
+ let(:footnote) { "Also works [fn::Anonymous] footnotes" }
+
+ it { expect(line.footnote?).to be_truthy }
+ end
+ end
it "should tell blank lines" do
blank = ["", " ", "\t", "\n", " \t\t\n\n"]
blank.each do |b|
diff --git a/spec/org-ruby/html_output_buffer_spec.rb b/spec/org-ruby/html_output_buffer_spec.rb
index 5ead7e0..f58fc48 100644
--- a/spec/org-ruby/html_output_buffer_spec.rb
+++ b/spec/org-ruby/html_output_buffer_spec.rb
@@ -16,9 +16,27 @@ module Orgmode
expect(buffer.buffer_tag).to eq 'HTML'
end
+ context 'when call with a document' do
+ let(:document) { "This is a document" }
+ let(:buffer) { Orgmode::HtmlOutputBuffer.new(output, document)}
+
+ it 'has a document' do
+ expect(buffer.document).to eq document
+ end
+
+ it 'has empty options' do
+ expect(buffer.options).to be_empty
+ end
+ end
+
context 'when call with options' do
let(:options) { { option: 'value'} }
- let(:buffer) { Orgmode::HtmlOutputBuffer.new(output, options)}
+ let(:buffer) { Orgmode::HtmlOutputBuffer.new(output, nil, options)}
+
+ it 'has nil document' do
+ expect(buffer.document).to be_nil
+ end
+
it 'has options' do
expect(buffer.options).to eq options
end
@@ -64,7 +82,7 @@ module Orgmode
let(:mode) { :src }
context 'when Buffer options include skip_syntax_highlight = true' do
- let(:buffer) { Orgmode::HtmlOutputBuffer.new(output, { skip_syntax_highlight: true })}
+ let(:buffer) { Orgmode::HtmlOutputBuffer.new(output, nil, { skip_syntax_highlight: true })}
before(:each) do
allow(buffer).to receive(:block_lang).and_return('')
end
diff --git a/spec/org-ruby/line_regexp_spec.rb b/spec/org-ruby/line_regexp_spec.rb
index ac27134..c67e598 100644
--- a/spec/org-ruby/line_regexp_spec.rb
+++ b/spec/org-ruby/line_regexp_spec.rb
@@ -39,6 +39,49 @@ class DummyRegexp
end
end
+ describe '.footnote_definition' do
+ it { expect(regexp.footnote_definition).to match '[fn:label]' }
+ it 'must occur at the start of an unindented line' do
+ expect(regexp.footnote_definition).not_to match ' [fn:label]'
+ expect(regexp.footnote_definition).not_to match "\t[fn:label]"
+ end
+ it { expect(regexp.footnote_definition).to match '[fn:label] contents' }
+ it 'caputre :label' do
+ match = regexp.footnote_definition.match('[fn:la-be_l]')
+ expect(match[:label]).to eq 'la-be_l'
+ expect(match[:contents]).to eq ''
+ end
+ it 'capture :contents' do
+ match = regexp.footnote_definition.match('[fn:la_bel] con(ten)ts]' )
+ expect(match[:label]).to eq 'la_bel'
+ expect(match[:contents]).to eq ' con(ten)ts]'
+ end
+
+ end
+
+ describe '.footnote_reference' do
+ it { expect(regexp.footnote_reference).to match '[fn:label]' }
+ it { expect(regexp.footnote_reference).to match '[fn:99]' }
+ it { expect(regexp.footnote_reference).to match ' [fn:label:contents]' }
+ it { expect(regexp.footnote_reference).to match "\t[fn::contents]"}
+ it 'caputre :label' do
+ match = regexp.footnote_reference.match('[fn:la-be_l]')
+ expect(match[:label]).to eq 'la-be_l'
+ expect(match[:contents]).to eq ''
+ end
+ it 'capture :content' do
+ match = regexp.footnote_reference.match('[fn:la_bel:con(ten)ts]' )
+ expect(match[:label]).to eq 'la_bel'
+ expect(match[:contents]).to eq 'con(ten)ts'
+ end
+
+ it 'support anonymus footnotes' do
+ match = regexp.footnote_reference.match('[fn::contents]' )
+ expect(match[:label]).to eq ''
+ expect(match[:contents]).to eq 'contents'
+ end
+ end
+
describe '.headline' do
# should recognize headlines that start with asterisks
it { expect(regexp.headline).to match "* Headline" }
diff --git a/spec/org-ruby/regexp_helper_spec.rb b/spec/org-ruby/regexp_helper_spec.rb
index 0b3055d..9044c0c 100644
--- a/spec/org-ruby/regexp_helper_spec.rb
+++ b/spec/org-ruby/regexp_helper_spec.rb
@@ -7,5 +7,57 @@ module Orgmode
it 'has headline regexp helper' do
expect(helper.headline).to match "* Headline"
end
+
+ describe 'capture_footnote_definition' do
+ let(:helper) { RegexpHelper.new }
+ let(:footnote_text) { '[fn:label] Definition content' }
+
+ it 'capture footnote label and empty definition' do
+ helper.capture_footnote_definition("[fn:label]") do |label, content|
+ expect(label).to eq 'label'
+ expect(content).to eq ''
+ end
+ end
+
+ it 'caputre footnote with definition' do
+ helper.capture_footnote_definition(footnote_text) do |label, content|
+ expect(label).to eq 'label'
+ expect(content).to eq ' Definition content'
+ end
+ end
+
+ it 'replace line with an empty string' do
+ helper.capture_footnote_definition(footnote_text) do |label, content|
+ # do nothing
+ end
+ expect(footnote_text).to be_empty
+ end
+ end
+
+ describe 'rewrite_footnote references' do
+ let(:helper) { RegexpHelper.new }
+
+ it 'yields label and contents from footnote' do
+ helper.rewrite_footnote("[fn:label]") do |label, contents|
+ expect(label).to eq 'label'
+ expect(contents).to eq ''
+ end
+ helper.rewrite_footnote("[fn:label:contents]") do |label, contents|
+ expect(label).to eq 'label'
+ expect(contents).to eq 'contents'
+ end
+ helper.rewrite_footnote("[fn::contents]") do |label, contents|
+ expect(label).to eq ''
+ expect(contents).to eq 'contents'
+ end
+ end
+
+ example do
+ helper.rewrite_footnote("Other [fn:footnote:with content]") do |label, content|
+ expect(label).to eq 'footnote'
+ expect(content).to eq 'with content'
+ end
+ end
+ end
end
end
diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb
index 19277e2..987807d 100644
--- a/spec/parser_spec.rb
+++ b/spec/parser_spec.rb
@@ -332,19 +332,6 @@
end
end
- describe "Footnotes title" do
- base_dir = File.join(File.dirname(__FILE__), "html_examples")
- org_file = File.join(base_dir, "footnotes.org")
- html_file = File.join(base_dir, "footnotes_title.html")
- it 'accept footnotes_title option' do
- expected = IO.read(html_file)
- parser = Orgmode::Parser.new(IO.read(org_file), :footnotes_title => "Footnotes Title")
- actual = parser.to_html
- expect(actual).to be_kind_of(String)
- expect(actual).to eq(expected)
- end
- end
-
describe "Left to right support by" do
base_dir = File.join(File.dirname(__FILE__), "html_examples")
org_file = File.join(base_dir, "left-to-right.org")
diff --git a/spec/textile_examples/footnotes.textile b/spec/textile_examples/footnotes.textile
index aaaffe6..5c4978e 100644
--- a/spec/textile_examples/footnotes.textile
+++ b/spec/textile_examples/footnotes.textile
@@ -1,18 +1,18 @@
h2. Footnotes
-p. Using numbers [0]
+p. Using numbers [1]
-p. Using letters and not defined in the footnote [1]
+p. Using letters and not defined in the footnote [2]
-p. Using letters and defined in the footnote [1]
+p. Using letters and defined in the footnote [2]
-p. Defined in the footnote itself with markup [2]
+p. Defined in the footnote itself with markup [3]
-p. [0] Definition of first footnote
+p.
-fn0. DEFINITION NOT FOUND
+fn1. Definition of first footnote
-fn1. definition of abc
+fn2. definition of abc
-fn2. *blub*
+fn3. *blub*