53
53
#include " fileinfo.h"
54
54
#include " utf8.h"
55
55
56
+ enum class ExplicitPage
57
+ {
58
+ notExplicit,
59
+ explicitPage,
60
+ explicitMainPage
61
+ };
62
+
56
63
#if !defined(NDEBUG)
57
64
#define ENABLE_TRACING
58
65
#endif
@@ -135,6 +142,11 @@ class Trace
135
142
m_resultSet = true ;
136
143
m_resultValue = b ? " true" : " false" ;
137
144
}
145
+ void setResult (ExplicitPage ep)
146
+ {
147
+ m_resultSet = true ;
148
+ m_resultValue = QCString ().setNum (static_cast <int >(ep));
149
+ }
138
150
void setResult (int i)
139
151
{
140
152
m_resultSet = true ;
@@ -194,7 +206,6 @@ int Trace::s_indent = 0;
194
206
(data[i]==' (' || data[i]==' {' || data[i]==' [' || (data[i]==' <' && data[i+1 ]!=' /' ) || \
195
207
data[i]==' \\ ' || \
196
208
data[i]==' @' )
197
-
198
209
// ----------
199
210
200
211
struct TableCell
@@ -2852,8 +2863,11 @@ QCString Markdown::processBlocks(const QCString &s,const int indent)
2852
2863
return m_out.get ();
2853
2864
}
2854
2865
2855
- /* * returns TRUE if input string docs starts with \@page or \@mainpage command */
2856
- static bool isExplicitPage (const QCString &docs)
2866
+ /* * returns ExplicitPage::explicitPage in case input string docs starts with page command
2867
+ * returns ExplicitPage::explicitMainPage in case input string docs starts with mainpage comand
2868
+ * returns ExplicitPage::notExplicit otherwise
2869
+ */
2870
+ static ExplicitPage isExplicitPage (const QCString &docs)
2857
2871
{
2858
2872
TRACE (docs);
2859
2873
int i=0 ;
@@ -2870,12 +2884,20 @@ static bool isExplicitPage(const QCString &docs)
2870
2884
(qstrncmp (&data[i+1 ]," page " ,5 )==0 || qstrncmp (&data[i+1 ]," mainpage" ,8 )==0 )
2871
2885
)
2872
2886
{
2873
- TRACE_RESULT (TRUE );
2874
- return TRUE ;
2887
+ if (qstrncmp (&data[i+1 ]," page " ,5 )==0 )
2888
+ {
2889
+ TRACE_RESULT (ExplicitPage::explicitPage);
2890
+ return ExplicitPage::explicitPage;
2891
+ }
2892
+ else
2893
+ {
2894
+ TRACE_RESULT (ExplicitPage::explicitMainPage);
2895
+ return ExplicitPage::explicitMainPage;
2896
+ }
2875
2897
}
2876
2898
}
2877
- TRACE_RESULT (FALSE );
2878
- return FALSE ;
2899
+ TRACE_RESULT (ExplicitPage::notExplicit );
2900
+ return ExplicitPage::notExplicit ;
2879
2901
}
2880
2902
2881
2903
QCString Markdown::extractPageTitle (QCString &docs,QCString &id, int &prepend)
@@ -3110,30 +3132,67 @@ void MarkdownOutlineParser::parseInput(const QCString &fileName,
3110
3132
QCString mdfileAsMainPage = Config_getString (USE_MDFILE_AS_MAINPAGE);
3111
3133
bool wasEmpty = id.isEmpty ();
3112
3134
if (wasEmpty) id = markdownFileNameToId (fileName);
3113
- if (! isExplicitPage (docs))
3135
+ switch ( isExplicitPage (docs))
3114
3136
{
3115
- if (!mdfileAsMainPage.isEmpty () &&
3116
- (fn==mdfileAsMainPage || // name reference
3117
- FileInfo (fileName.str ()).absFilePath ()==
3118
- FileInfo (mdfileAsMainPage.str ()).absFilePath ()) // file reference with path
3119
- )
3120
- {
3121
- docs.prepend (" @anchor " + id + " \\ ilinebr " );
3122
- docs.prepend (" @mainpage " +title+" \\ ilinebr " );
3123
- }
3124
- else if (id==" mainpage" || id==" index" )
3125
- {
3126
- if (title.isEmpty ()) title = titleFn;
3127
- docs.prepend (" @anchor " + id + " \\ ilinebr " );
3128
- docs.prepend (" @mainpage " +title+" \\ ilinebr " );
3129
- }
3130
- else
3131
- {
3132
- if (title.isEmpty ()) {title = titleFn;prepend=0 ;}
3133
- if (!wasEmpty) docs.prepend (" @anchor " + markdownFileNameToId (fileName) + " \\ ilinebr " );
3134
- docs.prepend (" @page " +id+" " +title+" \\ ilinebr " );
3135
- }
3136
- for (int i = 0 ; i < prepend; i++) docs.prepend (" \n " );
3137
+ case ExplicitPage::notExplicit:
3138
+ if (!mdfileAsMainPage.isEmpty () &&
3139
+ (fn==mdfileAsMainPage || // name reference
3140
+ FileInfo (fileName.str ()).absFilePath ()==
3141
+ FileInfo (mdfileAsMainPage.str ()).absFilePath ()) // file reference with path
3142
+ )
3143
+ {
3144
+ docs.prepend (" @anchor " + id + " \\ ilinebr " );
3145
+ docs.prepend (" @mainpage " +title+" \\ ilinebr " );
3146
+ }
3147
+ else if (id==" mainpage" || id==" index" )
3148
+ {
3149
+ if (title.isEmpty ()) title = titleFn;
3150
+ docs.prepend (" @anchor " + id + " \\ ilinebr " );
3151
+ docs.prepend (" @mainpage " +title+" \\ ilinebr " );
3152
+ }
3153
+ else
3154
+ {
3155
+ if (title.isEmpty ()) {title = titleFn;prepend=0 ;}
3156
+ if (!wasEmpty) docs.prepend (" @anchor " + markdownFileNameToId (fileName) + " \\ ilinebr " );
3157
+ docs.prepend (" @page " +id+" " +title+" \\ ilinebr " );
3158
+ }
3159
+ for (int i = 0 ; i < prepend; i++) docs.prepend (" \n " );
3160
+ break ;
3161
+ case ExplicitPage::explicitPage:
3162
+ {
3163
+ static const reg::Ex re (R"( [\\@]page[ \t]*)" );
3164
+ static const reg::Ex re0 (R"( ^[a-z_A-Z\x80-\xFF])" ); // from LABELID, see commentscan.l
3165
+ static const reg::Ex re1 (R"( [a-z_A-Z\x80-\xFF][a-z_A-Z0-9\x80-\xFF\-]*)" ); // LABELID, see commentscan.l
3166
+ static const reg::Ex re2 (R"( \n)" );
3167
+ reg::Match match;
3168
+ reg::Match match1;
3169
+ std::string t;
3170
+ std::string t1;
3171
+ t = docs.str ();
3172
+ reg::search (t,match,re);
3173
+ t1 = match.suffix ().str ();
3174
+
3175
+ // check first character in [a-z_A-Z\x80-\xFF], so we have a potential label
3176
+ if (reg::search (t1,match1,re0))
3177
+ {
3178
+ docs = match.prefix ().str ();
3179
+ docs += match.str () + markdownFileNameToId (fileName);
3180
+ t = match.suffix ().str ();
3181
+
3182
+ reg::search (t,match,re1);
3183
+ QCString saveAnchor = match.str ();
3184
+ t = match.suffix ().str ();
3185
+ reg::search (t,match,re2);
3186
+ docs += match.prefix ().str ();
3187
+ docs += " \\ ilinebr @anchor " ;
3188
+ docs += saveAnchor;
3189
+ docs += match.str ();
3190
+ docs += match.suffix ().str ();
3191
+ }
3192
+ }
3193
+ break ;
3194
+ case ExplicitPage::explicitMainPage:
3195
+ break ;
3137
3196
}
3138
3197
int lineNr=1 ;
3139
3198
0 commit comments