wallyqs-org-ruby 0.6.1 → 0.8.0
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.
- data/History.txt +41 -11
- data/README.rdoc +55 -50
- data/bin/org-ruby +11 -5
- data/lib/org-ruby.rb +20 -27
- data/lib/org-ruby/headline.rb +0 -10
- data/lib/org-ruby/html_output_buffer.rb +224 -143
- data/lib/org-ruby/html_symbol_replace.rb +359 -340
- data/lib/org-ruby/line.rb +91 -30
- data/lib/org-ruby/output_buffer.rb +147 -139
- data/lib/org-ruby/parser.rb +45 -111
- data/lib/org-ruby/regexp_helper.rb +52 -57
- data/lib/org-ruby/textile_output_buffer.rb +90 -37
- data/lib/org-ruby/textile_symbol_replace.rb +360 -341
- metadata +39 -200
- data/.bnsignore +0 -18
- data/.gitignore +0 -2
- data/Gemfile +0 -7
- data/Gemfile.lock +0 -36
- data/Rakefile +0 -33
- data/TAGS +0 -167
- data/announcement.txt +0 -24
- data/org-ruby.gemspec +0 -40
- data/spec/data/freeform-example.org +0 -113
- data/spec/data/freeform.org +0 -111
- data/spec/data/hyp-planning.org +0 -335
- data/spec/data/remember.org +0 -53
- data/spec/headline_spec.rb +0 -65
- data/spec/html_examples/advanced-code.html +0 -81
- data/spec/html_examples/advanced-code.org +0 -106
- data/spec/html_examples/advanced-lists.html +0 -31
- data/spec/html_examples/advanced-lists.org +0 -31
- data/spec/html_examples/block_code.html +0 -28
- data/spec/html_examples/block_code.org +0 -35
- data/spec/html_examples/blockcomment.html +0 -3
- data/spec/html_examples/blockcomment.org +0 -15
- data/spec/html_examples/blockquote.html +0 -7
- data/spec/html_examples/blockquote.org +0 -13
- data/spec/html_examples/center.html +0 -6
- data/spec/html_examples/center.org +0 -7
- data/spec/html_examples/code-comment.html +0 -18
- data/spec/html_examples/code-comment.org +0 -22
- data/spec/html_examples/code-syntax.html +0 -98
- data/spec/html_examples/code-syntax.org +0 -99
- data/spec/html_examples/comment-trees.html +0 -4
- data/spec/html_examples/comment-trees.org +0 -13
- data/spec/html_examples/custom-seq-todo.html +0 -15
- data/spec/html_examples/custom-seq-todo.org +0 -24
- data/spec/html_examples/custom-todo.html +0 -15
- data/spec/html_examples/custom-todo.org +0 -24
- data/spec/html_examples/custom-typ-todo.html +0 -15
- data/spec/html_examples/custom-typ-todo.org +0 -24
- data/spec/html_examples/deflist.html +0 -6
- data/spec/html_examples/deflist.org +0 -6
- data/spec/html_examples/entities.html +0 -4
- data/spec/html_examples/entities.org +0 -11
- data/spec/html_examples/escape-pre.html +0 -6
- data/spec/html_examples/escape-pre.org +0 -6
- data/spec/html_examples/export-exclude-only.html +0 -13
- data/spec/html_examples/export-exclude-only.org +0 -81
- data/spec/html_examples/export-keywords.html +0 -4
- data/spec/html_examples/export-keywords.org +0 -18
- data/spec/html_examples/export-tags.html +0 -8
- data/spec/html_examples/export-tags.org +0 -82
- data/spec/html_examples/export-title.html +0 -2
- data/spec/html_examples/export-title.org +0 -4
- data/spec/html_examples/footnotes.html +0 -10
- data/spec/html_examples/footnotes.org +0 -7
- data/spec/html_examples/html-literal.html +0 -2
- data/spec/html_examples/html-literal.org +0 -6
- data/spec/html_examples/inline-formatting.html +0 -20
- data/spec/html_examples/inline-formatting.org +0 -33
- data/spec/html_examples/inline-images.html +0 -10
- data/spec/html_examples/inline-images.org +0 -15
- data/spec/html_examples/link-features.html +0 -8
- data/spec/html_examples/link-features.org +0 -19
- data/spec/html_examples/lists.html +0 -23
- data/spec/html_examples/lists.org +0 -47
- data/spec/html_examples/metadata-comment.html +0 -27
- data/spec/html_examples/metadata-comment.org +0 -30
- data/spec/html_examples/only-list.html +0 -5
- data/spec/html_examples/only-list.org +0 -3
- data/spec/html_examples/only-table.html +0 -6
- data/spec/html_examples/only-table.org +0 -5
- data/spec/html_examples/skip-header.html +0 -3
- data/spec/html_examples/skip-header.org +0 -28
- data/spec/html_examples/skip-table.html +0 -4
- data/spec/html_examples/skip-table.org +0 -19
- data/spec/html_examples/subsupscript-nil.html +0 -3
- data/spec/html_examples/subsupscript-nil.org +0 -6
- data/spec/html_examples/subsupscript.html +0 -3
- data/spec/html_examples/subsupscript.org +0 -5
- data/spec/html_examples/tables.html +0 -35
- data/spec/html_examples/tables.org +0 -50
- data/spec/html_examples/text.html +0 -2
- data/spec/html_examples/text.org +0 -16
- data/spec/line_spec.rb +0 -155
- data/spec/output_buffer_spec.rb +0 -19
- data/spec/parser_spec.rb +0 -152
- data/spec/regexp_helper_spec.rb +0 -57
- data/spec/spec_helper.rb +0 -20
- data/spec/textile_examples/block_code.org +0 -35
- data/spec/textile_examples/block_code.textile +0 -29
- data/spec/textile_examples/blockquote.org +0 -13
- data/spec/textile_examples/blockquote.textile +0 -11
- data/spec/textile_examples/center.org +0 -7
- data/spec/textile_examples/center.textile +0 -6
- data/spec/textile_examples/footnotes.org +0 -7
- data/spec/textile_examples/footnotes.textile +0 -8
- data/spec/textile_examples/keywords.org +0 -13
- data/spec/textile_examples/keywords.textile +0 -11
- data/spec/textile_examples/links.org +0 -11
- data/spec/textile_examples/links.textile +0 -10
- data/spec/textile_examples/lists.org +0 -36
- data/spec/textile_examples/lists.textile +0 -20
- data/spec/textile_examples/single-space-plain-list.org +0 -13
- data/spec/textile_examples/single-space-plain-list.textile +0 -10
- data/spec/textile_examples/tables.org +0 -50
- data/spec/textile_examples/tables.textile +0 -40
- data/spec/textile_output_buffer_spec.rb +0 -21
- data/tasks/test_case.rake +0 -49
- data/test/test_orgmode_parser.rb +0 -0
- data/util/gen-special-replace.el +0 -37
data/History.txt
CHANGED
|
@@ -1,17 +1,47 @@
|
|
|
1
|
-
== 0.
|
|
1
|
+
== 0.8.0 / 2013-02-10
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
* A lot of refactoring work and bugfixes contributed by vonavi (many thanks!)
|
|
4
|
+
* Raw HTML is supported with #+html
|
|
5
|
+
* Code indentation for code blocks is fixed now
|
|
6
|
+
* Support for definition lists is improved
|
|
7
|
+
* Bugfix for when including headlines in center and quote blocks.
|
|
8
|
+
* Indentation of HTML output improved
|
|
9
|
+
* Improvements to entities support for Textile and HTML outputs
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
* Angle links in org-mode are embedded in anchor tags on html output
|
|
11
|
-
* Headlines with the COMMENT keyword, and the PROPERTIES drawer are not exported
|
|
11
|
+
== 0.7.2 / 2012-10-07
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
* Many fixes to the regular expressions used for emphasis, contributed by [[http://github.com/vonavi][vonavi]]
|
|
14
|
+
* Bug fix for when a table starts with a headline, thanks to [[http://github/til][til]]
|
|
15
|
+
* Asterisk can be used for definition lists too
|
|
16
|
+
* Use text lexer as default option for Pygments and Coderay when no language is specified
|
|
17
|
+
|
|
18
|
+
== 0.7.1 / 2012-08-04
|
|
19
|
+
|
|
20
|
+
* Make source code blocks from lisp dialects use Pygments scheme lexer
|
|
21
|
+
* Bugfix: Make Coderay fallback to text lexer when unsupported lang is set
|
|
22
|
+
|
|
23
|
+
== 0.7.0 / 2012-07-08
|
|
24
|
+
|
|
25
|
+
* Highlight source code blocks using Pygments or CodeRay when available
|
|
26
|
+
|
|
27
|
+
== 0.6.4 / 2012-07-08
|
|
28
|
+
|
|
29
|
+
* Fixed lists behavior when code fragments, tables and examples were present
|
|
30
|
+
* Remove code tags with lang class and use instead src-:lang like org-exporter
|
|
31
|
+
* Fixed property drawers to consider properties with hyphens like :noweb-ref:
|
|
32
|
+
|
|
33
|
+
== 0.6.3 / 2012-05-22
|
|
34
|
+
|
|
35
|
+
* Minor enhancement: Correct handling of .org URIs in HTML markup routine (thanks, rayl)
|
|
36
|
+
|
|
37
|
+
== 0.6.1 / 2012-04-14
|
|
38
|
+
|
|
39
|
+
* Added encoding directive to support Ruby 1.9.2
|
|
40
|
+
* Headlines with the COMMENT keyword, and the PROPERTIES drawer are not exported
|
|
41
|
+
* Angle links in org-mode are embedded in anchor tags on html output
|
|
42
|
+
* #+BEGIN/END_SRC lang code blocks are embedded in code tags with class that specifies the coding language
|
|
43
|
+
* Fixed bug in code blocks when a colon was at the beginning
|
|
44
|
+
* More than five dashes create an horizontal rule in html output
|
|
15
45
|
|
|
16
46
|
== 0.6.0 / 2011-09-03
|
|
17
47
|
|
data/README.rdoc
CHANGED
|
@@ -1,67 +1,72 @@
|
|
|
1
|
-
org-ruby
|
|
2
|
-
|
|
3
|
-
http://github.com/bdewey/org-ruby
|
|
1
|
+
= org-ruby
|
|
2
|
+
<em>Originally by Brian Dewey</em> (http://github.com/bdewey/org-ruby)
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
{<img src="https://secure.travis-ci.org/wallyqs/org-ruby.png?branch=master" alt="Build Status" />}[http://travis-ci.org/wallyqs/org-ruby]
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
conversion. The supplied textile conversion is optimized for
|
|
11
|
-
extracting "content" from the orgfile as opposed to "metadata."
|
|
6
|
+
An {org-mode}[http://orgmode.org] parser written in Ruby. The most significant thing this library does today is convert org-mode files to HTML or Textile.
|
|
7
|
+
Currently, you cannot do much to customize the conversion. The supplied textile conversion is optimized for extracting
|
|
8
|
+
“content” from the orgfile as opposed to “metadata.”
|
|
12
9
|
|
|
13
|
-
==
|
|
10
|
+
== Installation
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
* Supports tables, block quotes, and block code
|
|
17
|
-
* Supports bold, italic, underline, strikethrough, and code inline formatting.
|
|
18
|
-
* Supports hyperlinks that are in double-brackets
|
|
19
|
-
* Supports +.org+ views in Rails through Tilt.
|
|
20
|
-
* Upcoming: Handle export options specified in the org buffer.
|
|
21
|
-
|
|
22
|
-
== SYNOPSIS:
|
|
12
|
+
gem install org-ruby
|
|
23
13
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
org-ruby sample.org
|
|
27
|
-
|
|
28
|
-
...will output a HTML version of sample.org.
|
|
29
|
-
|
|
30
|
-
org-ruby --translate textile sample.org
|
|
31
|
-
|
|
32
|
-
...will output a textile version of sample.org.
|
|
14
|
+
== Usage
|
|
33
15
|
|
|
34
16
|
From Ruby code:
|
|
35
17
|
|
|
36
|
-
|
|
18
|
+
require 'org-ruby'
|
|
37
19
|
|
|
38
|
-
|
|
20
|
+
# Renders HTML
|
|
21
|
+
Orgmode::Parser.new("* Hello world!).to_html
|
|
22
|
+
# => "<h1>Hello world!</h1>\n"
|
|
39
23
|
|
|
40
|
-
|
|
24
|
+
# Renders Textile
|
|
25
|
+
Orgmode::Parser.new("* Hello world!).to_textile
|
|
26
|
+
# => "h1. Hello world!\n"
|
|
41
27
|
|
|
42
|
-
|
|
28
|
+
It can also be used from the command line:
|
|
43
29
|
|
|
44
|
-
|
|
30
|
+
org-ruby sample.org --translate html
|
|
45
31
|
|
|
46
|
-
|
|
32
|
+
...will output a HTML version of sample.org.
|
|
47
33
|
|
|
48
|
-
|
|
34
|
+
org-ruby --translate textile sample.org
|
|
49
35
|
|
|
50
|
-
|
|
51
|
-
a copy of this software and associated documentation files (the
|
|
52
|
-
'Software'), to deal in the Software without restriction, including
|
|
53
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
54
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
55
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
56
|
-
the following conditions:
|
|
36
|
+
...will output a textile version of sample.org.
|
|
57
37
|
|
|
58
|
-
|
|
59
|
-
included in all copies or substantial portions of the Software.
|
|
38
|
+
== Features
|
|
60
39
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
40
|
+
* Converts org-mode files to HTML or Textile
|
|
41
|
+
* Supports tables, block quotes, code blocks, and html blocks
|
|
42
|
+
* Supports bold, italic, underline, strikethrough, and code inline formatting.
|
|
43
|
+
* Supports hyperlinks that are in double-brackets
|
|
44
|
+
* Supports definition lists
|
|
45
|
+
* Supports footnotes
|
|
46
|
+
* Supports +.org+ views in Rails through Tilt.
|
|
47
|
+
* Code syntax highlight of code blocks using Pygments.rb or Coderay when available
|
|
48
|
+
|
|
49
|
+
== License
|
|
50
|
+
|
|
51
|
+
(The MIT License)
|
|
52
|
+
|
|
53
|
+
Copyright (c) 2009 Brian Dewey
|
|
54
|
+
|
|
55
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
56
|
+
a copy of this software and associated documentation files (the
|
|
57
|
+
'Software'), to deal in the Software without restriction, including
|
|
58
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
59
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
60
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
61
|
+
the following conditions:
|
|
62
|
+
|
|
63
|
+
The above copyright notice and this permission notice shall be
|
|
64
|
+
included in all copies or substantial portions of the Software.
|
|
65
|
+
|
|
66
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
67
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
68
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
69
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
70
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
71
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
72
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/org-ruby
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require File.expand_path(
|
|
4
|
-
File.join(File.dirname(__FILE__), %w[.. lib org-ruby]))
|
|
2
|
+
require 'org-ruby'
|
|
5
3
|
require 'optparse'
|
|
6
4
|
|
|
7
|
-
# Put your code here
|
|
8
|
-
|
|
9
5
|
options = {}
|
|
10
6
|
options_parser = OptionParser.new do |opts|
|
|
11
7
|
options[:help] = false
|
|
@@ -25,10 +21,20 @@ options_parser = OptionParser.new do |opts|
|
|
|
25
21
|
"Translate the ORG file to the specified format.") do |v|
|
|
26
22
|
options[:format] = v
|
|
27
23
|
end
|
|
24
|
+
|
|
25
|
+
opts.on("-v", "--version", "Print version") do |v|
|
|
26
|
+
options[:version] = true
|
|
27
|
+
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
begin
|
|
31
31
|
options_parser.parse!
|
|
32
|
+
|
|
33
|
+
if options[:version]
|
|
34
|
+
puts OrgRuby::VERSION
|
|
35
|
+
exit
|
|
36
|
+
end
|
|
37
|
+
|
|
32
38
|
if (ARGV.length == 0) then
|
|
33
39
|
puts options_parser
|
|
34
40
|
else
|
data/lib/org-ruby.rb
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
# internal requires
|
|
4
|
+
require 'org-ruby/parser'
|
|
5
|
+
require 'org-ruby/regexp_helper'
|
|
6
|
+
require 'org-ruby/line'
|
|
7
|
+
require 'org-ruby/headline'
|
|
8
|
+
require 'org-ruby/output_buffer'
|
|
9
|
+
|
|
10
|
+
# HTML exporter
|
|
11
|
+
require 'org-ruby/html_output_buffer'
|
|
12
|
+
require 'org-ruby/html_symbol_replace'
|
|
13
|
+
|
|
14
|
+
# Textile exporter
|
|
15
|
+
require 'org-ruby/textile_output_buffer'
|
|
16
|
+
require 'org-ruby/textile_symbol_replace'
|
|
17
|
+
|
|
18
|
+
# Tilt support
|
|
19
|
+
require 'org-ruby/tilt'
|
|
7
20
|
|
|
8
21
|
module OrgRuby
|
|
9
22
|
|
|
10
23
|
# :stopdoc:
|
|
11
|
-
VERSION = '0.
|
|
24
|
+
VERSION = '0.8.0'
|
|
12
25
|
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
|
13
26
|
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
|
14
27
|
# :startdoc:
|
|
@@ -19,22 +32,6 @@ module OrgRuby
|
|
|
19
32
|
VERSION
|
|
20
33
|
end
|
|
21
34
|
|
|
22
|
-
# Returns the library path for the module. If any arguments are given,
|
|
23
|
-
# they will be joined to the end of the libray path using
|
|
24
|
-
# <tt>File.join</tt>.
|
|
25
|
-
#
|
|
26
|
-
def self.libpath( *args )
|
|
27
|
-
args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Returns the lpath for the module. If any arguments are given,
|
|
31
|
-
# they will be joined to the end of the path using
|
|
32
|
-
# <tt>File.join</tt>.
|
|
33
|
-
#
|
|
34
|
-
def self.path( *args )
|
|
35
|
-
args.empty? ? PATH : ::File.join(PATH, args.flatten)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
35
|
# Utility method used to require all files ending in .rb that lie in the
|
|
39
36
|
# directory below this file that has the same name as the filename passed
|
|
40
37
|
# in. Optionally, a specific _directory_ name can be passed in such that
|
|
@@ -48,8 +45,4 @@ module OrgRuby
|
|
|
48
45
|
Dir.glob(search_me).sort.each {|rb| require rb}
|
|
49
46
|
end
|
|
50
47
|
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
OrgRuby.require_all_libs_relative_to(__FILE__)
|
|
54
|
-
|
|
55
|
-
end # unless defined?
|
|
48
|
+
end
|
data/lib/org-ruby/headline.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require OrgRuby.libpath(*%w[org-ruby line])
|
|
2
|
-
|
|
3
1
|
module Orgmode
|
|
4
2
|
|
|
5
3
|
# Represents a headline in an orgmode file.
|
|
@@ -47,7 +45,6 @@ module Orgmode
|
|
|
47
45
|
def initialize(line, parser = nil, offset=0)
|
|
48
46
|
super(line, parser)
|
|
49
47
|
@body_lines = []
|
|
50
|
-
@body_lines << self # Make @body_lines contain the headline?
|
|
51
48
|
@tags = []
|
|
52
49
|
@export_state = :exclude
|
|
53
50
|
if (@line =~ LineRegexp) then
|
|
@@ -87,13 +84,6 @@ module Orgmode
|
|
|
87
84
|
:"heading#{@level}"
|
|
88
85
|
end
|
|
89
86
|
|
|
90
|
-
# Converts this headline and its body to textile.
|
|
91
|
-
def to_textile
|
|
92
|
-
output = "h#{@level}. #{@headline_text}\n"
|
|
93
|
-
output << Line.to_textile(@body_lines[1..-1])
|
|
94
|
-
output
|
|
95
|
-
end
|
|
96
|
-
|
|
97
87
|
######################################################################
|
|
98
88
|
private
|
|
99
89
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
require OrgRuby.libpath(*%w[org-ruby html_symbol_replace])
|
|
2
|
-
require OrgRuby.libpath(*%w[org-ruby output_buffer])
|
|
3
|
-
|
|
4
1
|
begin
|
|
5
|
-
require '
|
|
2
|
+
require 'pygments'
|
|
6
3
|
rescue LoadError
|
|
7
|
-
#
|
|
4
|
+
# Pygments is not supported so we try instead with CodeRay
|
|
5
|
+
begin
|
|
6
|
+
require 'coderay'
|
|
7
|
+
rescue LoadError
|
|
8
|
+
# No code syntax highlighting
|
|
9
|
+
end
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
module Orgmode
|
|
@@ -13,12 +15,19 @@ module Orgmode
|
|
|
13
15
|
|
|
14
16
|
HtmlBlockTag = {
|
|
15
17
|
:paragraph => "p",
|
|
16
|
-
:ordered_list => "
|
|
17
|
-
:unordered_list => "
|
|
18
|
+
:ordered_list => "ol",
|
|
19
|
+
:unordered_list => "ul",
|
|
20
|
+
:list_item => "li",
|
|
21
|
+
:definition_list => "dl",
|
|
18
22
|
:definition_term => "dt",
|
|
19
23
|
:definition_descr => "dd",
|
|
24
|
+
:table => "table",
|
|
20
25
|
:table_row => "tr",
|
|
21
|
-
:
|
|
26
|
+
:quote => "blockquote",
|
|
27
|
+
:example => "pre",
|
|
28
|
+
:src => "pre",
|
|
29
|
+
:inline_example => "pre",
|
|
30
|
+
:center => "div",
|
|
22
31
|
:heading1 => "h1",
|
|
23
32
|
:heading2 => "h2",
|
|
24
33
|
:heading3 => "h3",
|
|
@@ -27,18 +36,6 @@ module Orgmode
|
|
|
27
36
|
:heading6 => "h6"
|
|
28
37
|
}
|
|
29
38
|
|
|
30
|
-
ModeTag = {
|
|
31
|
-
:unordered_list => "ul",
|
|
32
|
-
:ordered_list => "ol",
|
|
33
|
-
:definition_list => "dl",
|
|
34
|
-
:table => "table",
|
|
35
|
-
:blockquote => "blockquote",
|
|
36
|
-
:example => "pre",
|
|
37
|
-
:src => "pre",
|
|
38
|
-
:inline_example => "pre",
|
|
39
|
-
:center => "div"
|
|
40
|
-
}
|
|
41
|
-
|
|
42
39
|
attr_reader :options
|
|
43
40
|
|
|
44
41
|
def initialize(output, opts = {})
|
|
@@ -48,118 +45,160 @@ module Orgmode
|
|
|
48
45
|
else
|
|
49
46
|
@title_decoration = ""
|
|
50
47
|
end
|
|
48
|
+
@buffer_tag = "HTML"
|
|
51
49
|
@options = opts
|
|
50
|
+
@new_paragraph = :start
|
|
52
51
|
@footnotes = {}
|
|
52
|
+
@unclosed_tags = []
|
|
53
53
|
@logger.debug "HTML export options: #{@options.inspect}"
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
# Output buffer is entering a new mode. Use this opportunity to
|
|
57
|
-
# write out one of the block tags in the
|
|
58
|
-
# this information in the HTML stream.
|
|
59
|
-
def push_mode(mode)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
57
|
+
# write out one of the block tags in the HtmlBlockTag constant to
|
|
58
|
+
# put this information in the HTML stream.
|
|
59
|
+
def push_mode(mode, indent)
|
|
60
|
+
super(mode)
|
|
61
|
+
@list_indent_stack.push(indent)
|
|
62
|
+
|
|
63
|
+
if HtmlBlockTag[mode]
|
|
64
|
+
unless ((mode_is_table?(mode) and skip_tables?) or
|
|
65
|
+
(mode == :src and defined? Pygments))
|
|
66
|
+
css_class = case
|
|
67
|
+
when (mode == :src and @block_lang.empty?)
|
|
68
|
+
" class=\"src\""
|
|
69
|
+
when (mode == :src and not @block_lang.empty?)
|
|
70
|
+
" class=\"src src-#{@block_lang}\""
|
|
71
|
+
when (mode == :example || mode == :inline_example)
|
|
72
|
+
" class=\"example\""
|
|
73
|
+
when mode == :center
|
|
74
|
+
" style=\"text-align: center\""
|
|
75
|
+
else
|
|
76
|
+
@title_decoration
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
add_paragraph unless @new_paragraph == :start
|
|
80
|
+
@new_paragraph = true
|
|
81
|
+
|
|
82
|
+
@logger.debug "#{mode}: <#{HtmlBlockTag[mode]}#{css_class}>"
|
|
83
|
+
@output << "<#{HtmlBlockTag[mode]}#{css_class}>"
|
|
84
|
+
# Entering a new mode obliterates the title decoration
|
|
85
|
+
@title_decoration = ""
|
|
72
86
|
end
|
|
73
|
-
# Entering a new mode obliterates the title decoration
|
|
74
|
-
@title_decoration = ""
|
|
75
87
|
end
|
|
76
|
-
super(mode)
|
|
77
88
|
end
|
|
78
89
|
|
|
79
90
|
# We are leaving a mode. Close any tags that were opened when
|
|
80
91
|
# entering this mode.
|
|
81
92
|
def pop_mode(mode = nil)
|
|
82
93
|
m = super(mode)
|
|
83
|
-
if
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
@
|
|
87
|
-
@
|
|
94
|
+
if HtmlBlockTag[m]
|
|
95
|
+
unless ((mode_is_table?(m) and skip_tables?) or
|
|
96
|
+
(m == :src and defined? Pygments))
|
|
97
|
+
add_paragraph if @new_paragraph
|
|
98
|
+
@new_paragraph = true
|
|
99
|
+
@logger.debug "</#{HtmlBlockTag[m]}>"
|
|
100
|
+
@output << "</#{HtmlBlockTag[m]}>"
|
|
88
101
|
end
|
|
89
|
-
@logger.debug "</#{ModeTag[m]}>\n"
|
|
90
|
-
@output << "</#{ModeTag[m]}>\n" unless mode == :table and skip_tables?
|
|
91
102
|
end
|
|
103
|
+
@list_indent_stack.pop
|
|
92
104
|
end
|
|
93
105
|
|
|
94
106
|
def flush!
|
|
95
|
-
if
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if
|
|
99
|
-
@logger.debug "Applying syntax coloring for: #{@block_lang}"
|
|
107
|
+
return false if @buffer.empty?
|
|
108
|
+
case
|
|
109
|
+
when preserve_whitespace?
|
|
110
|
+
strip_code_block! if mode_is_code? current_mode
|
|
100
111
|
|
|
101
|
-
|
|
112
|
+
# NOTE: CodeRay and Pygments already escape the html once, so
|
|
113
|
+
# no need to escape_string!(@buffer)
|
|
114
|
+
case
|
|
115
|
+
when (current_mode == :src and defined? Pygments)
|
|
116
|
+
lang = normalize_lang @block_lang
|
|
117
|
+
@output << "\n" unless @new_paragraph == :start
|
|
118
|
+
|
|
119
|
+
begin
|
|
120
|
+
@buffer = Pygments.highlight(@buffer, :lexer => lang)
|
|
121
|
+
rescue
|
|
122
|
+
# Not supported lexer from Pygments, we fallback on using the text lexer
|
|
123
|
+
@buffer = Pygments.highlight(@buffer, :lexer => 'text')
|
|
124
|
+
end
|
|
125
|
+
when (current_mode == :src and defined? CodeRay)
|
|
126
|
+
lang = normalize_lang @block_lang
|
|
127
|
+
|
|
128
|
+
# CodeRay might throw a warning when unsupported lang is set,
|
|
129
|
+
# then fallback to using the text lexer
|
|
102
130
|
silence_warnings do
|
|
103
|
-
|
|
131
|
+
begin
|
|
132
|
+
@buffer = CodeRay.scan(@buffer, lang).html(:wrap => nil, :css => :style)
|
|
133
|
+
rescue ArgumentError
|
|
134
|
+
@buffer = CodeRay.scan(@buffer, 'text').html(:wrap => nil, :css => :style)
|
|
135
|
+
end
|
|
104
136
|
end
|
|
137
|
+
when (current_mode == :html or current_mode == :raw_text)
|
|
138
|
+
@buffer.gsub!(/\A\n/, "") if @new_paragraph == :start
|
|
139
|
+
@new_paragraph = true
|
|
105
140
|
else
|
|
106
|
-
|
|
141
|
+
escape_string! @buffer
|
|
107
142
|
end
|
|
108
143
|
|
|
109
|
-
# Whitespace is significant in :code mode. Always output the
|
|
110
|
-
# and do not do any additional translation.
|
|
144
|
+
# Whitespace is significant in :code mode. Always output the
|
|
145
|
+
# buffer and do not do any additional translation.
|
|
111
146
|
@logger.debug "FLUSH CODE ==========> #{@buffer.inspect}"
|
|
147
|
+
@output << @buffer
|
|
148
|
+
|
|
149
|
+
when (mode_is_table? current_mode and skip_tables?)
|
|
150
|
+
@logger.debug "SKIP ==========> #{current_mode}"
|
|
112
151
|
|
|
113
|
-
@output << @buffer << "\n"
|
|
114
152
|
else
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
else
|
|
126
|
-
@output << "\n"
|
|
127
|
-
end
|
|
128
|
-
@title_decoration = ""
|
|
129
|
-
end
|
|
130
|
-
elsif @buffer.length > 0 then
|
|
131
|
-
unless buffer_mode_is_table? and skip_tables?
|
|
132
|
-
@logger.debug "FLUSH ==========> #{@buffer_mode}"
|
|
133
|
-
output_indentation
|
|
134
|
-
@output << "<#{HtmlBlockTag[@output_type]}#{@title_decoration}>"
|
|
135
|
-
if (@buffered_lines[0].kind_of?(Headline)) then
|
|
136
|
-
headline = @buffered_lines[0]
|
|
137
|
-
raise "Cannot be more than one headline!" if @buffered_lines.length > 1
|
|
138
|
-
if @options[:export_heading_number] then
|
|
139
|
-
level = headline.level
|
|
140
|
-
heading_number = get_next_headline_number(level)
|
|
141
|
-
output << "<span class=\"heading-number heading-number-#{level}\">#{heading_number} </span>"
|
|
142
|
-
end
|
|
143
|
-
if @options[:export_todo] and headline.keyword then
|
|
144
|
-
keyword = headline.keyword
|
|
145
|
-
output << "<span class=\"todo-keyword #{keyword}\">#{keyword} </span>"
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
@output << inline_formatting(@buffer)
|
|
149
|
-
@output << "</#{HtmlBlockTag[@output_type]}>\n"
|
|
150
|
-
@title_decoration = ""
|
|
153
|
+
@buffer.lstrip!
|
|
154
|
+
@new_paragraph = nil
|
|
155
|
+
@logger.debug "FLUSH ==========> #{current_mode}"
|
|
156
|
+
|
|
157
|
+
case current_mode
|
|
158
|
+
when :definition_term
|
|
159
|
+
d = @buffer.split(/\A(.*[ \t]+|)::(|[ \t]+.*?)$/, 4)
|
|
160
|
+
d[1] = d[1].strip
|
|
161
|
+
unless d[1].empty?
|
|
162
|
+
@output << inline_formatting(d[1])
|
|
151
163
|
else
|
|
152
|
-
@
|
|
164
|
+
@output << "???"
|
|
153
165
|
end
|
|
166
|
+
indent = @list_indent_stack.last
|
|
167
|
+
pop_mode
|
|
168
|
+
|
|
169
|
+
@new_paragraph = :start
|
|
170
|
+
push_mode(:definition_descr, indent)
|
|
171
|
+
@output << inline_formatting(d[2].strip + d[3])
|
|
172
|
+
@new_paragraph = nil
|
|
173
|
+
|
|
174
|
+
when :horizontal_rule
|
|
175
|
+
add_paragraph unless @new_paragraph == :start
|
|
176
|
+
@new_paragraph = true
|
|
177
|
+
@output << "<hr />"
|
|
178
|
+
|
|
179
|
+
else
|
|
180
|
+
@output << inline_formatting(@buffer)
|
|
154
181
|
end
|
|
155
182
|
end
|
|
156
|
-
|
|
183
|
+
@buffer = ""
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def add_line_attributes headline
|
|
187
|
+
if @options[:export_heading_number] then
|
|
188
|
+
level = headline.level
|
|
189
|
+
heading_number = get_next_headline_number(level)
|
|
190
|
+
@output << "<span class=\"heading-number heading-number-#{level}\">#{heading_number}</span> "
|
|
191
|
+
end
|
|
192
|
+
if @options[:export_todo] and headline.keyword then
|
|
193
|
+
keyword = headline.keyword
|
|
194
|
+
@output << "<span class=\"todo-keyword #{keyword}\">#{keyword}</span> "
|
|
195
|
+
end
|
|
157
196
|
end
|
|
158
197
|
|
|
159
198
|
def output_footnotes!
|
|
160
199
|
return false unless @options[:export_footnotes] and not @footnotes.empty?
|
|
161
200
|
|
|
162
|
-
@output << "<div id=\"footnotes\">\n<h2 class=\"footnotes\">Footnotes
|
|
201
|
+
@output << "\n<div id=\"footnotes\">\n<h2 class=\"footnotes\">Footnotes:</h2>\n<div id=\"text-footnotes\">\n"
|
|
163
202
|
|
|
164
203
|
@footnotes.each do |name, defi|
|
|
165
204
|
@output << "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.#{name}\" href=\"#fnr.#{name}\">#{name}</a></sup>" \
|
|
@@ -167,11 +206,15 @@ module Orgmode
|
|
|
167
206
|
<< "</p>\n"
|
|
168
207
|
end
|
|
169
208
|
|
|
170
|
-
@output << "</div>\n</div
|
|
209
|
+
@output << "</div>\n</div>"
|
|
171
210
|
|
|
172
211
|
return true
|
|
173
212
|
end
|
|
174
213
|
|
|
214
|
+
# Test if we're in an output mode in which whitespace is significant.
|
|
215
|
+
def preserve_whitespace?
|
|
216
|
+
super or current_mode == :html
|
|
217
|
+
end
|
|
175
218
|
|
|
176
219
|
######################################################################
|
|
177
220
|
private
|
|
@@ -180,84 +223,116 @@ module Orgmode
|
|
|
180
223
|
@options[:skip_tables]
|
|
181
224
|
end
|
|
182
225
|
|
|
183
|
-
def
|
|
184
|
-
|
|
226
|
+
def mode_is_table?(mode)
|
|
227
|
+
(mode == :table or mode == :table_row or
|
|
228
|
+
mode == :table_separator or mode == :table_header)
|
|
185
229
|
end
|
|
186
230
|
|
|
187
231
|
# Escapes any HTML content in the output accumulation buffer @buffer.
|
|
188
|
-
def
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
232
|
+
def escape_string! str
|
|
233
|
+
str.gsub!(/&/, "&")
|
|
234
|
+
# Escapes the left and right angular brackets but construction
|
|
235
|
+
# @<text> which is formatted to <text>
|
|
236
|
+
str.gsub! /<([^<>\n]*)/ do |match|
|
|
237
|
+
if $`[-1..-1] == "@" and $'[0..0] == ">" then $&
|
|
238
|
+
else "<#{$1}"
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
str.gsub! /([^<>\n]*)>/ do |match|
|
|
242
|
+
if $`[-2..-1] == "@<" then $&
|
|
243
|
+
else "#{$1}>"
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
str.gsub!(/@(<[^<>\n]*>)/, "\\1")
|
|
192
247
|
end
|
|
193
248
|
|
|
194
|
-
def
|
|
195
|
-
indent = " " *
|
|
196
|
-
@
|
|
249
|
+
def buffer_indentation
|
|
250
|
+
indent = " " * @list_indent_stack.length
|
|
251
|
+
@buffer << indent
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def add_paragraph
|
|
255
|
+
indent = " " * (@list_indent_stack.length - 1)
|
|
256
|
+
@output << "\n" << indent
|
|
197
257
|
end
|
|
198
258
|
|
|
199
259
|
Tags = {
|
|
200
|
-
"*" => { :open => "
|
|
201
|
-
"/" => { :open => "
|
|
202
|
-
"_" => { :open => "
|
|
203
|
-
:close => "
|
|
204
|
-
"=" => { :open => "
|
|
205
|
-
"~" => { :open => "
|
|
206
|
-
"+" => { :open => "
|
|
260
|
+
"*" => { :open => "b", :close => "b" },
|
|
261
|
+
"/" => { :open => "i", :close => "i" },
|
|
262
|
+
"_" => { :open => "span style=\"text-decoration:underline;\"",
|
|
263
|
+
:close => "span" },
|
|
264
|
+
"=" => { :open => "code", :close => "code" },
|
|
265
|
+
"~" => { :open => "code", :close => "code" },
|
|
266
|
+
"+" => { :open => "del", :close => "del" }
|
|
207
267
|
}
|
|
208
268
|
|
|
209
269
|
# Applies inline formatting rules to a string.
|
|
210
270
|
def inline_formatting(str)
|
|
211
|
-
str
|
|
212
|
-
|
|
213
|
-
"#{Tags[marker][:open]}#{s}#{Tags[marker][:close]}"
|
|
271
|
+
@re_help.rewrite_emphasis str do |marker, s|
|
|
272
|
+
"@<#{Tags[marker][:open]}>#{s}@</#{Tags[marker][:close]}>"
|
|
214
273
|
end
|
|
215
274
|
if @options[:use_sub_superscripts] then
|
|
216
|
-
|
|
275
|
+
@re_help.rewrite_subp str do |type, text|
|
|
217
276
|
if type == "_" then
|
|
218
|
-
"
|
|
277
|
+
"@<sub>#{text}@</sub>"
|
|
219
278
|
elsif type == "^" then
|
|
220
|
-
"
|
|
279
|
+
"@<sup>#{text}@</sup>"
|
|
221
280
|
end
|
|
222
281
|
end
|
|
223
282
|
end
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
end
|
|
227
|
-
str = @re_help.rewrite_links(str) do |link, text|
|
|
228
|
-
text ||= link
|
|
229
|
-
link = link.sub(/^file:(.*)::(.*?)$/) do
|
|
230
|
-
|
|
283
|
+
@re_help.rewrite_links str do |link, defi|
|
|
284
|
+
[link, defi].compact.each do |text|
|
|
231
285
|
# We don't support search links right now. Get rid of it.
|
|
286
|
+
text.sub!(/\A(file:[^\s]+)::[^\s]*?\Z/, "\\1")
|
|
287
|
+
text.sub!(/\A(file:[^\s]+)\.org\Z/i, "\\1.html")
|
|
288
|
+
text.sub!(/\Afile:(?=[^\s]+\Z)/, "")
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
# We don't add a description for images in links, because its
|
|
292
|
+
# empty value forces the image to be inlined.
|
|
293
|
+
defi ||= link unless link =~ @re_help.org_image_file_regexp
|
|
232
294
|
|
|
233
|
-
|
|
295
|
+
if defi =~ @re_help.org_image_file_regexp
|
|
296
|
+
defi = "@<img src=\"#{defi}\" alt=\"#{defi}\" />"
|
|
234
297
|
end
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
298
|
+
|
|
299
|
+
if defi
|
|
300
|
+
"@<a href=\"#{link}\">#{defi}@</a>"
|
|
301
|
+
else
|
|
302
|
+
"@<img src=\"#{link}\" alt=\"#{link}\" />"
|
|
239
303
|
end
|
|
240
|
-
"<a href=\"#{link}\">#{text}</a>"
|
|
241
304
|
end
|
|
242
|
-
if
|
|
243
|
-
str.gsub!(/^\|\s*/, "
|
|
244
|
-
str.gsub!(/\s*\|$/, "
|
|
245
|
-
str.gsub!(/\s*\|\s*/, "
|
|
305
|
+
if @output_type == :table_row
|
|
306
|
+
str.gsub!(/^\|\s*/, "@<td>")
|
|
307
|
+
str.gsub!(/\s*\|$/, "@</td>")
|
|
308
|
+
str.gsub!(/\s*\|\s*/, "@</td>@<td>")
|
|
246
309
|
end
|
|
247
|
-
if
|
|
248
|
-
str.gsub!(/^\|\s*/, "
|
|
249
|
-
str.gsub!(/\s*\|$/, "
|
|
250
|
-
str.gsub!(/\s*\|\s*/, "
|
|
310
|
+
if @output_type == :table_header
|
|
311
|
+
str.gsub!(/^\|\s*/, "@<th>")
|
|
312
|
+
str.gsub!(/\s*\|$/, "@</th>")
|
|
313
|
+
str.gsub!(/\s*\|\s*/, "@</th>@<th>")
|
|
251
314
|
end
|
|
252
315
|
if @options[:export_footnotes] then
|
|
253
|
-
|
|
316
|
+
@re_help.rewrite_footnote str do |name, defi|
|
|
254
317
|
# TODO escape name for url?
|
|
255
318
|
@footnotes[name] = defi if defi
|
|
256
|
-
"
|
|
319
|
+
"@<sup>@<a class=\"footref\" name=\"fnr.#{name}\" href=\"#fn.#{name}\">#{name}@</a>@</sup>"
|
|
257
320
|
end
|
|
258
321
|
end
|
|
259
|
-
|
|
260
|
-
str
|
|
322
|
+
escape_string! str
|
|
323
|
+
Orgmode.special_symbols_to_html str
|
|
324
|
+
str = @re_help.restore_code_snippets str
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
def normalize_lang(lang)
|
|
328
|
+
case lang
|
|
329
|
+
when 'emacs-lisp', 'common-lisp', 'lisp'
|
|
330
|
+
'scheme'
|
|
331
|
+
when ''
|
|
332
|
+
'text'
|
|
333
|
+
else
|
|
334
|
+
lang
|
|
335
|
+
end
|
|
261
336
|
end
|
|
262
337
|
|
|
263
338
|
# Helper method taken from Rails
|
|
@@ -269,5 +344,11 @@ module Orgmode
|
|
|
269
344
|
ensure
|
|
270
345
|
$VERBOSE = warn_level
|
|
271
346
|
end
|
|
347
|
+
|
|
348
|
+
def strip_code_block!
|
|
349
|
+
strip_regexp = Regexp.new("^" + " " * @code_block_indent)
|
|
350
|
+
@buffer.gsub!(strip_regexp, "")
|
|
351
|
+
@code_block_indent = nil
|
|
352
|
+
end
|
|
272
353
|
end # class HtmlOutputBuffer
|
|
273
354
|
end # module Orgmode
|