@@ -900,7 +900,7 @@ void DocRef::parse()
900900
901901// ---------------------------------------------------------------------------
902902
903- DocCite::DocCite (DocParser *parser,DocNodeVariant *parent,const QCString &target,const QCString &) : DocNode(parser,parent)
903+ DocCite::DocCite (DocParser *parser,DocNodeVariant *parent,const QCString &target,const QCString &,CiteInfoOption opt ) : DocNode(parser,parent)
904904{
905905 size_t numBibFiles = Config_getList (CITE_BIB_FILES).size ();
906906 // printf("DocCite::DocCite(target=%s)\n",qPrint(target));
@@ -909,17 +909,17 @@ DocCite::DocCite(DocParser *parser,DocNodeVariant *parent,const QCString &target
909909 const CitationManager &ct = CitationManager::instance ();
910910 const CiteInfo *cite = ct.find (target);
911911 // printf("cite=%p text='%s' numBibFiles=%d\n",cite,cite?qPrint(cite->text):"<null>",numBibFiles);
912+ m_option = opt;
913+ m_target = target;
912914 if (numBibFiles>0 && cite && !cite->text ().isEmpty ()) // ref to citation
913915 {
914- m_text = cite->text ();
915916 m_ref = " " ;
916917 m_anchor = ct.anchorPrefix ()+cite->label ();
917918 m_file = convertNameToFile (ct.fileName (),FALSE ,TRUE );
918919 // printf("CITE ==> m_text=%s,m_ref=%s,m_file=%s,m_anchor=%s\n",
919920 // qPrint(m_text),qPrint(m_ref),qPrint(m_file),qPrint(m_anchor));
920921 return ;
921922 }
922- m_text = target;
923923 if (numBibFiles==0 )
924924 {
925925 warn_doc_error (parser->context .fileName ,parser->tokenizer .getLineNr ()," \\ cite command found but no bib files specified via CITE_BIB_FILES!" );
@@ -936,6 +936,27 @@ DocCite::DocCite(DocParser *parser,DocNodeVariant *parent,const QCString &target
936936 }
937937}
938938
939+ QCString DocCite::getText () const
940+ {
941+ QCString txt;
942+ auto opt = m_option;
943+ const CitationManager &ct = CitationManager::instance ();
944+ const CiteInfo *citeInfo = ct.find (m_target);
945+
946+ if (!opt.noPar ()) txt += " [" ;
947+
948+ if (citeInfo)
949+ {
950+ if (opt.isNumber ()) txt += citeInfo->text ();
951+ else if (opt.isShortAuthor ()) txt += citeInfo->shortAuthor ();
952+ else if (opt.isYear ()) txt += citeInfo->year ();
953+ }
954+
955+ if (!opt.noPar ()) txt += " ]" ;
956+ return txt;
957+ }
958+
959+
939960// ---------------------------------------------------------------------------
940961
941962DocLink::DocLink (DocParser *parser,DocNodeVariant *parent,const QCString &target) : DocCompoundNode(parser,parent)
@@ -3304,31 +3325,104 @@ Token DocPara::handleParamSection(const QCString &cmdName,
33043325void DocPara::handleCite (char cmdChar,const QCString &cmdName)
33053326{
33063327 AUTO_TRACE ();
3328+ QCString saveCmdName = cmdName;
33073329 // get the argument of the cite command.
33083330 Token tok=parser ()->tokenizer .lex ();
3309- if (!tok.is (TokenRetval::TK_WHITESPACE))
3331+
3332+ CiteInfoOption option;
3333+ if (tok.is (TokenRetval::TK_WORD) && parser ()->context .token ->name ==" {" )
3334+ {
3335+ parser ()->tokenizer .setStateOptions ();
3336+ parser ()->tokenizer .lex ();
3337+ StringVector optList=split (parser ()->context .token ->name .str ()," ," );
3338+ for (auto const &opt : optList)
3339+ {
3340+ if (opt == " number" )
3341+ {
3342+ if (!option.isUnknown ())
3343+ {
3344+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Multiple options specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3345+ }
3346+ else
3347+ {
3348+ option = CiteInfoOption::makeNumber ();
3349+ }
3350+ }
3351+ else if (opt == " year" )
3352+ {
3353+ if (!option.isUnknown ())
3354+ {
3355+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Multiple options specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3356+ }
3357+ else
3358+ {
3359+ option = CiteInfoOption::makeYear ();
3360+ }
3361+ }
3362+ else if (opt == " shortauthor" )
3363+ {
3364+ if (!option.isUnknown ())
3365+ {
3366+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Multiple options specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3367+ }
3368+ else
3369+ {
3370+ option = CiteInfoOption::makeShortAuthor ();
3371+ }
3372+ }
3373+ else if (opt == " nopar" )
3374+ {
3375+ option.setNoPar ();
3376+ }
3377+ else if (opt == " nocite" )
3378+ {
3379+ option.setNoCite ();
3380+ }
3381+ else
3382+ {
3383+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Unkown option specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3384+ }
3385+ }
3386+
3387+ if (option.isUnknown ()) option = CiteInfoOption::makeNumber ();
3388+
3389+ parser ()->tokenizer .setStatePara ();
3390+ tok=parser ()->tokenizer .lex ();
3391+ if (!tok.is (TokenRetval::TK_WHITESPACE))
3392+ {
3393+ warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," expected whitespace after \\ {} command" ,
3394+ saveCmdName);
3395+ return ;
3396+ }
3397+ }
3398+ else if (!tok.is (TokenRetval::TK_WHITESPACE))
33103399 {
33113400 warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," expected whitespace after '{:c}{}' command" ,
3312- cmdChar,cmdName );
3401+ cmdChar,saveCmdName );
33133402 return ;
33143403 }
3404+ else
3405+ {
3406+ option = CiteInfoOption::makeNumber ();
3407+ }
3408+
33153409 parser ()->tokenizer .setStateCite ();
33163410 tok=parser ()->tokenizer .lex ();
33173411 if (tok.is_any_of (TokenRetval::TK_NONE,TokenRetval::TK_EOF))
33183412 {
3319- warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," unexpected end of comment block while parsing the "
3320- " argument of command '{:c}{}'" ,cmdChar,cmdName );
3413+ warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," THE ONE unexpected end of comment block while parsing the "
3414+ " argument of command '{:c}{}'" ,cmdChar,saveCmdName );
33213415 return ;
33223416 }
33233417 else if (!tok.is_any_of (TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD))
33243418 {
33253419 warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," unexpected token {} as the argument of '{:c}{}'" ,
3326- tok.to_string (),cmdChar,cmdName );
3420+ tok.to_string (),cmdChar,saveCmdName );
33273421 return ;
33283422 }
33293423 parser ()->context .token ->sectionId = parser ()->context .token ->name ;
33303424 children ().append <DocCite>(
3331- parser (),thisVariant (),parser ()->context .token ->name ,parser ()->context .context );
3425+ parser (),thisVariant (),parser ()->context .token ->name ,parser ()->context .context ,option );
33323426
33333427 parser ()->tokenizer .setStatePara ();
33343428}
0 commit comments