| Class | Orgmode::RegexpHelper |
| In: |
lib/org-ruby/regexp_helper.rb
|
| Parent: | Object |
This class contains helper routines to deal with the Regexp "black magic" you need to properly parse org-mode files.
| org_image_file_regexp | [R] |
EMPHASIS
I figure it‘s best to stick as closely to the elisp implementation as possible for emphasis. org.el defines the regular expression that is used to apply "emphasis" (in my terminology, inline formatting instead of block formatting). Here‘s the documentation from org.el. Terminology: In an emphasis string like " *strong word* ", we call the initial space PREMATCH, the final space POSTMATCH, the stars MARKERS, "s" and "d" are BORDER characters and "trong wor" is the body. The different components in this variable specify what is allowed/forbidden in each part: pre Chars allowed as prematch. Line beginning allowed, too. post Chars allowed as postmatch. Line end will be allowed too. border The chars forbidden as border characters. body-regexp A regexp like \".\" to match a body character. Don‘t use
non-shy groups here, and don't allow newline here.
newline The maximum number of newlines allowed in an emphasis exp. |
Finds all emphasis matches in a string. Supply a block that will get the marker and body as parameters.
Compute replacements for all matching emphasized phrases. Supply a block that will get the marker and body as parameters; return the replacement string from your block.
re = RegexpHelper.new
result = re.rewrite_emphasis("*bold*, /italic/, =code=") do |marker, body|
"<#{map[marker]}>#{body}</#{map[marker]}>"
end
In this example, the block body will get called three times:
The return from this block is a string that will be used to replace "bold", "/italic/", and "=code=", respectively. (Clearly this sample string will use HTML-like syntax, assuming map is defined appropriately.)
Rewrite org-mode links in a string to markup suitable to the output format.
Give this a block that expect the link and optional friendly text. Return how that link should get formatted.
re = RegexpHelper.new
result = re.rewrite_links("[[http://www.bing.com]] and [[http://www.hotmail.com][Hotmail]]") do |link, text}
text ||= link
"<a href=\"#{link}\">#{text}</a>"
end
In this example, the block body will get called two times. In the first instance, text will be nil (the org-mode markup gives no friendly text for the link +www.bing.com+. In the second instance, the block will get text of Hotmail and the link +www.hotmail.com+. In both cases, the block returns an HTML-style link, and that is how things will get recorded in result.