/usr/share/tdiary/misc/plugin/makerss.rb is in tdiary-plugin 3.2.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | # makerss.rb
#
# generate RSS file when updating.
#
# options configurable through settings:
# @conf['makerss.hidecontent'] : hide full-text content. default: false
# @conf['makerss.shortdesc'] : shorter description. default: false
# @conf['makerss.comment_link'] : insert tsukkomi's link. default: false
#
# options to be edited in tdiary.conf:
# @conf['makerss.file'] : local file name of RSS file. default: 'index.rdf'.
# @conf['makerss.url'] : URL of RSS file.
# @conf['makerss.no_comments.file'] : local file name of RSS file without
# comments. default: 'no_comments.rdf'.
# @conf['makerss.no_comments.url'] : URL of RSS file without TSUKOMI.
# @conf.banner : URL of site banner image (can be relative)
# @conf.description : desciption of the diary
# @conf['makerss.partial'] : how much portion of body to be in description
# used when makerss.shortdesc, default: 0.25
# @conf['makerss.suffix'] : strings which are appended to the title tag.
# @conf['makerss.no_comments.suffix'] : strings which are appended to
# the title tag of the commentless rdf.
#
# CAUTION: Before using, make 'index.rdf' and 'no_comments.rdf' file
# into the directory of your diary, and permit writable to httpd.
#
# Copyright (c) 2009 TADA Tadashi <t@tdtds.jp>
# Distributed under the GPL
#
if /^append|replace|comment|showcomment$/ =~ @mode then
unless @conf.description
@conf.description = @conf['whatsnew_list.rdf.description']
end
module ::TDiary
class RDFSection
attr_reader :id, :time, :section, :diary_title
# 'id' has 'YYYYMMDDpNN' format (p or c).
# 'time' is Last-Modified this section as a Time object.
def initialize( id, time, section )
@id, @time, @section, @diary_title = id, time, section, diary_title
end
def time_string
g = @time.dup.gmtime
l = Time::local( g.year, g.month, g.day, g.hour, g.min, g.sec )
tz = (g.to_i - l.to_i)
zone = sprintf( "%+03d:%02d", tz / 3600, tz % 3600 / 60 )
@time.strftime( "%Y-%m-%dT%H:%M:%S" ) + zone
end
def <=>( other )
other.time <=> @time
end
end
end
end
@makerss_rsses = @makerss_rsses || []
class MakeRssFull
include ERB::Util
include TDiary::ViewHelper
def initialize(conf, cgi = CGI.new)
@conf, @cgi = conf, cgi
@item_num = 0
end
def title
@conf['makerss.suffix'] || ''
end
def head( str )
@head = str
@head.sub!( /<\/title>/, "#{h title}</title>" )
end
def foot( str ); @foot = str; end
def image( str ); @image = str; end
def banner( str ); @banner = str; end
def item( seq, body, rdfsec )
@item_num += 1
return if @item_num > 15
@seq = '' unless @seq
@seq << seq
@body = '' unless @body
@body << body
end
def xml
xml = @head.to_s
xml << @image.to_s
xml << "<items><rdf:Seq>\n"
xml << @seq.to_s
xml << "</rdf:Seq></items>\n</channel>\n"
xml << @banner.to_s
xml << @body.to_s
xml << @foot.to_s
xml.gsub( /[\x00-\x1f]/ ){|s| s =~ /[\r\n\t]/ ? s : ""}
end
def file
f = @conf['makerss.file'] || 'index.rdf'
f = 'index.rdf' if f.empty?
f =~ %r|^/| ? f : "#{TDiary.document_root}/#{f}"
end
def writable?
if FileTest::writable?( file ) then
return true
elsif FileTest::exist?( file )
return false
else # try to create
begin
File::open( file, 'w' ){|f|}
return true
rescue
return false
end
end
end
def write( encoder )
begin
File::open( file, 'w' ) do |f|
f.write( encoder.call( xml ) )
end
rescue
end
end
def url
u = @conf['makerss.url'] || "#{base_url}#{File.basename(file)}"
u = "#{base_url}#{File.basename(file)}" if u.empty?
u
end
end
@makerss_rsses << MakeRssFull::new(@conf, @cgi)
class MakeRssNoComments < MakeRssFull
def title
@conf['makerss.no_comments.suffix'] || '(without comments)'
end
def item( seq, body, rdfsec )
return unless rdfsec.section.respond_to?( :body_to_html )
super
end
def file
f = @conf['makerss.no_comments.file'] || 'no_comments.rdf'
f = 'no_comments.rdf' if f.empty?
f =~ %r|^/| ? f : "#{TDiary.document_root}/#{f}"
end
def write( encoder )
return unless @conf['makerss.no_comments']
super( encoder )
end
def url
return nil unless @conf['makerss.no_comments']
u = @conf['makerss.no_comments.url'] || "#{base_url}#{File.basename(file)}"
u = "#{base_url}#{File.basename(file)}" if u.empty?
u
end
end
@makerss_rsses << MakeRssNoComments::new(@conf, @cgi)
def makerss_update
date = @date.strftime( "%Y%m%d" )
diary = @diaries[date]
uri = @conf.index.dup
uri[0, 0] = base_url if %r|^https?://|i !~ @conf.index
uri.gsub!( %r|/\./|, '/' )
require 'pstore'
cache = {}
rsses = @makerss_rsses
begin
PStore::new( "#{@cache_path}/makerss.cache" ).transaction do |db|
begin
cache = db['cache'] if db.root?( 'cache' )
if /^append|replace$/ =~ @mode then
format = "#{date}p%02d"
index = 0
diary.each_section do |section|
index += 1
id = format % index
if diary.visible? and !cache[id] then
cache[id] = RDFSection::new( id, Time::now, section )
elsif !diary.visible? and cache[id]
cache.delete( id )
elsif diary.visible? and cache[id]
if cache[id].section.body_to_html != section.body_to_html or
cache[id].section.subtitle_to_html != section.subtitle_to_html then
cache[id] = RDFSection::new( id, Time::now, section )
end
end
end
loop do
index += 1
id = format % index
if cache[id] then
cache.delete( id )
else
break
end
end
elsif /^comment$/ =~ @mode and @conf.show_comment
id = "#{date}c%02d" % diary.count_comments( true )
cache[id] = RDFSection::new( id, @comment.date, @comment )
elsif /^showcomment$/ =~ @mode
index = 0
diary.each_comment do |comment|
index += 1
id = "#{date}c%02d" % index
if !cache[id] and (@conf.show_comment and comment.visible? and /^(TrackBack|Pingback)$/i !~ comment.name) then
cache[id] = RDFSection::new( id, comment.date, comment )
elsif cache[id] and !(@conf.show_comment and comment.visible? and /^(TrackBack|Pingback)$/i !~ comment.name)
cache.delete( id )
end
end
end
rsses.each{|rss| rss.head( makerss_header( uri ) ) }
cache.values.sort{|a,b| b.time <=> a.time}.each_with_index do |rdfsec, idx|
unless rdfsec.section.respond_to?( :visible? ) and !rdfsec.section.visible?
rsses.each {|rss|
rss.item( makerss_seq( uri, rdfsec ), makerss_body( uri, rdfsec ), rdfsec )
}
end
if idx > 50
cache.delete( rdfsec.id )
end
end
db['cache'] = cache
rescue PStore::Error
end
end
rescue ArgumentError
File.unlink( "#{@cache_path}/makerss.cache" )
retry
end
if @conf.banner and not @conf.banner.empty?
if /^http/ =~ @conf.banner
rdf_image = @conf.banner
else
rdf_image = base_url + @conf.banner
end
rsses.each {|r| r.image( %Q[<image rdf:resource="#{h rdf_image}" />\n] ) }
end
rsses.each {|r|
r.banner( makerss_banner( uri, rdf_image ) ) if rdf_image
r.foot( makerss_footer )
r.write( Proc::new{|s| replace_entities( to_utf8( s ) )} )
}
end
def makerss_header( uri )
rdf_url = @conf['makerss.url'] || "#{base_url}index.rdf"
rdf_url = "#{base_url}index.rdf" if rdf_url.empty?
desc = @conf.description || ''
copyright = Time::now.strftime( "Copyright %Y #{@conf.author_name}" )
copyright += " <#{@conf.author_mail}>" if @conf.author_mail and not @conf.author_mail.empty?
copyright += ", copyright of comments by respective authors"
xml = %Q[<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="rss.css" type="text/css"?>
<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="#{h @conf.html_lang}">
<channel rdf:about="#{h rdf_url}">
<title>#{h @conf.html_title}</title>
<link>#{h uri}</link>
<xhtml:link xhtml:rel="alternate" xhtml:media="handheld" xhtml:type="text/html" xhtml:href="#{h uri}" />
<description>#{h desc}</description>
<dc:creator>#{h @conf.author_name}</dc:creator>
<dc:rights>#{h copyright}</dc:rights>
]
end
def makerss_seq( uri, rdfsec )
%Q|<rdf:li rdf:resource="#{h uri}#{anchor rdfsec.id}"/>\n|
end
def makerss_banner( uri, rdf_image )
%Q[<image rdf:about="#{h rdf_image}">
<title>#{h @conf.html_title}</title>
<url>#{h rdf_image}</url>
<link>#{h uri}</link>
</image>
]
end
def makerss_desc_shorten( text )
if @conf['makerss.shortdesc'] then
@conf['makerss.partial'] = 0.25 unless @conf['makerss.partial']
len = ( text.size.to_f * @conf['makerss.partial'] ).ceil.to_i
len = 500 if len > 500
else
len = 500
end
@conf.shorten( text, len )
end
def feed?
@makerss_in_feed
end
def makerss_body( uri, rdfsec )
rdf = ""
if rdfsec.section.respond_to?( :body_to_html ) then
rdf = %Q|<item rdf:about="#{h uri}#{anchor rdfsec.id}">\n|
rdf << %Q|<link>#{h uri}#{anchor rdfsec.id}</link>\n|
rdf << %Q|<xhtml:link xhtml:rel="alternate" xhtml:media="handheld" xhtml:type="text/html" xhtml:href="#{h uri}#{anchor rdfsec.id}" />\n|
rdf << %Q|<dc:date>#{h rdfsec.time_string}</dc:date>\n|
a = rdfsec.id.scan( /(\d{4})(\d\d)(\d\d)/ ).flatten.map{|s| s.to_i}
date = Time::local( *a )
old_apply_plugin = @conf['apply_plugin']
@conf['apply_plugin'] = true
@makerss_in_feed = true
subtitle = rdfsec.section.subtitle_to_html
sec_id = rdfsec.id[9,2].to_i
body_enter = body_enter_proc( date )
body = apply_plugin( rdfsec.section.body_to_html )
body_leave = body_leave_proc( date )
@makerss_in_feed = false
sub = (subtitle || '').sub( /^(\[([^\]]+)\])+ */, '' )
sub = apply_plugin( sub, true ).strip
if sub.empty?
sub = @conf.shorten( remove_tag( body ).strip, 20 )
end
rdf << %Q|<title>#{sub}</title>\n|
rdf << %Q|<dc:creator>#{h @conf.author_name}</dc:creator>\n|
unless rdfsec.section.categories.empty?
rdfsec.section.categories.each do |category|
rdf << %Q|<dc:subject>#{h category}</dc:subject>\n|
end
end
desc = remove_tag( body ).strip
desc.gsub!( /&.*?;/, '' )
rdf << %Q|<description>#{h makerss_desc_shorten( desc )}</description>\n|
unless @conf['makerss.hidecontent']
text = ''
text << '<h3>' + apply_plugin( subtitle.sub( /^(\[([^\]]+)\])+ */, '' ) ).strip + '</h3>' if subtitle and not subtitle.empty?
text << body_enter
text << body
text << body_leave
unless text.empty?
uri = @conf.index.dup
uri[0, 0] = base_url unless %r|^https?://|i =~ uri
uri.gsub!( %r|/\./|, '/' )
text = absolutify( text, uri )
text.gsub!( /\]\]>/, ']]]]><![CDATA[>' )
rdf << %Q|<content:encoded><![CDATA[#{text}|
unless @conf['makerss.comment_link']
ymd = date.strftime( "%Y%m%d" )
rdf << %Q|\n<p><a href="#{h uri}#{anchor "#{ymd}c"}">#{comment_new}</a></p>|
end
rdf << %Q|]]></content:encoded>\n|
end
end
@conf['apply_plugin'] = old_apply_plugin
rdf << "</item>\n"
else # TSUKKOMI
rdf = %Q|<item rdf:about="#{h uri}#{anchor rdfsec.id}">\n|
rdf << %Q|<link>#{h uri}#{anchor rdfsec.id}</link>\n|
rdf << %Q|<dc:date>#{h rdfsec.time_string}</dc:date>\n|
rdf << %Q|<title>#{makerss_tsukkomi_label( rdfsec.id )} (#{h rdfsec.section.name})</title>\n|
rdf << %Q|<dc:creator>#{h rdfsec.section.name}</dc:creator>\n|
text = rdfsec.section.body
rdf << %Q|<description>#{h makerss_desc_shorten( text )}</description>\n|
unless @conf['makerss.hidecontent']
rdf << %Q|<content:encoded><![CDATA[#{text.make_link.gsub( /\n/, '<br>' ).gsub( /<br><br>\Z/, '' ).gsub( /\]\]>/, ']]]]><![CDATA[>' )}]]></content:encoded>\n|
end
rdf << "</item>\n"
end
rdf
end
def makerss_footer
"</rdf:RDF>\n"
end
add_update_proc do
makerss_update unless @cgi.params['makerss_update'][0] == 'false'
end
add_header_proc {
html = ''
@makerss_rsses.each do |rss|
next unless rss.url
html << %Q|\t<link rel="alternate" type="application/rss+xml" title="RSS#{h rss.title}" href="#{h rss.url}">\n|
end
html
}
add_conf_proc( 'makerss', @makerss_conf_label, 'update' ) do
if @mode == 'saveconf' then
%w( hidecontent shortdesc comment_link no_comments).each do |s|
item = "makerss.#{s}"
@conf[item] = ( 't' == @cgi.params[item][0] )
end
end
@makerss_rsses.each do |rss|
if rss.class == MakeRssFull then
@makerss_full = rss
elsif rss.class == MakeRssNoComments
@makerss_no_comments = rss
end
end
makerss_conf_html
end
add_edit_proc do
checked = if @cgi.params['makerss_update'][0] == 'false' then
' checked'
elsif @date < (Time::now - 30*24*60*60) # older over a month
' checked'
else
''
end
r = <<-HTML
<div class="makerss"><label for="makerss_update">
<input type="checkbox" id="makerss_update" name="makerss_update" value="false"#{checked} tabindex="390">
#{@makerss_edit_label}
</label></div>
HTML
end
def replace_entities( text )
unless @xml_entity_table then
@xml_entity_table = {
' ' => ' ',
'¡' => '¡',
'¢' => '¢',
'£' => '£',
'¤' => '¤',
'¥' => '¥',
'¦' => '¦',
'§' => '§',
'¨' => '¨',
'©' => '©',
'ª' => 'ª',
'«' => '«',
'¬' => '¬',
'­' => '­',
'®' => '®',
'¯' => '¯',
'°' => '°',
'±' => '±',
'²' => '²',
'³' => '³',
'´' => '´',
'µ' => 'µ',
'¶' => '¶',
'·' => '·',
'¸' => '¸',
'¹' => '¹',
'º' => 'º',
'»' => '»',
'¼' => '¼',
'½' => '½',
'¾' => '¾',
'¿' => '¿',
'À' => 'À',
'Á' => 'Á',
'Â' => 'Â',
'Ã' => 'Ã',
'Ä' => 'Ä',
'Å' => 'Å',
'&Aelig;' => 'Æ',
'Ç' => 'Ç',
'È' => 'È',
'É' => 'É',
'Ê' => 'Ê',
'Ë' => 'Ë',
'Ì' => 'Ì',
'Í' => 'Í',
'Î' => 'Î',
'Ï' => 'Ï',
'Ð' => 'Ð',
'Ñ' => 'Ñ',
'Ò' => 'Ò',
'Ó' => 'Ó',
'Ô' => 'Ô',
'Õ' => 'Õ',
'Ö' => 'Ö',
'×' => '×',
'Ø' => 'Ø',
'Ù' => 'Ù',
'Ú' => 'Ú',
'Û' => 'Û',
'Ü' => 'Ü',
'Ý' => 'Ý',
'Þ' => 'Þ',
'ß' => 'ß',
'à' => 'à',
'á' => 'á',
'â' => 'â',
'ã' => 'ã',
'ä' => 'ä',
'å' => 'å',
'æ' => 'æ',
'ç' => 'ç',
'è' => 'è',
'é' => 'é',
'ê' => 'ê',
'ë' => 'ë',
'ì' => 'ì',
'í' => 'í',
'î' => 'î',
'ï' => 'ï',
'ð' => 'ð',
'ñ' => 'ñ',
'ò' => 'ò',
'ó' => 'ó',
'ô' => 'ô',
'õ' => 'õ',
'ö' => 'ö',
'÷' => '÷',
'ø' => 'ø',
'ù' => 'ù',
'ú' => 'ú',
'û' => 'û',
'ü' => 'ü',
'ý' => 'ý',
'þ' => 'þ',
'ÿ' => 'ÿ',
'œ' => 'Œ',
'œ' => 'œ',
'š' => 'Š',
'š' => 'š',
'ÿ' => 'Ÿ',
'ˆ' => 'ˆ',
'˜' => '˜',
' ' => ' ',
' ' => ' ',
' ' => ' ',
'‌' => '‌',
'‍' => '‍',
'‎' => '‎',
'‏' => '‏',
'–' => '–',
'—' => '—',
'‘' => '‘',
'’' => '’',
'‚' => '‚',
'“' => '“',
'”' => '”',
'„' => '„',
'†' => '†',
'‡' => '‡',
'‰' => '‰',
'‹' => '‹',
'›' => '›',
'€' => '€',
'ƒ' => 'ƒ',
'Α' => 'Α',
'Β' => 'Β',
'Γ' => 'Γ',
'Δ' => 'Δ',
'Ε' => 'Ε',
'Ζ' => 'Ζ',
'Η' => 'Η',
'Θ' => 'Θ',
'Ι' => 'Ι',
'Κ' => 'Κ',
'Λ' => 'Λ',
'Μ' => 'Μ',
'Ν' => 'Ν',
'Ξ' => 'Ξ',
'Ο' => 'Ο',
'Π' => 'Π',
'Ρ' => 'Ρ',
'Σ' => 'Σ',
'Τ' => 'Τ',
'Υ' => 'Υ',
'Φ' => 'Φ',
'Χ' => 'Χ',
'Ψ' => 'Ψ',
'Ω' => 'Ω',
'α' => 'α',
'β' => 'β',
'γ' => 'γ',
'δ' => 'δ',
'ε' => 'ε',
'ζ' => 'ζ',
'η' => 'η',
'θ' => 'θ',
'ι' => 'ι',
'κ' => 'κ',
'λ' => 'λ',
'μ' => 'μ',
'ν' => 'ν',
'ξ' => 'ξ',
'ο' => 'ο',
'π' => 'π',
'ρ' => 'ρ',
'ς' => 'ς',
'σ' => 'σ',
'τ' => 'τ',
'υ' => 'υ',
'φ' => 'φ',
'χ' => 'χ',
'ψ' => 'ψ',
'ω' => 'ω',
'ϑ' => 'ϑ',
'ϒ' => 'ϒ',
'ϖ' => 'ϖ',
'•' => '•',
'…' => '…',
'′' => '′',
'′' => '″',
'‾' => '‾',
'⁄' => '⁄',
'℘' => '℘',
'ℑ' => 'ℑ',
'ℜ' => 'ℜ',
'™' => '™',
'ℵ' => 'ℵ',
'←' => '←',
'→' => '→',
'↓' => '↓',
'↔' => '↔',
'↵' => '↵',
'⇐' => '⇐',
'⇑' => '⇑',
'⇒' => '⇒',
'⇓' => '⇓',
'⇔' => '⇔',
'∀' => '∀',
'∂' => '∂',
'∃' => '∃',
'∅' => '∅',
'∇' => '∇',
'∈' => '∈',
'∉' => '∉',
'∋' => '∋',
'∏' => '∏',
'∑' => '∑',
'−' => '−',
'∗' => '∗',
'√' => '√',
'∝' => '∝',
'∞' => '∞',
'∠' => '∠',
'∧' => '∧',
'∨' => '∨',
'∩' => '∩',
'∪' => '∪',
'∫' => '∫',
'∴' => '∴',
'∼' => '∼',
'≅' => '≅',
'≈' => '≈',
'≠' => '≠',
'≡' => '≡',
'≤' => '≤',
'≥' => '≥',
'⊂' => '⊂',
'⊃' => '⊃',
'⊄' => '⊄',
'⊆' => '⊆',
'⊇' => '⊇',
'⊕' => '⊕',
'⊗' => '⊗',
'⊥' => '⊥',
'⋅' => '⋅',
'⌈' => '⌈',
'⌉' => '⌉',
'⌊' => '⌊',
'⌋' => '⌋',
'⟨' => '〈',
'⟩' => '〉',
'◊' => '◊',
'♠' => '♠',
'♣' => '♣',
'♥' => '♥',
'♦' => '♦'
}
end
text.gsub( /&[a-z]+;/im ) do |e|
@xml_entity_table[e] || e
end
end
# Copied from below which includes some tests
# http://github.com/zunda/ruby-absolutify/tree/master
def absolutify(html, baseurl)
@@_absolutify_attr_regexp ||= Hash.new
baseuri = URI.parse(URI.encode(baseurl))
r = html.gsub(%r|<\S[^>]*/?>|) do |tag|
type = tag.scan(/\A<(\S+)/)[0][0].downcase
if attr = {'a' => 'href', 'img' => 'src'}[type]
@@_absolutify_attr_regexp[attr] ||= %r|(.*#{attr}\s*=\s*)(['"]?)([^\2>]+?)(\2.*)|im
m = tag.match(@@_absolutify_attr_regexp[attr])
unless m.nil?
prefix = m[1] + m[2]
location = m[3]
postfix = m[4]
begin
uri = URI.parse(location)
if uri.relative?
location = (baseuri + location).to_s
elsif not uri.host and uri.path
path = uri.path
path += '?' + uri.query if uri.query
path += '#' + uri.fragment if uri.fragment
location = (baseuri + path).to_s
end
tag = prefix + location + postfix
rescue URI::InvalidURIError
end
end
end
tag
end
return r
end
# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End:
|