org-ruby 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,10 @@
1
- == 0.5.0 / 2009-12-29
1
+ == 0.5.1 / 2009-12-30
2
+
3
+ * Minor enhancement: Recognize lines starting with ":" as examples.
4
+ * Minor enhancement: Recognize #+BEGIN_SRC as source blocks
5
+ * Minor enhancement: Add "src" and "example" classes to <pre> blocks.
6
+
7
+ == 0.5.0 / 2009-12-30
2
8
 
3
9
  * Parse (but not necessarily *use*) in-buffer settings. The following
4
10
  in-buffer settings *are* used:
data/lib/org-ruby.rb CHANGED
@@ -3,7 +3,7 @@ unless defined? ::OrgRuby
3
3
  module OrgRuby
4
4
 
5
5
  # :stopdoc:
6
- VERSION = '0.5.0'
6
+ VERSION = '0.5.1'
7
7
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
8
8
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
9
9
  # :startdoc:
@@ -17,7 +17,9 @@ module Orgmode
17
17
  :ordered_list => "ol",
18
18
  :table => "table",
19
19
  :blockquote => "blockquote",
20
- :code => "pre"
20
+ :example => "pre",
21
+ :src => "pre",
22
+ :inline_example => "pre"
21
23
  }
22
24
 
23
25
  attr_reader :options
@@ -33,17 +35,25 @@ module Orgmode
33
35
  @logger.debug "HTML export options: #{@options.inspect}"
34
36
  end
35
37
 
38
+ # Output buffer is entering a new mode. Use this opportunity to
39
+ # write out one of the block tags in the ModeTag constant to put
40
+ # this information in the HTML stream.
36
41
  def push_mode(mode)
37
42
  if ModeTag[mode] then
38
43
  output_indentation
39
- @logger.debug "<#{ModeTag[mode]}>\n"
40
- @output << "<#{ModeTag[mode]}>\n" unless mode == :table and skip_tables?
44
+ css_class = ""
45
+ css_class = " class=\"src\"" if mode == :src
46
+ css_class = " class=\"example\"" if (mode == :example || mode == :inline_example)
47
+ @logger.debug "#{mode}: <#{ModeTag[mode]}#{css_class}>\n"
48
+ @output << "<#{ModeTag[mode]}#{css_class}>\n" unless mode == :table and skip_tables?
41
49
  # Entering a new mode obliterates the title decoration
42
50
  @title_decoration = ""
43
51
  end
44
52
  super(mode)
45
53
  end
46
54
 
55
+ # We are leaving a mode. Close any tags that were opened when
56
+ # entering this mode.
47
57
  def pop_mode(mode = nil)
48
58
  m = super(mode)
49
59
  if ModeTag[m] then
@@ -55,12 +65,9 @@ module Orgmode
55
65
 
56
66
  def flush!
57
67
  escape_buffer!
58
- if @buffer_mode == :code then
68
+ if mode_is_code(@buffer_mode) then
59
69
  # Whitespace is significant in :code mode. Always output the buffer
60
70
  # and do not do any additional translation.
61
- #
62
- # FIXME 2009-12-29 bdewey: It looks like I'll always get an extraneous
63
- # newline at the start of code blocks. Find a way to fix this.
64
71
  @logger.debug "FLUSH CODE ==========> #{@buffer.inspect}"
65
72
  @output << @buffer << "\n"
66
73
  else
data/lib/org-ruby/line.rb CHANGED
@@ -117,6 +117,18 @@ module Orgmode
117
117
  $2 if @line =~ BlockRegexp
118
118
  end
119
119
 
120
+ def code_block_type?
121
+ block_type =~ /^(EXAMPLE|SRC)$/
122
+ end
123
+
124
+ InlineExampleRegexp = /^\s*:/
125
+
126
+ # Test if the line matches the "inline example" case:
127
+ # the first character on the line is a colon.
128
+ def inline_example?
129
+ check_assignment_or_regexp(:inline_example, InlineExampleRegexp)
130
+ end
131
+
120
132
  InBufferSettingRegexp = /^#\+(\w+):\s*(.*)$/
121
133
 
122
134
  # call-seq:
@@ -148,6 +160,7 @@ module Orgmode
148
160
  return :table_separator if table_separator?
149
161
  return :table_row if table_row?
150
162
  return :table_header if table_header?
163
+ return :inline_example if inline_example?
151
164
  return :paragraph
152
165
  end
153
166
 
@@ -180,10 +193,12 @@ module Orgmode
180
193
 
181
194
  if line.begin_block?
182
195
  output_buffer.push_mode(:blockquote) if line.block_type == "QUOTE"
183
- output_buffer.push_mode(:code) if line.block_type == "EXAMPLE"
196
+ output_buffer.push_mode(:src) if line.block_type == "SRC"
197
+ output_buffer.push_mode(:example) if line.block_type == "EXAMPLE"
184
198
  elsif line.end_block?
185
199
  output_buffer.pop_mode(:blockquote) if line.block_type == "QUOTE"
186
- output_buffer.pop_mode(:code) if line.block_type == "EXAMPLE"
200
+ output_buffer.pop_mode(:src) if line.block_type == "SRC"
201
+ output_buffer.pop_mode(:example) if line.block_type == "EXAMPLE"
187
202
  else
188
203
  output_buffer << line.line if output_buffer.preserve_whitespace?
189
204
  end
@@ -200,6 +215,10 @@ module Orgmode
200
215
 
201
216
  output_buffer << line.strip_unordered_list_tag << " "
202
217
 
218
+ when :inline_example
219
+
220
+ output_buffer << line.line.sub(InlineExampleRegexp, "")
221
+
203
222
  when :paragraph
204
223
 
205
224
  if output_buffer.preserve_whitespace? then
@@ -45,7 +45,7 @@ module Orgmode
45
45
  push_mode(:normal)
46
46
  end
47
47
 
48
- Modes = [:normal, :ordered_list, :unordered_list, :blockquote, :code, :table]
48
+ Modes = [:normal, :ordered_list, :unordered_list, :blockquote, :src, :example, :table, :inline_example]
49
49
 
50
50
  def current_mode
51
51
  @mode_stack.last
@@ -75,6 +75,8 @@ module Orgmode
75
75
  maintain_list_indent_stack(line)
76
76
  @output_type = line.paragraph_type
77
77
  end
78
+ push_mode(:inline_example) if line.inline_example? and current_mode != :inline_example
79
+ pop_mode(:inline_example) if current_mode == :inline_example && !line.inline_example?
78
80
  push_mode(:table) if enter_table?
79
81
  pop_mode(:table) if exit_table?
80
82
  end
@@ -108,17 +110,19 @@ module Orgmode
108
110
 
109
111
  # Test if we're in an output mode in which whitespace is significant.
110
112
  def preserve_whitespace?
111
- return current_mode == :code
113
+ mode_is_code current_mode
112
114
  end
113
115
 
114
116
  ######################################################################
115
117
  private
116
118
 
117
- # call-seq:
118
- # continue_current_list? => boolean
119
- #
120
- # Tests if the line should continue the current list.
121
- def continue_current_list?(line)
119
+ def mode_is_code(mode)
120
+ case mode
121
+ when :src, :inline_example, :example
122
+ true
123
+ else
124
+ false
125
+ end
122
126
  end
123
127
 
124
128
  def maintain_list_indent_stack(line)
@@ -11,12 +11,12 @@ module Orgmode
11
11
 
12
12
  def push_mode(mode)
13
13
  super(mode)
14
- @output << "bc.. " if mode == :code
14
+ @output << "bc.. " if mode_is_code(mode)
15
15
  end
16
16
 
17
17
  def pop_mode(mode = nil)
18
18
  m = super(mode)
19
- @add_paragraph = (m == :code)
19
+ @add_paragraph = (mode_is_code(m))
20
20
  m
21
21
  end
22
22
 
@@ -0,0 +1,36 @@
1
+ <p class="title">advanced-code.org</p>
2
+ <p>Turns out there&#8217;s more way to do code than just BEGIN_EXAMPLE.</p>
3
+ <h1><span class="heading-number heading-number-1">1 </span>Inline examples</h1>
4
+ <p>This should work:</p>
5
+ <pre class="example">
6
+ fixed width? how does this work?
7
+ ...........
8
+ ............
9
+ .
10
+ . . . .
11
+ . ..
12
+ ....... .....
13
+ . .
14
+ ....
15
+ </pre>
16
+ <p>Two ASCII blobs.</p>
17
+ <h1><span class="heading-number heading-number-1">2 </span>BEGIN_SRC</h1>
18
+ <pre class="example">
19
+ PROPERTIES:
20
+ ARCHIVE_TIME: 2009-12-26 Sat 22:16
21
+ ARCHIVE_FILE: ~/brians-brain/content/projects/orgmode_parser.org
22
+ ARCHIVE_OLPATH: &amp;lt;%= @page.title %&amp;gt;/Future Development
23
+ ARCHIVE_CATEGORY: orgmode_parser
24
+ ARCHIVE_TODO: DONE
25
+ END:
26
+ </pre>
27
+ <p>And this:</p>
28
+ <pre class="src">
29
+ # Finds all emphasis matches in a string.
30
+ # Supply a block that will get the marker and body as parameters.
31
+ def match_all(str)
32
+ str.scan(@org_emphasis_regexp) do |match|
33
+ yield $2, $3
34
+ end
35
+ end
36
+ </pre>
@@ -0,0 +1,53 @@
1
+ #+TITLE: advanced-code.org
2
+ #+AUTHOR: Brian Dewey
3
+ #+EMAIL: bdewey@gmail.com
4
+ #+DATE: 2009-12-30 Wed
5
+ #+DESCRIPTION: More types of code support
6
+ #+KEYWORDS:
7
+ #+LANGUAGE: en
8
+ #+OPTIONS: H:3 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
9
+ #+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
10
+ #+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
11
+ #+EXPORT_SELECT_TAGS: export
12
+ #+EXPORT_EXCLUDE_TAGS: noexport
13
+ #+LINK_UP:
14
+ #+LINK_HOME:
15
+
16
+ Turns out there's more way to do code than just BEGIN_EXAMPLE.
17
+
18
+ * Inline examples
19
+
20
+ This should work:
21
+
22
+ : fixed width? how does this work?
23
+ : ...........
24
+ : ............
25
+ : .
26
+ : . . . .
27
+ : . ..
28
+ : ....... .....
29
+ : . .
30
+ : ....
31
+
32
+ Two ASCII blobs.
33
+
34
+ * BEGIN_SRC
35
+ :PROPERTIES:
36
+ :ARCHIVE_TIME: 2009-12-26 Sat 22:16
37
+ :ARCHIVE_FILE: ~/brians-brain/content/projects/orgmode_parser.org
38
+ :ARCHIVE_OLPATH: &lt;%= @page.title %&gt;/Future Development
39
+ :ARCHIVE_CATEGORY: orgmode_parser
40
+ :ARCHIVE_TODO: DONE
41
+ :END:
42
+
43
+ And this:
44
+
45
+ #+BEGIN_SRC ruby
46
+ # Finds all emphasis matches in a string.
47
+ # Supply a block that will get the marker and body as parameters.
48
+ def match_all(str)
49
+ str.scan(@org_emphasis_regexp) do |match|
50
+ yield $2, $3
51
+ end
52
+ end
53
+ #+END_SRC
@@ -1,6 +1,6 @@
1
1
  <h1 class="title">Block Code</h1>
2
2
  <p>I need to get block code examples working. In <code>orgmode</code>, they look like this:</p>
3
- <pre>
3
+ <pre class="example">
4
4
 
5
5
  def initialize(output)
6
6
  @output = output
@@ -17,7 +17,7 @@
17
17
  <p>And now I should be back to normal text.</p>
18
18
  <p>Putting in another paragraph for good measure.</p>
19
19
  <p>Code should also get cancelled by a list, thus:</p>
20
- <pre>
20
+ <pre class="example">
21
21
  This is my code!
22
22
 
23
23
  Another line!
@@ -1,6 +1,6 @@
1
1
  <h1 class="title">Code Comment</h1>
2
2
  <p>I need to be able to export things that look like org-mode comments inside of code blocks, like this:</p>
3
- <pre>
3
+ <pre class="example">
4
4
  #+TITLE: orgmode_parser.org
5
5
  #+AUTHOR:
6
6
  #+EMAIL: brian@BRIAN-DESK
@@ -1,4 +1,4 @@
1
- <pre>
1
+ <pre class="example">
2
2
  &lt;li&gt;[ ] &amp;#8220;smart quotes&amp;#8221;&lt;/li&gt;
3
3
  &lt;li&gt;[ ] I think I need this for &amp;#8216;single quotes&amp;#8217; too. Don&amp;#8217;t I?&lt;/li&gt;
4
4
  &lt;li&gt;[ ] Em dashes would be great &amp;#8212; wouldn&amp;#8217;t they?&lt;/li&gt;
@@ -1,6 +1,6 @@
1
1
  <h1 class="title">Metadata, etc.</h1>
2
2
  <p>I normally filter out things that look like metadata. Can&#8217;t do it any more. I need to see all of the following:</p>
3
- <pre>
3
+ <pre class="example">
4
4
  * DONE Handle inline formatting
5
5
  CLOSED: [2009-12-26 Sat 21:41]
6
6
  :PROPERTIES:
data/spec/line_spec.rb CHANGED
@@ -24,6 +24,13 @@ describe Orgmode::Line do
24
24
  end
25
25
  end
26
26
 
27
+ [": inline", " :inline", "\t\t:\tinline"].each do |inline_example|
28
+ it "should recognize this inline example: #{inline_example}" do
29
+ Orgmode::Line.new(inline_example).inline_example?.should be_true
30
+ end
31
+ end
32
+
33
+
27
34
  it "should recognize plain lists" do
28
35
  list_formats = ["-",
29
36
  "+",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: org-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Dewey
@@ -65,6 +65,8 @@ files:
65
65
  - spec/data/hyp-planning.org
66
66
  - spec/data/remember.org
67
67
  - spec/headline_spec.rb
68
+ - spec/html_examples/advanced-code.html
69
+ - spec/html_examples/advanced-code.org
68
70
  - spec/html_examples/advanced-lists.html
69
71
  - spec/html_examples/advanced-lists.org
70
72
  - spec/html_examples/block_code.html