Module | Generators::MarkUp |
In: |
generators/html_generator.rb
generators/xhtml_generator.rb |
Build a webcvs URL with the given ‘url’ argument. URLs with a ’%s’ in them get the file‘s path sprintfed into them; otherwise they‘re just catenated together.
# File generators/html_generator.rb, line 306 306: def cvs_url(url, full_path) 307: if /%s/ =~ url 308: return sprintf( url, full_path ) 309: else 310: return url + full_path 311: end 312: end
Convert a string in markup format into HTML. We keep a cached SimpleMarkup object lying around after the first time we‘re called per object.
# File generators/html_generator.rb, line 236 236: def markup(str, remove_para=false) 237: return '' unless str 238: unless defined? @markup 239: @markup = SM::SimpleMarkup.new 240: 241: # class names, variable names, or instance variables 242: @markup.add_special(/( 243: \b\w+(::\w+)*[\.\#]\w+(\([\.\w+\*\/\+\-\=\<\>]+\))? # A::B.meth(**) (for operator and assignment in Fortran 90 or 95) 244: | \#\w+(\([.\w\*\/\+\-\=\<\>]+\))? # meth(**) (for operator and assignment in Fortran 90 or 95) 245: | \b([A-Z]\w*(::\w+)*[.\#]\w+) # A::B.meth 246: | \b([A-Z]\w+(::\w+)*) # A::B.. 247: | \#\w+[!?=]? # #meth_name 248: | \b\w+([_\/\.]+\w+)*[!?=]? # meth_name 249: )/x, 250: :CROSSREF) 251: 252: # file names 253: @markup.add_special(/( 254: ((\/|\.\.\/|\.\/|\w)[\w\#\/\.\-\~\:]*[!?=]?) # file_name 255: | ((\/|\.\.\/|\.\/|\w)[\w\#\/\.\-\~\:]*(\([\.\w+\*\/\+\-\=\<\>]+\))?) 256: )/x, 257: :CROSSREFFILE) 258: 259: # external hyperlinks 260: @markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK) 261: 262: # and links of the form <text>[<url>] 263: @markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\.\S+?\])/, :TIDYLINK) 264: # @markup.add_special(/\b(\S+?\[\S+?\.\S+?\])/, :TIDYLINK) 265: 266: end 267: unless defined? @html_formatter 268: @html_formatter = HyperlinkHtml.new(self.path, self) 269: end 270: 271: # Convert leading comment markers to spaces, but only 272: # if all non-blank lines have them 273: 274: if str =~ /^(?>\s*)[^\#]/ 275: content = str 276: else 277: content = str.gsub(/^\s*(#+)/) { $1.tr('#',' ') } 278: end 279: 280: res = @markup.convert(content, @html_formatter) 281: if remove_para 282: res.sub!(/^<p>/, '') 283: res.sub!(/<\/p>$/, '') 284: end 285: res 286: end
This is almost a copy of the markup method in html_generator. This method markup $ .… $ and \[ … \] as tex format.
# File generators/xhtml_generator.rb, line 217 217: def markup(str, remove_para=false) 218: return '' unless str 219: unless defined? @markup 220: @markup = SM::SimpleMarkup.new 221: 222: # class names, variable names, or instance variables 223: @markup.add_special(/( 224: \b\w+(::\w+)*[\.\#]\w+(\([\.\w+\*\/\+\-\=\<\>]+\))? # A::B.meth(**) (for operator in Fortran95) 225: | \#\w+(\([.\w\*\/\+\-\=\<\>]+\))? # meth(**) (for operator in Fortran95) 226: | \b([A-Z]\w*(::\w+)*[.\#]\w+) # A::B.meth 227: | \b([A-Z]\w+(::\w+)*) # A::B.. 228: | \#\w+[!?=]? # #meth_name 229: | \b\w+([_\/\.]+\w+)*[!?=]? # meth_name 230: )/x, 231: :CROSSREF) 232: 233: # file names 234: @markup.add_special(/( 235: \b(\w[\w\#\/\.\-\~\:]*[!?=]?) # file_name 236: | \b(\w[\w\#\/\.\-\~\:]*(\([\.\w+\*\/\+\-\=\<\>]+\))?) 237: )/x, 238: :CROSSREFFILE) 239: 240: # external hyperlinks 241: @markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK) 242: 243: # and links of the form <text>[<url>] 244: @markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\.\S+?\])/, :TIDYLINK) 245: # @markup.add_special(/\b(\S+?\[\S+?\.\S+?\])/, :TIDYLINK) 246: 247: if Options.instance.mathml 248: # TeX inline form 249: @markup.add_special(/(\$(.*?)[^\\]\$)/im, :TEXINLINE) 250: 251: # TeX inline delimiter 252: @markup.add_special(/(\\\$)/im, :TEXINLINEDELIMITER) 253: 254: # TeX block form 255: @markup.add_special(/(\\\[(.+?)\\\])/im, :TEXBLOCK) 256: end 257: 258: end 259: unless defined? @html_formatter 260: @html_formatter = TexParser.new(self.path, self) 261: end 262: 263: # Convert leading comment markers to spaces, but only 264: # if all non-blank lines have them 265: 266: if str =~ /^(?>\s*)[^\#]/ 267: content = str 268: else 269: content = str.gsub(/^\s*(#+)/) { $1.tr('#',' ') } 270: end 271: 272: block_exceptions = [] 273: if Options.instance.mathml 274: block_exceptions << { 275: 'name' => :texblockform, 276: 'start' => Regexp.new("^\\\\\\["), 277: 'end' => Regexp.new("\\\\\\]$"), 278: 'replaces' => [] 279: } 280: block_exceptions[0]['replaces'] << { 281: 'from' => Regexp.new("\\\\\\\\"), 282: 'to' => "\\\\\\\\\\\\\\\\", 283: } 284: end 285: 286: res = @markup.convert(content, @html_formatter, block_exceptions) 287: if remove_para 288: res.sub!(/^<p>/, '') 289: res.sub!(/<\/p>$/, '') 290: end 291: res 292: end
Qualify a stylesheet URL; if if css_name does not begin with ‘/’ or ‘http[s]://’, prepend a prefix relative to path. Otherwise, return it unmodified.
# File generators/html_generator.rb, line 292 292: def style_url(path, css_name=nil) 293: # $stderr.puts "style_url( #{path.inspect}, #{css_name.inspect} )" 294: css_name ||= CSS_NAME 295: if %r{^(https?:/)?/} =~ css_name 296: return css_name 297: else 298: return HTMLGenerator.gen_url(path, css_name) 299: end 300: end