Class: TracWiki::Parser
- Inherits:
-
Object
- Object
- TracWiki::Parser
- Defined in:
- lib/trac-wiki/parser.rb
Constant Summary collapse
- MACRO_BEG_REX =
macro {$var} | TracWiki::Parser.{{#comment} | {!cmd} | {template} | {/template} string begins with macro
/\A\{\{ ( \$[#\$\.\w]+ | [\#!\/]\w* |\w+ ) /x
- MACRO_BEG_INSIDE_REX =
/\A(.*?) (?<!\{|!|!\{) \{\{ ( \$[#\$\.\w]+ | [\#!\/]\w* | \w+ ) /xm
- MACRO_END_REX =
find end of marcro or begin of inner macro
/\A(.*?) ( \}\} | \{\{ ( \$[#\$\.\w]+ | [\#!\/]\w* | \w+) )/mx
Instance Attribute Summary collapse
-
#allow_html ⇒ Object
writeonly
allow some <b> <form> <html> html will be sanitized.
-
#allowed_schemes ⇒ Object
Allowed url schemes Examples: http https ftp ftps.
-
#at_callback ⇒ Object
Proc or nil at_callback.call(env, key) -> computed value.
-
#base ⇒ Object
writeonly
url base for links.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#div_around_table ⇒ Object
writeonly
Enable <div> around <table>.
-
#edit_heading ⇒ Object
writeonly
add ‘<a class=’editheading’ href=“?edit=N>edit</a>‘ to each heading.
-
#env ⇒ Object
Returns the value of attribute env.
-
#headings ⇒ Object
structure where headings are stroed list of hasheses with ‘level` and `title`, `sline` [ { leven: 1, # <h1> sline: 3, # line where head starts eline: 4, # line before next heading starts aname: ’anchor-to-this-heading’, title: ‘heading title’ }, … ].
-
#id_from_heading ⇒ Object
writeonly
every heading had id, generated from heading text.
-
#id_translit ⇒ Object
writeonly
when id_from_heading, non ascii char are transliterated to ascii.
-
#macro_commands ⇒ Object
like template but more powerfull do no use.
-
#macros ⇒ Object
writeonly
use macros? defalut yes.
-
#math ⇒ Object
writeonly
math syntax extension: $e^x$ for inline math $$ e^x $$ for display math.
-
#merge ⇒ Object
writeonly
understand merge tags (see diff3(1)) >>>>>>> mine ||||||| orig ======= <<<<<<< yours convert to <div class=“merge merge-mine”>mine</div>.
-
#no_escape ⇒ Object
writeonly
Disable url escaping for local links Escaping: [[/Test]] –> %2FTest No escaping: [[/Test]] –> Test.
-
#no_link ⇒ Object
writeonly
Disable url escaping for local links [[whatwerver]] stays [[whatwerver]].
-
#root ⇒ Object
writeonly
url base for /links.
-
#template_handler ⇒ Object
template_handler(macroname) -> template_text when macros enabled and {myCoolMacro} ocured, result fo ‘template_handler(’myCoolMacro’) inserted.
-
#used_templates ⇒ Object
readonly
Returns the value of attribute used_templates.
Instance Method Summary collapse
- #add_macro_command(name, &block) ⇒ Object
- #allow_html? ⇒ Boolean
- #div_around_table? ⇒ Boolean
- #edit_heading? ⇒ Boolean
- #id_from_heading? ⇒ Boolean
- #id_translit? ⇒ Boolean
-
#initialize(options = {}) ⇒ Parser
constructor
Create a new Parser instance.
- #macros? ⇒ Boolean
- #make_toc_html ⇒ Object
- #math? ⇒ Boolean
- #merge? ⇒ Boolean
- #no_escape? ⇒ Boolean
- #no_link? ⇒ Boolean
- #text(text) ⇒ Object
- #to_html(text = nil, base_url = '') ⇒ Object
- #was_math? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Parser
Create a new Parser instance.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/trac-wiki/parser.rb', line 147 def initialize( = {}) init_macros @at_callback = nil @env = Env.new(self) @macros = true @allowed_schemes = %w(http https ftp ftps) macro_commands = .delete :macro_commands @macro_commands.merge! macro_commands if ! macro_commands.nil? @no_escape = nil @base = '' @root = '' .each_pair {|k,v| send("#{k}=", v) } @base += '/' if !@base.empty? && @base[-1] != '/' @root += '/' if @root.empty? || @root[-1] != '/' end |
Instance Attribute Details
#allow_html=(value) ⇒ Object (writeonly)
allow some <b> <form> <html> html will be sanitized
96 97 98 |
# File 'lib/trac-wiki/parser.rb', line 96 def allow_html=(value) @allow_html = value end |
#allowed_schemes ⇒ Object
Allowed url schemes Examples: http https ftp ftps
47 48 49 |
# File 'lib/trac-wiki/parser.rb', line 47 def allowed_schemes @allowed_schemes end |
#at_callback ⇒ Object
Proc or nil at_callback.call(env, key) -> computed value
137 138 139 |
# File 'lib/trac-wiki/parser.rb', line 137 def at_callback @at_callback end |
#base=(value) ⇒ Object (writeonly)
url base for links
68 69 70 |
# File 'lib/trac-wiki/parser.rb', line 68 def base=(value) @base = value end |
#base_url ⇒ Object
Returns the value of attribute base_url.
61 62 63 |
# File 'lib/trac-wiki/parser.rb', line 61 def base_url @base_url end |
#div_around_table=(value) ⇒ Object (writeonly)
Enable <div> around <table>
85 86 87 |
# File 'lib/trac-wiki/parser.rb', line 85 def div_around_table=(value) @div_around_table = value end |
#edit_heading=(value) ⇒ Object (writeonly)
add ‘<a class=’editheading’ href=“?edit=N>edit</a>‘ to each heading
101 102 103 |
# File 'lib/trac-wiki/parser.rb', line 101 def edit_heading=(value) @edit_heading = value end |
#env ⇒ Object
Returns the value of attribute env.
60 61 62 |
# File 'lib/trac-wiki/parser.rb', line 60 def env @env end |
#headings ⇒ Object
structure where headings are stroed list of hasheses with ‘level` and `title`, `sline` [ { leven: 1, # <h1>
sline: 3, # line where head starts
eline: 4, # line before next heading starts
aname: 'anchor-to-this-heading',
title: 'heading title'
},
...
]
59 60 61 |
# File 'lib/trac-wiki/parser.rb', line 59 def headings @headings end |
#id_from_heading=(value) ⇒ Object (writeonly)
every heading had id, generated from heading text
114 115 116 |
# File 'lib/trac-wiki/parser.rb', line 114 def id_from_heading=(value) @id_from_heading = value end |
#id_translit=(value) ⇒ Object (writeonly)
when id_from_heading, non ascii char are transliterated to ascii
122 123 124 |
# File 'lib/trac-wiki/parser.rb', line 122 def id_translit=(value) @id_translit = value end |
#macro_commands ⇒ Object
like template but more powerfull do no use.
127 128 129 |
# File 'lib/trac-wiki/parser.rb', line 127 def macro_commands @macro_commands end |
#macros=(value) ⇒ Object (writeonly)
use macros? defalut yes
118 119 120 |
# File 'lib/trac-wiki/parser.rb', line 118 def macros=(value) @macros = value end |
#math=(value) ⇒ Object (writeonly)
math syntax extension: $e^x$ for inline math $$ e^x $$ for display math
91 92 93 |
# File 'lib/trac-wiki/parser.rb', line 91 def math=(value) @math = value end |
#merge=(value) ⇒ Object (writeonly)
understand merge tags (see diff3(1)) >>>>>>> mine ||||||| orig
<<<<<<< yours convert to <div class=“merge merge-mine”>mine</div>
110 111 112 |
# File 'lib/trac-wiki/parser.rb', line 110 def merge=(value) @merge = value end |
#no_escape=(value) ⇒ Object (writeonly)
Disable url escaping for local links Escaping: [[/Test]] –> %2FTest No escaping: [[/Test]] –> Test
76 77 78 |
# File 'lib/trac-wiki/parser.rb', line 76 def no_escape=(value) @no_escape = value end |
#no_link=(value) ⇒ Object (writeonly)
Disable url escaping for local links
- [whatwerver]
-
stays [[whatwerver]]
81 82 83 |
# File 'lib/trac-wiki/parser.rb', line 81 def no_link=(value) @no_link = value end |
#root=(value) ⇒ Object (writeonly)
url base for /links
71 72 73 |
# File 'lib/trac-wiki/parser.rb', line 71 def root=(value) @root = value end |
#template_handler ⇒ Object
template_handler(macroname) -> template_text when macros enabled and {myCoolMacro} ocured, result fo ‘template_handler(’myCoolMacro’) inserted
133 134 135 |
# File 'lib/trac-wiki/parser.rb', line 133 def template_handler @template_handler end |
#used_templates ⇒ Object (readonly)
Returns the value of attribute used_templates.
63 64 65 |
# File 'lib/trac-wiki/parser.rb', line 63 def used_templates @used_templates end |
Instance Method Details
#add_macro_command(name, &block) ⇒ Object
196 197 198 |
# File 'lib/trac-wiki/parser.rb', line 196 def add_macro_command(name, &block) @macro_commands[name] = block end |
#allow_html? ⇒ Boolean
97 |
# File 'lib/trac-wiki/parser.rb', line 97 def allow_html?; @allow_html; end |
#div_around_table? ⇒ Boolean
86 |
# File 'lib/trac-wiki/parser.rb', line 86 def div_around_table?; @div_around_table; end |
#edit_heading? ⇒ Boolean
102 |
# File 'lib/trac-wiki/parser.rb', line 102 def edit_heading?; @edit_heading; end |
#id_from_heading? ⇒ Boolean
115 |
# File 'lib/trac-wiki/parser.rb', line 115 def id_from_heading?; @id_from_heading; end |
#id_translit? ⇒ Boolean
123 |
# File 'lib/trac-wiki/parser.rb', line 123 def id_translit?; @id_translit; end |
#macros? ⇒ Boolean
119 |
# File 'lib/trac-wiki/parser.rb', line 119 def macros?; @macros; end |
#make_toc_html ⇒ Object
190 191 192 193 194 |
# File 'lib/trac-wiki/parser.rb', line 190 def make_toc_html @tree = TracWiki::Tree.new parse_block(make_toc) @tree.to_html end |
#math? ⇒ Boolean
92 |
# File 'lib/trac-wiki/parser.rb', line 92 def math?; @math; end |
#merge? ⇒ Boolean
111 |
# File 'lib/trac-wiki/parser.rb', line 111 def merge?; @merge; end |
#no_escape? ⇒ Boolean
77 |
# File 'lib/trac-wiki/parser.rb', line 77 def no_escape?; @no_escape; end |
#no_link? ⇒ Boolean
82 |
# File 'lib/trac-wiki/parser.rb', line 82 def no_link?; @no_link; end |
#text(text) ⇒ Object
163 164 165 166 |
# File 'lib/trac-wiki/parser.rb', line 163 def text(text) @text = text return self end |
#to_html(text = nil, base_url = '') ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/trac-wiki/parser.rb', line 170 def to_html(text = nil, base_url = '') text(text) if ! text.nil? @base_url = base_url @used_templates = {} @was_math = false @anames = {} @count_lines_level = 0 @text = text if !text.nil? @tree = TracWiki::Tree.new @edit_heading_class = 'editheading' @headings = [ {level: 0, sline: 1 } ] @p = false @stack = [] @stacki = [] @was_math = false @line_no = 1 parse_block(@text) @tree.to_html end |
#was_math? ⇒ Boolean
168 |
# File 'lib/trac-wiki/parser.rb', line 168 def was_math?; @was_math; end |