@ -41,7 +41,8 @@ class substitution_plugin {
@@ -41,7 +41,8 @@ class substitution_plugin {
std : : vector < std : : string > get_arguments ( const std : : string & invocation , int numargs ) ;
/* Must be globally unique: invocation name in the template */
inline static const std : : string hook_name = " invalid " ;
virtual std : : string hook_name ( ) = 0 ;
/* Must return lengh of replaced text */
virtual int perform_substitution ( int start , int end , const std : : string & invocation ,
@ -115,7 +116,7 @@ std::vector<std::string> substitution_plugin::get_arguments(const std::string &i
@@ -115,7 +116,7 @@ std::vector<std::string> substitution_plugin::get_arguments(const std::string &i
class file_transclude_plugin : public substitution_plugin {
public :
inline static const std : : string hook_name = " include " ;
std : : string hook_name ( ) override { return " include " ; } ;
int perform_substitution ( int start , int end , const std : : string & invocation ,
std : : string & file_text ,
@ -148,7 +149,7 @@ class file_transclude_plugin : public substitution_plugin {
@@ -148,7 +149,7 @@ class file_transclude_plugin : public substitution_plugin {
class mmd_snippet_transclude_plugin : public substitution_plugin {
public :
inline static const std : : string hook_name = " md " ;
std : : string hook_name ( ) override { return " md " ; } ;
int perform_substitution ( int start , int end , const std : : string & invocation ,
std : : string & file_text ,
@ -171,7 +172,7 @@ class mmd_snippet_transclude_plugin : public substitution_plugin {
@@ -171,7 +172,7 @@ class mmd_snippet_transclude_plugin : public substitution_plugin {
class variable_transclude_plugin final : public substitution_plugin {
public :
inline static const std : : string hook_name = " " ;
std : : string hook_name ( ) override { return " " ; } ;
int perform_substitution ( int start , int end , const std : : string & invocation ,
std : : string & file_text ,
@ -244,7 +245,7 @@ class ifdef_plugin : public substitution_plugin {
@@ -244,7 +245,7 @@ class ifdef_plugin : public substitution_plugin {
public :
inline static const std : : string hook_name = " ifdef " ;
std : : string hook_name ( ) override { return " ifdef " ; } ;
int perform_substitution ( int start , int end , const std : : string & invocation ,
std : : string & file_text ,
@ -271,7 +272,7 @@ class ifdef_plugin : public substitution_plugin {
@@ -271,7 +272,7 @@ class ifdef_plugin : public substitution_plugin {
class comment_plugin : public substitution_plugin {
public :
inline static const std : : string hook_name = " # " ;
std : : string hook_name ( ) override { return " # " ; } ;
int perform_substitution ( int start , int end , const std : : string & invocation ,
std : : string & file_text ,
@ -290,7 +291,7 @@ class comment_plugin : public substitution_plugin {
@@ -290,7 +291,7 @@ class comment_plugin : public substitution_plugin {
class ifndef_plugin : public ifdef_plugin {
public :
inline static const std : : string hook_name = " ifndef " ;
std : : string hook_name ( ) override { return " ifndef " ; } ;
int perform_substitution ( int start , int end , const std : : string & invocation ,
std : : string & file_text ,
@ -422,7 +423,7 @@ class file_index_plugin : public substitution_plugin {
@@ -422,7 +423,7 @@ class file_index_plugin : public substitution_plugin {
public :
inline static const std : : string hook_name = " postlist " ;
std : : string hook_name ( ) override { return " postlist " ; } ;
int perform_substitution ( int start , int end , const std : : string & invocation ,
std : : string & file_text ,
@ -720,7 +721,7 @@ std::multimap<time_t, blog_item> get_sorted_post_list(const std::string &cs_dire
@@ -720,7 +721,7 @@ std::multimap<time_t, blog_item> get_sorted_post_list(const std::string &cs_dire
class rss_feed_plugin : public s2_substitution_plugin {
public :
inline static const std : : string hook_name = " feed " ;
std : : string hook_name ( ) override { return " feed " ; } ;
int perform_substitution ( int start , int end , const std : : string & invocation ,
@ -778,7 +779,7 @@ class rss_feed_plugin : public s2_substitution_plugin {
@@ -778,7 +779,7 @@ class rss_feed_plugin : public s2_substitution_plugin {
class microblog_plugin : public s2_substitution_plugin {
public :
inline static const std : : string hook_name = " microblog " ;
std : : string hook_name ( ) override { return " microblog " ; } ;
int perform_substitution ( int start , int end , const std : : string & invocation ,
@ -839,6 +840,7 @@ class templater {
@@ -839,6 +840,7 @@ class templater {
public :
templater ( ) {
/*
substitution_commands [ variable_transclude_plugin : : hook_name ] = new variable_transclude_plugin { } ;
substitution_commands [ file_index_plugin : : hook_name ] = new file_index_plugin { } ;
substitution_commands [ ifdef_plugin : : hook_name ] = new ifdef_plugin { } ;
@ -848,20 +850,27 @@ class templater {
@@ -848,20 +850,27 @@ class templater {
s2_substitution_commands [ rss_feed_plugin : : hook_name ] = new rss_feed_plugin { } ;
s2_substitution_commands [ microblog_plugin : : hook_name ] = new microblog_plugin { } ;
*/
}
templater ( std : : vector < substitution_plugin * > s1 , std : : vector < s2_substitution_plugin * > s2 ) {
for ( auto s : s1 ) {
substitution_commands . insert ( { s - > hook_name , s } ) ;
substitution_commands . insert ( { s - > hook_name ( ) , s } ) ;
}
for ( auto s : s2 ) {
s2_substitution_commands . insert ( { s - > hook_name , s } ) ;
s2_substitution_commands . insert ( { s - > hook_name ( ) , s } ) ;
}
for ( auto s : substitution_commands ) {
spdlog : : info ( " {}: thing " , s . first ) ;
}
}
struct done_subtitution_options {
int num ;
bool recurse = tru e;
bool recurse = fals e;
} ;
done_subtitution_options
@ -871,7 +880,6 @@ class templater {
@@ -871,7 +880,6 @@ class templater {
std : : optional < const std : : map < fs : : path , blog_item > > pages )
{
spdlog : : info ( " invoc: {} at {} " , invocation , properties . at ( " current_file " ) ) ;
assert ( substitution_commands . size ( ) > 0 ) ;
std : : string command_name = invocation . substr ( 0 , invocation . find ( " : " ) ) ;
@ -928,6 +936,7 @@ class templater {
@@ -928,6 +936,7 @@ class templater {
}
int search_from = next + TEMPLATE_CODE_START . length ( ) ;
int loops = 0 ;
while ( next_start < end ) {
// we found a nested tag
@ -967,11 +976,15 @@ class templater {
@@ -967,11 +976,15 @@ class templater {
end + = TEMPLATE_CODE_END . length ( ) ;
auto subst = do_substitution ( next , end , invocation , text , properties , pages ) ;
next + = subst . num ;
if ( ! subst . num ) {
// unsuccesful
next + = TEMPLATE_CODE_START . length ( ) ;
// spdlog::info("Substitution failed, {} in {}", invocation, properties.at("current_file"));
} else if ( true | | properties . count ( " notemplating " ) | | ! subst . recurse ) {
// next = end;
// break;
// spdlog::info("Substitution failed, {} in {}", nvocation, properties.at("current_file"));
} else if ( properties . count ( " notemplating " ) | | ! subst . recurse ) {
// do not recurse into substituted content
next + = subst . num ;
}