Skip to content

Commit 573fcda

Browse files
committed
use proper doctype in HTML generation
Depending on the selected HTML standard the files will now have the proper (X)HTML doctype declaration.
1 parent f333f64 commit 573fcda

23 files changed

+119
-13
lines changed

code/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(pmdb_sources
99
CompressionDetection.cpp
1010
ConsoleColours.cpp
1111
FolderMap.cpp
12+
HTMLStandard.cpp
1213
MessageDatabase.cpp
1314
MsgTemplate.cpp
1415
PMSource.cpp

code/HTMLOptions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define PMDB_HTMLOPTIONS_HPP
2323

2424
#include <string>
25-
#include "bbcode/HTMLStandard.hpp"
25+
#include "HTMLStandard.hpp"
2626
#include "bbcode/TableClasses.hpp"
2727

2828
struct HTMLOptions

code/HTMLStandard.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
-------------------------------------------------------------------------------
3+
This file is part of the Private Message Database.
4+
Copyright (C) 2025 Dirk Stolle
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
-------------------------------------------------------------------------------
19+
*/
20+
21+
#include "HTMLStandard.hpp"
22+
23+
std::string doctype(const HTMLStandard standard)
24+
{
25+
switch (standard)
26+
{
27+
case HTMLStandard::HTML4_01:
28+
return R"(<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
29+
"http://www.w3.org/TR/html4/loose.dtd">)";
30+
case HTMLStandard::XHTML:
31+
return R"(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
32+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">)";
33+
}
34+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#ifndef BBCODE_HTMLSTANDARD_HPP
2222
#define BBCODE_HTMLSTANDARD_HPP
2323

24+
#include <string>
25+
2426
/** \brief Enumeration type to indicate an (X)HTML standard version.
2527
*
2628
* \brief Currently, it's only used to distinguish between HTML and XHTML.
@@ -34,4 +36,11 @@ enum class HTMLStandard: bool
3436
XHTML = true
3537
};
3638

39+
/** \brief Gets the doctype for a given HTML standard.
40+
*
41+
* \param standard the (X)HTML standard version
42+
* \return Returns the corresponding doctype.
43+
*/
44+
std::string doctype(const HTMLStandard standard);
45+
3746
#endif // BBCODE_HTMLSTANDARD_HPP

code/MessageDatabase.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ std::string generateFolderList(MsgTemplate folderList, MsgTemplate folderEntry,
396396
return folderList.show();
397397
}
398398

399-
bool MessageDatabase::saveIndexFiles(const std::string& directory, MsgTemplate index, MsgTemplate entry, MsgTemplate folderList, MsgTemplate folderEntry, const FolderMap& fm) const
399+
bool MessageDatabase::saveIndexFiles(const std::string& directory, MsgTemplate index, MsgTemplate entry, MsgTemplate folderList, MsgTemplate folderEntry, const FolderMap& fm, const HTMLStandard standard) const
400400
{
401401
std::vector<SortType> sortedList;
402402
for (const auto& [digest, pm]: m_Messages)
@@ -432,6 +432,7 @@ bool MessageDatabase::saveIndexFiles(const std::string& directory, MsgTemplate i
432432
++fcIter;
433433
}
434434

435+
index.addReplacement("doctype", doctype(standard), false);
435436
fcIter = folderContents.begin();
436437
while (fcIter != folderContents.end())
437438
{

code/MessageDatabase.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <map>
2525
#include <vector>
26+
#include "HTMLStandard.hpp"
2627
#include "PrivateMessage.hpp"
2728
#include "MsgTemplate.hpp"
2829
#include "FolderMap.hpp"
@@ -127,7 +128,7 @@ class MessageDatabase
127128
* \param fm the current folder map
128129
* \return Returns true, if file was created successfully.
129130
*/
130-
bool saveIndexFiles(const std::string& directory, MsgTemplate index, MsgTemplate entry, MsgTemplate folderList, MsgTemplate folderEntry, const FolderMap& fm) const;
131+
bool saveIndexFiles(const std::string& directory, MsgTemplate index, MsgTemplate entry, MsgTemplate folderList, MsgTemplate folderEntry, const FolderMap& fm, const HTMLStandard standard) const;
131132

132133

133134
/** \brief finds messages whose texts "overlap"

code/bbcode/BBCodeParser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <string>
3737
#include <vector>
3838
#include "BBCode.hpp"
39-
#include "HTMLStandard.hpp"
39+
#include "../HTMLStandard.hpp"
4040
#ifndef NO_SMILIES_IN_PARSER
4141
#include "Smilie.hpp"
4242
#endif

code/bbcode/HorizontalRuleBBCode.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include <string>
2525
#include "BBCode.hpp"
26-
#include "HTMLStandard.hpp"
26+
#include "../HTMLStandard.hpp"
2727

2828
/** \brief HorizontalRuleBBCode:
2929
struct for hr BB code

code/bbcode/Smilie.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define SMILIE_HPP
2323

2424
#include <string>
25-
#include "HTMLStandard.hpp"
25+
#include "../HTMLStandard.hpp"
2626

2727
enum class UrlType: bool
2828
{

code/html_generation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ int generateHtmlFiles(const MessageDatabase& mdb, const FolderMap& fm, const HTM
154154

155155
// create HTML files
156156
std::cout << "Creating HTML files for message texts. This may take a while...\n";
157+
theTemplate.addReplacement("doctype", doctype(htmlOptions.standard), false);
157158
theTemplate.addReplacement("forum_url", conf.getForumURL(), false);
158159
while (msgIter != mdb.getEnd())
159160
{
@@ -206,7 +207,7 @@ int generateHtmlFiles(const MessageDatabase& mdb, const FolderMap& fm, const HTM
206207
}
207208
tplIndex.addReplacement("forum_url", conf.getForumURL(), true);
208209
tplEntry.addReplacement("forum_url", conf.getForumURL(), true);
209-
if (!mdb.saveIndexFiles(htmlDir, tplIndex, tplEntry, tplFolderList, tplFolderEntry, fm))
210+
if (!mdb.saveIndexFiles(htmlDir, tplIndex, tplEntry, tplFolderList, tplFolderEntry, fm, htmlOptions.standard))
210211
{
211212
std::cerr << "Could not write index.html!\n";
212213
return rcFileError;

0 commit comments

Comments
 (0)