Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bin/org-ruby
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ options_parser = OptionParser.new do |opts|
options[:debug] = true
end

opts.on("-i", "--heading-id", "Add id attribute to HTML headings") do |v|
options[:generate_heading_id] = true
end

opts.on("-m", "--markup <file>", "Set Custom Markup file") do |f|
options[:markup_file] = f
end
Expand All @@ -43,7 +47,10 @@ begin
puts options_parser
else
data = IO.read(ARGV[0])
p = Orgmode::Parser.new(data, (options[:markup_file] ? {:markup_file => options[:markup_file]} : {}))
parser_options = {}
parser_options.merge!(options[:markup_file] ? {:markup_file => options[:markup_file]} : {})
parser_options.merge!(options[:generate_heading_id] ? {:generate_heading_id => options[:generate_heading_id]} : {})
p = Orgmode::Parser.new(data, parser_options)
$DEBUG = true if options[:debug]
puts p.to_html if options[:format] == :html
puts p.to_textile if options[:format] == :textile
Expand Down
8 changes: 8 additions & 0 deletions lib/org-ruby/html_output_buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def initialize(output, opts = {})
@new_paragraph = :start
@footnotes = {}
@unclosed_tags = []
@heading_id = []
@logger.debug "HTML export options: #{@options.inspect}"
@custom_blocktags = {} if @options[:markup_file]

Expand Down Expand Up @@ -195,6 +196,13 @@ def flush!
end

def add_line_attributes headline
if @options[:generate_heading_id] then
level = headline.level
@output.delete_suffix!('>')
@heading_id.slice!(level, @heading_id.length - level)
@heading_id[level-1]=headline.output_text.downcase.gsub(/\W/, "-")
@output << " id=\"" + @heading_id.join("--") + "\">"
end
if @options[:export_heading_number] then
level = headline.level
heading_number = get_next_headline_number(level)
Expand Down
3 changes: 2 additions & 1 deletion lib/org-ruby/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ def to_html
:export_footnotes => export_footnotes?,
:link_abbrevs => @link_abbrevs,
:skip_syntax_highlight => @parser_options[:skip_syntax_highlight],
:markup_file => @parser_options[:markup_file]
:markup_file => @parser_options[:markup_file],
:generate_heading_id => @parser_options[:generate_heading_id]
}
export_options[:skip_tables] = true if not export_tables?
output = ""
Expand Down
11 changes: 11 additions & 0 deletions spec/html_output_buffer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spec_helper'

describe Orgmode::HtmlOutputBuffer do
it 'generates html headings ids' do
lines = "* Hello\n** World"
parser_options = {:generate_heading_id => true}
expected_output = "<h1 id=\"hello\">Hello</h1>\n<h2 id=\"hello--world\">World</h2>"
actual_output = Orgmode::Parser.new(lines, parser_options).to_html.strip
expect(actual_output).to eql(expected_output)
end
end