/docs/manual/lib/editorial-filter.rb

https://bitbucket.org/laika/thingfish · Ruby · 64 lines · 28 code · 13 blank · 23 comment · 1 complexity · 303bde00481dcf7b0a59460718d7729f MD5 · raw file

  1. #!/usr/bin/env ruby
  2. #
  3. # A manual filter to highlight content that needs editorial help.
  4. #
  5. # Authors:
  6. # * Michael Granger <ged@FaerieMUD.org>
  7. #
  8. #
  9. ### Avoid declaring the class if the tasklib hasn't been loaded yet.
  10. unless Object.const_defined?( :Manual )
  11. raise LoadError, "not intended for standalone use: try the 'manual.rb' rake tasklib"
  12. end
  13. ### A filter for making editorial marks in manual content.
  14. ###
  15. ### Editorial marks are XML processing instructions. There are several available types of
  16. ### marks:
  17. ###
  18. ### <?ed "This is an editor's note." ?>
  19. ### <?ed verify:"this content needs checking or verification" ?>
  20. ###
  21. class EditorialFilter < Manual::Page::Filter
  22. # PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
  23. LinkPI = %r{
  24. <\?
  25. ed # Instruction Target
  26. \s+
  27. (\w+?) # type of editorial mark [$1]
  28. :? # optional colon
  29. "
  30. (.*?) # content that should be edited [$2]
  31. "
  32. \s*
  33. \?>
  34. }x
  35. ######
  36. public
  37. ######
  38. ### Process the given +source+ for <?ed ... ?> processing-instructions
  39. def process( source, page, metadata )
  40. return source.gsub( LinkPI ) do |match|
  41. # Grab the tag values
  42. mark_type = $1
  43. content = $2
  44. self.generate_mark( page, mark_type, content )
  45. end
  46. end
  47. ### Create an HTML fragment from the parsed LinkPI.
  48. def generate_mark( current_page, mark_type, content )
  49. return "%%(editorial %s-mark)%s%%" % [ mark_type, content ]
  50. end
  51. end