Class: TracWiki::Parser
- Inherits:
-
Object
- Object
- TracWiki::Parser
- Defined in:
- lib/trac-wiki/parser.rb
Constant Summary collapse
- MACRO_BEG_REX =
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.
-
#base ⇒ Object
writeonly
url base for links.
-
#edit_heading ⇒ Object
writeonly
add ‘<a class=’editheading’ href=“?edit=N>edit</a>‘ to each heading.
-
#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]].
-
#template_handler ⇒ Object
template_handler(macroname) -> template_text when macros enabled and {myCoolMacro} ocured, result fo ‘template_handler(’myCoolMacro’) inserted.
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 = nil) ⇒ 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 = nil) ⇒ Parser
Create a new Parser instance.
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/trac-wiki/parser.rb', line 127 def initialize( = nil) init_macros @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 = '' .each_pair {|k,v| send("#{k}=", v) } @base += '/' if !@base.empty? && @base[-1] != '/' end |
Instance Attribute Details
#allow_html=(value) ⇒ Object (writeonly)
allow some <b> <form> <html> html will be sanitized
81 82 83 |
# File 'lib/trac-wiki/parser.rb', line 81 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 |
#base=(value) ⇒ Object (writeonly)
url base for links
60 61 62 |
# File 'lib/trac-wiki/parser.rb', line 60 def base=(value) @base = value end |
#edit_heading=(value) ⇒ Object (writeonly)
add ‘<a class=’editheading’ href=“?edit=N>edit</a>‘ to each heading
86 87 88 |
# File 'lib/trac-wiki/parser.rb', line 86 def edit_heading=(value) @edit_heading = value 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
99 100 101 |
# File 'lib/trac-wiki/parser.rb', line 99 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
107 108 109 |
# File 'lib/trac-wiki/parser.rb', line 107 def id_translit=(value) @id_translit = value end |
#macro_commands ⇒ Object
like template but more powerfull do no use.
112 113 114 |
# File 'lib/trac-wiki/parser.rb', line 112 def macro_commands @macro_commands end |
#macros=(value) ⇒ Object (writeonly)
use macros? defalut yes
103 104 105 |
# File 'lib/trac-wiki/parser.rb', line 103 def macros=(value) @macros = value end |
#math=(value) ⇒ Object (writeonly)
math syntax extension: $e^x$ for inline math $$ e^x $$ for display math
76 77 78 |
# File 'lib/trac-wiki/parser.rb', line 76 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>
95 96 97 |
# File 'lib/trac-wiki/parser.rb', line 95 def merge=(value) @merge = value end |
#no_escape=(value) ⇒ Object (writeonly)
Disable url escaping for local links Escaping: [[/Test]] –> %2FTest No escaping: [[/Test]] –> Test
65 66 67 |
# File 'lib/trac-wiki/parser.rb', line 65 def no_escape=(value) @no_escape = value end |
#no_link=(value) ⇒ Object (writeonly)
Disable url escaping for local links
- [whatwerver]
-
stays [[whatwerver]]
70 71 72 |
# File 'lib/trac-wiki/parser.rb', line 70 def no_link=(value) @no_link = value end |
#template_handler ⇒ Object
template_handler(macroname) -> template_text when macros enabled and {myCoolMacro} ocured, result fo ‘template_handler(’myCoolMacro’) inserted
118 119 120 |
# File 'lib/trac-wiki/parser.rb', line 118 def template_handler @template_handler end |
Instance Method Details
#add_macro_command(name, &block) ⇒ Object
170 171 172 |
# File 'lib/trac-wiki/parser.rb', line 170 def add_macro_command(name, &block) @macro_commands[name] = block end |
#allow_html? ⇒ Boolean
82 |
# File 'lib/trac-wiki/parser.rb', line 82 def allow_html?; @allow_html; end |
#edit_heading? ⇒ Boolean
87 |
# File 'lib/trac-wiki/parser.rb', line 87 def edit_heading?; @edit_heading; end |
#id_from_heading? ⇒ Boolean
100 |
# File 'lib/trac-wiki/parser.rb', line 100 def id_from_heading?; @id_from_heading; end |
#id_translit? ⇒ Boolean
108 |
# File 'lib/trac-wiki/parser.rb', line 108 def id_translit?; @id_translit; end |
#macros? ⇒ Boolean
104 |
# File 'lib/trac-wiki/parser.rb', line 104 def macros?; @macros; end |
#make_toc_html ⇒ Object
164 165 166 167 168 |
# File 'lib/trac-wiki/parser.rb', line 164 def make_toc_html @tree = TracWiki::Tree.new parse_block(make_toc) @tree.to_html end |
#math? ⇒ Boolean
77 |
# File 'lib/trac-wiki/parser.rb', line 77 def math?; @math; end |
#merge? ⇒ Boolean
96 |
# File 'lib/trac-wiki/parser.rb', line 96 def merge?; @merge; end |
#no_escape? ⇒ Boolean
66 |
# File 'lib/trac-wiki/parser.rb', line 66 def no_escape?; @no_escape; end |
#no_link? ⇒ Boolean
71 |
# File 'lib/trac-wiki/parser.rb', line 71 def no_link?; @no_link; end |
#text(text) ⇒ Object
139 140 141 142 |
# File 'lib/trac-wiki/parser.rb', line 139 def text(text) @text = text return self end |
#to_html(text = nil) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/trac-wiki/parser.rb', line 146 def to_html(text = nil) text(text) if ! text.nil? @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
144 |
# File 'lib/trac-wiki/parser.rb', line 144 def was_math?; @was_math; end |