Skip to content

Commit

Permalink
Added support for exporting comments inside code blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdewey committed Dec 29, 2009
1 parent 6ceb3c1 commit 49ed71f
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 7 deletions.
3 changes: 2 additions & 1 deletion History.txt
@@ -1,6 +1,7 @@
== 0.4.1 / 2009-12-29

* HTML is now escaped by default.
* HTML is now escaped by default
* org-mode comments will show up in a code block.

== 0.4.0 / 2009-12-28

Expand Down
8 changes: 7 additions & 1 deletion lib/org-ruby/html_output_buffer.rb
Expand Up @@ -32,6 +32,7 @@ def initialize(output, opts = {})
def push_mode(mode)
if ModeTag[mode] then
output_indentation
@logger.debug "<#{ModeTag[mode]}>\n"
@output << "<#{ModeTag[mode]}>\n"
# Entering a new mode obliterates the title decoration
@title_decoration = ""
Expand All @@ -43,19 +44,24 @@ def pop_mode(mode = nil)
m = super(mode)
if ModeTag[m] then
output_indentation
@logger.debug "</#{ModeTag[m]}>\n"
@output << "</#{ModeTag[m]}>\n"
end
end

def flush!
@logger.debug "FLUSH ==========> #{@output_type}"
escape_buffer!
if current_mode == :code then
# Whitespace is significant in :code mode. Always output the buffer
# and do not do any additional translation.
#
# FIXME 2009-12-29 bdewey: It looks like I'll always get an extraneous
# newline at the start of code blocks. Find a way to fix this.
@logger.debug "FLUSH CODE ==========> #{@buffer.inspect}"
@output << @buffer << "\n"
else
if (@buffer.length > 0) then
@logger.debug "FLUSH ==========> #{@output_type}"
output_indentation
@output << "<#{HtmlBlockTag[@output_type]}#{@title_decoration}>" \
<< inline_formatting(@buffer) \
Expand Down
15 changes: 10 additions & 5 deletions lib/org-ruby/line.rb
Expand Up @@ -135,14 +135,19 @@ def self.translate(lines, output_buffer)
case line.paragraph_type
when :metadata, :table_separator, :blank

# IGNORE
output_buffer << line.line if output_buffer.preserve_whitespace?

when :comment

output_buffer.push_mode(:blockquote) if line.begin_block? and line.block_type == "QUOTE"
output_buffer.push_mode(:code) if line.begin_block? and line.block_type == "EXAMPLE"
output_buffer.pop_mode(:blockquote) if line.end_block? and line.block_type == "QUOTE"
output_buffer.pop_mode(:code) if line.end_block? and line.block_type == "EXAMPLE"
if line.begin_block?
output_buffer.push_mode(:blockquote) if line.block_type == "QUOTE"
output_buffer.push_mode(:code) if line.block_type == "EXAMPLE"
elsif line.end_block?
output_buffer.pop_mode(:blockquote) if line.block_type == "QUOTE"
output_buffer.pop_mode(:code) if line.block_type == "EXAMPLE"
else
output_buffer << line.line if output_buffer.preserve_whitespace?
end

when :table_row

Expand Down
19 changes: 19 additions & 0 deletions spec/html_examples/code-comment.html
@@ -0,0 +1,19 @@
<h1 class="title">Code Comment</h1>
<p>I need to be able to export things that look like org-mode comments inside of code blocks, like this:</p>
<pre>

#+TITLE: orgmode_parser.org
#+AUTHOR:
#+EMAIL: brian@BRIAN-DESK
#+DATE: 2009-12-29 Tue
#+DESCRIPTION:
#+KEYWORDS:
#+LANGUAGE: en
#+OPTIONS: H:3 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t &lt;:t
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+LINK_UP:
#+LINK_HOME:
</pre>
22 changes: 22 additions & 0 deletions spec/html_examples/code-comment.org
@@ -0,0 +1,22 @@
* Code Comment

I need to be able to export things that look like org-mode comments
inside of code blocks, like this:

#+BEGIN_EXAMPLE
#+TITLE: orgmode_parser.org
#+AUTHOR:
#+EMAIL: brian@BRIAN-DESK
#+DATE: 2009-12-29 Tue
#+DESCRIPTION:
#+KEYWORDS:
#+LANGUAGE: en
#+OPTIONS: H:3 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+LINK_UP:
#+LINK_HOME:
#+END_EXAMPLE

30 changes: 30 additions & 0 deletions spec/html_examples/metadata-comment.org-fail
@@ -0,0 +1,30 @@
* Metadata, etc.

I normally filter out things that look like metadata. Can't do it any
more. I need to see all of the following:

#+BEGIN_EXAMPLE
* DONE Handle inline formatting
CLOSED: [2009-12-26 Sat 21:41]
:PROPERTIES:
:ARCHIVE_TIME: 2009-12-26 Sat 22:16
:ARCHIVE_FILE: ~/brians-brain/content/projects/orgmode_parser.org
:ARCHIVE_OLPATH: <%= @page.title %>/Future Development
:ARCHIVE_CATEGORY: orgmode_parser
:ARCHIVE_TODO: DONE
:END:

I still need to handle:

- [ ] =Inline code=

How does the =emacs= HTML parser handle *inline* formatting? Ah,
it looks like it defines everything in =org-emphasis-alist= (line
2855 of =org.el=).

And then look at =org-emphasis-regexp-components=, line 2828 of
=org.el=. It looks like they just use a crazy regexp for inline
formatting. Which is good, because it means I can copy!


#+END_EXAMPLE

0 comments on commit 49ed71f

Please sign in to comment.