1 package org.apache.maven.doxia.module.confluence.parser;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.doxia.parser.ParseException;
23 import org.apache.maven.doxia.util.ByLineSource;
24
25
26
27
28
29
30
31
32 public class DefinitionListBlockParser
33 implements BlockParser
34 {
35 static final String LS = System.getProperty( "line.separator" );
36
37
38 public boolean accept( String line, ByLineSource source )
39 {
40 return ( line.startsWith( "{note" ) || line.startsWith( "{tip" )
41 || line.startsWith( "{info" ) || line.startsWith( "{quote" ) );
42 }
43
44
45 public Block visit( String line, ByLineSource source )
46 throws ParseException
47 {
48 StringBuffer text = new StringBuffer();
49 StringBuffer title = new StringBuffer();
50
51 int index = line.indexOf( "title=" );
52
53 if ( index >= 0 )
54 {
55 line = line.substring( index + 6 );
56
57 while ( !( line.indexOf( "}" ) >= 0 ) && line != null )
58 {
59 append( title, line );
60 line = source.getNextLine();
61 }
62
63 if ( line != null )
64 {
65 append( title, line.substring( 0, line.indexOf( "}" ) ) );
66 }
67 }
68
69 while ( ( line = source.getNextLine() ) != null )
70 {
71 if ( line.startsWith( "{note" ) || line.startsWith( "{tip" )
72 || line.startsWith( "{info" ) || line.startsWith( "{quote" ) )
73 {
74 break;
75 }
76
77 append( text, line );
78 }
79
80 return new DefinitionListBlock( title.toString(), text.toString() );
81 }
82
83 private void append( StringBuffer title, String line )
84 {
85 if ( title.length() > 0 )
86 {
87 title.append( " " );
88 }
89
90 title.append( line.trim() );
91 }
92 }