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 public class DefinitionListBlockParser
32 implements BlockParser
33 {
34 static final String LS = System.getProperty( "line.separator" );
35
36
37 public boolean accept( String line, ByLineSource source )
38 {
39 return ( line.startsWith( "{note" ) || line.startsWith( "{tip" )
40 || line.startsWith( "{info" ) || line.startsWith( "{quote" ) );
41 }
42
43
44 public Block visit( String line, ByLineSource source )
45 throws ParseException
46 {
47 StringBuilder text = new StringBuilder();
48 StringBuilder title = new StringBuilder();
49
50 int index = line.indexOf( "title=" );
51
52 if ( index >= 0 )
53 {
54 line = line.substring( index + 6 );
55
56 while ( !( line.contains( "}" ) ) && line != null )
57 {
58 append( title, line );
59 line = source.getNextLine();
60 }
61
62 if ( line != null )
63 {
64 append( title, line.substring( 0, line.indexOf( "}" ) ) );
65 }
66 }
67
68 while ( ( line = source.getNextLine() ) != null )
69 {
70 if ( line.startsWith( "{note" ) || line.startsWith( "{tip" )
71 || line.startsWith( "{info" ) || line.startsWith( "{quote" ) )
72 {
73 break;
74 }
75
76 append( text, line );
77 }
78
79 return new DefinitionListBlock( title.toString(), text.toString() );
80 }
81
82 private void append( StringBuilder title, String line )
83 {
84 if ( title.length() > 0 )
85 {
86 title.append( " " );
87 }
88
89 title.append( line.trim() );
90 }
91 }