/docs/manual/lib/editorial-filter.rb
Ruby | 64 lines | 28 code | 13 blank | 23 comment | 1 complexity | 303bde00481dcf7b0a59460718d7729f MD5 | raw file
Possible License(s): BSD-3-Clause
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
10### Avoid declaring the class if the tasklib hasn't been loaded yet.
11unless Object.const_defined?( :Manual )
12 raise LoadError, "not intended for standalone use: try the 'manual.rb' rake tasklib"
13end
14
15
16
17### A filter for making editorial marks in manual content.
18###
19### Editorial marks are XML processing instructions. There are several available types of
20### marks:
21###
22### <?ed "This is an editor's note." ?>
23### <?ed verify:"this content needs checking or verification" ?>
24###
25class EditorialFilter < Manual::Page::Filter
26
27 # PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
28 LinkPI = %r{
29 <\?
30 ed # Instruction Target
31 \s+
32 (\w+?) # type of editorial mark [$1]
33 :? # optional colon
34 "
35 (.*?) # content that should be edited [$2]
36 "
37 \s*
38 \?>
39 }x
40
41
42 ######
43 public
44 ######
45
46 ### Process the given +source+ for <?ed ... ?> processing-instructions
47 def process( source, page, metadata )
48 return source.gsub( LinkPI ) do |match|
49 # Grab the tag values
50 mark_type = $1
51 content = $2
52
53 self.generate_mark( page, mark_type, content )
54 end
55 end
56
57
58 ### Create an HTML fragment from the parsed LinkPI.
59 def generate_mark( current_page, mark_type, content )
60 return "%%(editorial %s-mark)%s%%" % [ mark_type, content ]
61 end
62
63
64end