Avoid anchor for label which determined creation of the new file and is already included in filename.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30099 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba
2004-10-26 17:10:49 +00:00
parent 6848729f2b
commit ae6c0ccf26

View File

@@ -2,7 +2,7 @@
// Name: htmlutil.cpp // Name: htmlutil.cpp
// Purpose: Converts Latex to HTML // Purpose: Converts Latex to HTML
// Author: Julian Smart // Author: Julian Smart
// Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support // Modified by: Wlodzimierz ABX Skiba 2003/2004 Unicode support
// Ron Lee // Ron Lee
// Created: 7.9.93 // Created: 7.9.93
// RCS-ID: $Id$ // RCS-ID: $Id$
@@ -30,6 +30,8 @@
#include "tex2rtf.h" #include "tex2rtf.h"
#include "table.h" #include "table.h"
#define HTML_FILENAME_PATTERN _T("%s_%s.html")
#if !WXWIN_COMPATIBILITY_2_4 #if !WXWIN_COMPATIBILITY_2_4
static inline wxChar* copystring(const wxChar* s) static inline wxChar* copystring(const wxChar* s)
{ return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); } { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
@@ -41,6 +43,8 @@ extern wxHashTable TexReferences;
extern void DecToHex(int, wxChar *); extern void DecToHex(int, wxChar *);
void GenerateHTMLIndexFile(wxChar *fname); void GenerateHTMLIndexFile(wxChar *fname);
bool PrimaryAnchorOfTheFile( wxChar *file, wxChar *label );
void GenerateHTMLWorkshopFiles(wxChar *fname); void GenerateHTMLWorkshopFiles(wxChar *fname);
void HTMLWorkshopAddToContents(int level, wxChar *s, wxChar *file); void HTMLWorkshopAddToContents(int level, wxChar *s, wxChar *file);
void HTMLWorkshopStartContents(); void HTMLWorkshopStartContents();
@@ -205,7 +209,7 @@ void ReopenFile(FILE **fd, wxChar **fileName, const wxChar *label)
{ {
if (fileId == 1) if (fileId == 1)
gs_filenames.Add(wxEmptyString); gs_filenames.Add(wxEmptyString);
wxSnprintf(buf, sizeof(buf), _T("%s_%s.html"), FileRoot, label); wxSnprintf(buf, sizeof(buf), HTML_FILENAME_PATTERN, FileRoot, label);
gs_filenames.Add(buf); gs_filenames.Add(buf);
} }
if (*fileName) delete[] *fileName; if (*fileName) delete[] *fileName;
@@ -476,7 +480,7 @@ void AddBrowseButtons(wxChar *upLabel, wxChar *upFilename,
if (upLabel && upFilename) if (upLabel && upFilename)
{ {
if (wxStrlen(upLabel) > 0) if ( (wxStrlen(upLabel) > 0) && !PrimaryAnchorOfTheFile(upFilename, upLabel) )
wxSnprintf(buf, sizeof(buf), wxSnprintf(buf, sizeof(buf),
_T("<A HREF=\"%s#%s\">%s</A> "), _T("<A HREF=\"%s#%s\">%s</A> "),
ConvertCase(upFilename), upLabel, upReference); ConvertCase(upFilename), upLabel, upReference);
@@ -501,9 +505,14 @@ void AddBrowseButtons(wxChar *upLabel, wxChar *upFilename,
if (previousLabel && previousFilename) if (previousLabel && previousFilename)
{ {
wxSnprintf(buf, sizeof(buf), if (PrimaryAnchorOfTheFile(previousFilename, previousLabel))
_T("<A HREF=\"%s#%s\">%s</A> "), wxSnprintf(buf, sizeof(buf),
ConvertCase(previousFilename), previousLabel, backReference); _T("<A HREF=\"%s\">%s</A> "),
ConvertCase(previousFilename), backReference);
else
wxSnprintf(buf, sizeof(buf),
_T("<A HREF=\"%s#%s\">%s</A> "),
ConvertCase(previousFilename), previousLabel, backReference);
if (wxStrcmp(previousLabel, _T("contents")) == 0) if (wxStrcmp(previousLabel, _T("contents")) == 0)
{ {
// TexOutput(_T("<NOFRAMES>")); // TexOutput(_T("<NOFRAMES>"));
@@ -550,9 +559,14 @@ void AddBrowseButtons(wxChar *upLabel, wxChar *upFilename,
if (nextLabel && nextFilename) if (nextLabel && nextFilename)
{ {
wxSnprintf(buf, sizeof(buf), if (PrimaryAnchorOfTheFile(nextFilename, nextLabel))
_T("<A HREF=\"%s#%s\">%s</A> "), wxSnprintf(buf, sizeof(buf),
ConvertCase(nextFilename), nextLabel, forwardReference); _T("<A HREF=\"%s\">%s</A> "),
ConvertCase(nextFilename), forwardReference);
else
wxSnprintf(buf, sizeof(buf),
_T("<A HREF=\"%s#%s\">%s</A> "),
ConvertCase(nextFilename), nextLabel, forwardReference);
TexOutput(buf); TexOutput(buf);
} }
else else
@@ -764,12 +778,18 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
lastTopic, lastFileName, // Last topic lastTopic, lastFileName, // Last topic
topicName, ChaptersName); // This topic topicName, ChaptersName); // This topic
wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), topicName); if(PrimaryAnchorOfTheFile(ChaptersName, topicName))
wxFprintf(Contents, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName));
else
wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), topicName);
if (htmlFrameContents && FrameContents) if (htmlFrameContents && FrameContents)
{ {
SetCurrentOutput(FrameContents); SetCurrentOutput(FrameContents);
wxFprintf(FrameContents, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName), topicName); if(PrimaryAnchorOfTheFile(ChaptersName, topicName))
wxFprintf(FrameContents, _T("\n<LI><A HREF=\"%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName));
else
wxFprintf(FrameContents, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName), topicName);
OutputCurrentSection(); OutputCurrentSection();
wxFprintf(FrameContents, _T("</A>\n")); wxFprintf(FrameContents, _T("</A>\n"));
} }
@@ -831,9 +851,19 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
SetCurrentOutputs(jumpFrom, Sections); SetCurrentOutputs(jumpFrom, Sections);
if (DocumentStyle == LATEX_ARTICLE) if (DocumentStyle == LATEX_ARTICLE)
wxFprintf(jumpFrom, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName), topicName); {
if(PrimaryAnchorOfTheFile(SectionsName, topicName))
wxFprintf(jumpFrom, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(SectionsName));
else
wxFprintf(jumpFrom, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName), topicName);
}
else else
wxFprintf(jumpFrom, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName), topicName); {
if(PrimaryAnchorOfTheFile(SectionsName, topicName))
wxFprintf(jumpFrom, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SectionsName));
else
wxFprintf(jumpFrom, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName), topicName);
}
wxFprintf(Sections, _T("\n<H2>")); wxFprintf(Sections, _T("\n<H2>"));
OutputCurrentSection(); OutputCurrentSection();
@@ -924,7 +954,10 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
topicName, SubsectionsName); // This topic topicName, SubsectionsName); // This topic
SetCurrentOutputs(Sections, Subsections); SetCurrentOutputs(Sections, Subsections);
wxFprintf(Sections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName), topicName); if(PrimaryAnchorOfTheFile(SubsectionsName, topicName))
wxFprintf(Sections, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsectionsName));
else
wxFprintf(Sections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName), topicName);
wxFprintf(Subsections, _T("\n<H3>")); wxFprintf(Subsections, _T("\n<H3>"));
OutputCurrentSection(); OutputCurrentSection();
@@ -1006,7 +1039,10 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
topicName, SubsubsectionsName); // This topic topicName, SubsubsectionsName); // This topic
SetCurrentOutputs(Subsections, Subsubsections); SetCurrentOutputs(Subsections, Subsubsections);
wxFprintf(Subsections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName), topicName); if(PrimaryAnchorOfTheFile(SubsubsectionsName, topicName))
wxFprintf(Subsections, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsubsectionsName));
else
wxFprintf(Subsections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName), topicName);
wxFprintf(Subsubsections, _T("\n<H3>")); wxFprintf(Subsubsections, _T("\n<H3>"));
OutputCurrentSection(); OutputCurrentSection();
@@ -1982,13 +2018,17 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
{ {
TraverseChildrenFromChunk(helpRefFilename); TraverseChildrenFromChunk(helpRefFilename);
TexOutput(_T("#")); TexOutput(_T("#"));
TexOutput(refName);
} }
else if (refFilename) else if (refFilename)
{ {
TexOutput(ConvertCase(refFilename)); TexOutput(ConvertCase(refFilename));
TexOutput(_T("#")); if(!PrimaryAnchorOfTheFile(texRef->refFile, refName))
{
TexOutput(_T("#"));
TexOutput(refName);
}
} }
TexOutput(refName);
TexOutput(_T("\">")); TexOutput(_T("\">"));
if (helpRefText) if (helpRefText)
TraverseChildrenFromChunk(helpRefText); TraverseChildrenFromChunk(helpRefText);
@@ -2771,7 +2811,10 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
_T("bibliography"), ChaptersName); // This topic _T("bibliography"), ChaptersName); // This topic
SetCurrentOutputs(Contents, Chapters); SetCurrentOutputs(Contents, Chapters);
wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), "bibliography"); if(PrimaryAnchorOfTheFile(ChaptersName, _T("bibliography")))
wxFprintf(Contents, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName));
else
wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), _T("bibliography"));
wxFprintf(Contents, _T("%s</A>\n"), ReferencesNameString); wxFprintf(Contents, _T("%s</A>\n"), ReferencesNameString);
wxFprintf(Chapters, _T("</H2>\n</A>\n")); wxFprintf(Chapters, _T("</H2>\n</A>\n"));
@@ -3329,7 +3372,15 @@ void HTMLWorkshopStartContents()
void HTMLWorkshopEndContents() void HTMLWorkshopEndContents()
{ {
for (int i = HTMLWorkshopLastLevel; i >= 0; i--) for (int i = HTMLWorkshopLastLevel; i >= 0; i--)
wxFprintf(HTMLWorkshopContents, _T("</UL>\n")); wxFprintf(HTMLWorkshopContents, _T("</UL>\n"));
fclose(HTMLWorkshopContents); fclose(HTMLWorkshopContents);
} }
bool PrimaryAnchorOfTheFile( wxChar *file, wxChar *label )
{
wxString file_label;
file_label.Printf( HTML_FILENAME_PATTERN, FileRoot, label );
return file_label.IsSameAs( file , false );
}