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.
-
#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
levelandtitle,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
- #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) ⇒ Object
- #was_math? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Parser
Create a new Parser instance.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/trac-wiki/parser.rb', line 140 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
89 90 91 |
# File 'lib/trac-wiki/parser.rb', line 89 def allow_html=(value) @allow_html = value end |
#allowed_schemes ⇒ Object
Allowed url schemes Examples: http https ftp ftps
45 46 47 |
# File 'lib/trac-wiki/parser.rb', line 45 def allowed_schemes @allowed_schemes end |
#at_callback ⇒ Object
Proc or nil at_callback.call(env, key) -> computed value
130 131 132 |
# File 'lib/trac-wiki/parser.rb', line 130 def at_callback @at_callback end |
#base=(value) ⇒ Object (writeonly)
url base for links
65 66 67 |
# File 'lib/trac-wiki/parser.rb', line 65 def base=(value) @base = value end |
#edit_heading=(value) ⇒ Object (writeonly)
add ‘<a class=’editheading’ href=“?edit=N>edit</a>‘ to each heading
94 95 96 |
# File 'lib/trac-wiki/parser.rb', line 94 def edit_heading=(value) @edit_heading = value end |
#env ⇒ Object
Returns the value of attribute env.
58 59 60 |
# File 'lib/trac-wiki/parser.rb', line 58 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'
},
...
]
57 58 59 |
# File 'lib/trac-wiki/parser.rb', line 57 def headings @headings end |
#id_from_heading=(value) ⇒ Object (writeonly)
every heading had id, generated from heading text
107 108 109 |
# File 'lib/trac-wiki/parser.rb', line 107 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
115 116 117 |
# File 'lib/trac-wiki/parser.rb', line 115 def id_translit=(value) @id_translit = value end |
#macro_commands ⇒ Object
like template but more powerfull do no use.
120 121 122 |
# File 'lib/trac-wiki/parser.rb', line 120 def macro_commands @macro_commands end |
#macros=(value) ⇒ Object (writeonly)
use macros? defalut yes
111 112 113 |
# File 'lib/trac-wiki/parser.rb', line 111 def macros=(value) @macros = value end |
#math=(value) ⇒ Object (writeonly)
math syntax extension: $e^x$ for inline math $$ e^x $$ for display math
84 85 86 |
# File 'lib/trac-wiki/parser.rb', line 84 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>
103 104 105 |
# File 'lib/trac-wiki/parser.rb', line 103 def merge=(value) @merge = value end |
#no_escape=(value) ⇒ Object (writeonly)
Disable url escaping for local links Escaping: [[/Test]] –> %2FTest No escaping: [[/Test]] –> Test
73 74 75 |
# File 'lib/trac-wiki/parser.rb', line 73 def no_escape=(value) @no_escape = value end |
#no_link=(value) ⇒ Object (writeonly)
Disable url escaping for local links
- [whatwerver]
-
stays [[whatwerver]]
78 79 80 |
# File 'lib/trac-wiki/parser.rb', line 78 def no_link=(value) @no_link = value end |
#root=(value) ⇒ Object (writeonly)
url base for /links
68 69 70 |
# File 'lib/trac-wiki/parser.rb', line 68 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
126 127 128 |
# File 'lib/trac-wiki/parser.rb', line 126 def template_handler @template_handler end |
#used_templates ⇒ Object (readonly)
Returns the value of attribute used_templates.
60 61 62 |
# File 'lib/trac-wiki/parser.rb', line 60 def used_templates @used_templates end |
Instance Method Details
#add_macro_command(name, &block) ⇒ Object
188 189 190 |
# File 'lib/trac-wiki/parser.rb', line 188 def add_macro_command(name, &block) @macro_commands[name] = block end |
#allow_html? ⇒ Boolean
90 |
# File 'lib/trac-wiki/parser.rb', line 90 def allow_html?; @allow_html; end |
#edit_heading? ⇒ Boolean
95 |
# File 'lib/trac-wiki/parser.rb', line 95 def edit_heading?; @edit_heading; end |
#id_from_heading? ⇒ Boolean
108 |
# File 'lib/trac-wiki/parser.rb', line 108 def id_from_heading?; @id_from_heading; end |
#id_translit? ⇒ Boolean
116 |
# File 'lib/trac-wiki/parser.rb', line 116 def id_translit?; @id_translit; end |
#macros? ⇒ Boolean
112 |
# File 'lib/trac-wiki/parser.rb', line 112 def macros?; @macros; end |
#make_toc_html ⇒ Object
182 183 184 185 186 |
# File 'lib/trac-wiki/parser.rb', line 182 def make_toc_html @tree = TracWiki::Tree.new parse_block(make_toc) @tree.to_html end |
#math? ⇒ Boolean
85 |
# File 'lib/trac-wiki/parser.rb', line 85 def math?; @math; end |
#merge? ⇒ Boolean
104 |
# File 'lib/trac-wiki/parser.rb', line 104 def merge?; @merge; end |
#no_escape? ⇒ Boolean
74 |
# File 'lib/trac-wiki/parser.rb', line 74 def no_escape?; @no_escape; end |
#no_link? ⇒ Boolean
79 |
# File 'lib/trac-wiki/parser.rb', line 79 def no_link?; @no_link; end |
#text(text) ⇒ Object
156 157 158 159 |
# File 'lib/trac-wiki/parser.rb', line 156 def text(text) @text = text return self end |
#to_html(text = nil) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/trac-wiki/parser.rb', line 163 def to_html(text = nil) text(text) if ! text.nil? @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
161 |
# File 'lib/trac-wiki/parser.rb', line 161 def was_math?; @was_math; end |