diff --git a/HtmlFile2/HTMLReader.cpp b/HtmlFile2/HTMLReader.cpp
index 153192f8f0..2706d5b309 100644
--- a/HtmlFile2/HTMLReader.cpp
+++ b/HtmlFile2/HTMLReader.cpp
@@ -7,9 +7,13 @@
#include "../Common/3dParty/html/htmltoxhtml.h"
#include "Common.h"
-#include "Interpretators/OOXMLInterpretator.h"
+
+#include "Writers/OOXMLWriter.h"
#include "Tags/OOXMLTags.h"
+#include "Writers/MDWriter.h"
+#include "Tags/MDTags.h"
+
#include "../../Common/3dParty/html/gumbo-parser/src/gumbo.h"
#include "../src/StringFinder.h"
@@ -165,32 +169,71 @@ inline bool UnreadableNode(const std::wstring& wsNodeName);
inline bool TagIsUnprocessed(const std::wstring& wsTagName);
CHTMLReader::CHTMLReader()
- : m_pInterpretator(nullptr)
+ : m_pWriter(nullptr)
{
- COOXMLInterpretator *pInterpretator = new COOXMLInterpretator();
+ // InitOOXMLTags();
+ InitMDTags();
+}
- if (nullptr == pInterpretator)
+CHTMLReader::~CHTMLReader()
+{
+ if (nullptr != m_pWriter)
+ delete m_pWriter;
+}
+
+HRESULT CHTMLReader::ConvertFromTo(const std::wstring& wsFrom, const std::wstring& wsTo)
+{
+ if (nullptr == m_pWriter || !HTML2XHTML(wsFrom) || !m_oLightReader.IsValid() || !IsHTML())
+ return S_FALSE;
+
+ m_pWriter->Begin(wsTo, nullptr);
+
+ m_sSrc = NSSystemPath::GetDirectoryName(wsFrom);
+ // m_sDst = sDst;
+
+ m_oLightReader.MoveToStart();
+ m_oLightReader.ReadNextNode();
+ ReadStyle();
+
+ // Переходим в начало
+ if(!m_oLightReader.MoveToStart())
+ return S_FALSE;
+
+ // if(oParams && oParams->m_bNeedPageBreakBefore)
+ // m_internal->PageBreakBefore();
+
+ ReadDocument();
+
+ m_pWriter->End(wsTo);
+ return S_OK;
+}
+
+void CHTMLReader::InitOOXMLTags()
+{
+ COOXMLWriter *pWriter = new COOXMLWriter();
+
+ if (nullptr == pWriter)
return;
- pInterpretator->SetCSSCalculator(&m_oCSSCalculator);
- m_pInterpretator = pInterpretator;
+ pWriter->SetCSSCalculator(&m_oCSSCalculator);
+ m_pWriter = pWriter;
- m_mTags[HTML_TAG(A)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(ABBR)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(BR)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(DIV)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(IMG)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(FONT)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(INPUT)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(BASEFONT)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(BLOCKQUOTE)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(HR)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(UL)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(LI)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(CAPTION)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(TABLE)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(TR)] = std::make_shared>(pInterpretator);
- m_mTags[HTML_TAG(TD)] = std::make_shared>(pInterpretator);
+ m_mTags[HTML_TAG(A)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(ABBR)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(BR)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(DIV)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(IMG)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(FONT)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(INPUT)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(BASEFONT)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(BLOCKQUOTE)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(HR)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(UL)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(LI)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(CAPTION)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(TABLE)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(TR)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(TD)] = std::make_shared>(pWriter);
std::shared_ptr oIgnoredTag{std::make_shared()};
@@ -210,37 +253,49 @@ CHTMLReader::CHTMLReader()
m_mTags[HTML_TAG(H1)] = oIgnoredTag;
}
-CHTMLReader::~CHTMLReader()
+void CHTMLReader::InitMDTags()
{
- if (nullptr != m_pInterpretator)
- delete m_pInterpretator;
-}
+ CMDWriter *pWriter = new CMDWriter({});
-HRESULT CHTMLReader::ConvertFromTo(const std::wstring& wsFrom, const std::wstring& wsTo)
-{
- if (nullptr == m_pInterpretator || !HTML2XHTML(wsFrom) || !m_oLightReader.IsValid() || !IsHTML())
- return S_FALSE;
+ if (nullptr == pWriter)
+ return;
- m_pInterpretator->Begin(wsTo, nullptr);
+ m_pWriter = pWriter;
- m_sSrc = NSSystemPath::GetDirectoryName(wsFrom);
- // m_sDst = sDst;
+ m_mTags[HTML_TAG(A)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(B)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(BR)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(I)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(S)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(U)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(Q)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(H1)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(IMG)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(HR)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(BLOCKQUOTE)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(TABLE)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(TR)] = std::make_shared>(pWriter);
+ m_mTags[HTML_TAG(TD)] = std::make_shared>(pWriter);
- m_oLightReader.MoveToStart();
- m_oLightReader.ReadNextNode();
- ReadStyle();
+ std::shared_ptr oPreformatted{std::make_shared>(pWriter)};
- // Переходим в начало
- if(!m_oLightReader.MoveToStart())
- return S_FALSE;
+ m_mTags[HTML_TAG(PRE)] = oPreformatted;
+ m_mTags[HTML_TAG(KBD)] = oPreformatted;
- // if(oParams && oParams->m_bNeedPageBreakBefore)
- // m_internal->PageBreakBefore();
+ std::shared_ptr oIgnoredTag{std::make_shared()};
- ReadDocument();
-
- m_pInterpretator->End(wsTo);
- return S_OK;
+ m_mTags[HTML_TAG(ABBR)] = oIgnoredTag;
+ m_mTags[HTML_TAG(DIV)] = oIgnoredTag;
+ m_mTags[HTML_TAG(FONT)] = oIgnoredTag;
+ m_mTags[HTML_TAG(INPUT)] = oIgnoredTag;
+ m_mTags[HTML_TAG(BASEFONT)] = oIgnoredTag;
+ m_mTags[HTML_TAG(CENTER)] = oIgnoredTag;
+ m_mTags[HTML_TAG(MARK)] = oIgnoredTag;
+ m_mTags[HTML_TAG(SUP)] = oIgnoredTag;
+ m_mTags[HTML_TAG(DD)] = oIgnoredTag;
+ m_mTags[HTML_TAG(BDO)] = oIgnoredTag;
+ m_mTags[HTML_TAG(SPAN)] = oIgnoredTag;
+ m_mTags[HTML_TAG(CAPTION)] = oIgnoredTag;
}
bool CHTMLReader::IsHTML()
@@ -455,7 +510,7 @@ bool CHTMLReader::ReadStream(std::vector& arSelectors, bool bInser
if (!bInsertEmptyP)
return false;
- m_pInterpretator->WriteEmptyParagraph();
+ m_pWriter->WriteEmptyParagraph();
return true;
// WriteEmptyParagraph(sSelectors, oTS);
@@ -479,7 +534,7 @@ bool CHTMLReader::ReadStream(std::vector& arSelectors, bool bInser
} while(m_oLightReader.ReadNextSiblingNode2(nDeath));
if (!bResult && bInsertEmptyP)
- m_pInterpretator->WriteEmptyParagraph();
+ m_pWriter->WriteEmptyParagraph();
return bResult;
}
@@ -660,7 +715,7 @@ bool CHTMLReader::ReadInside(std::vector& arSelectors)
}
default:
{
- m_pInterpretator->BeginBlock();
+ m_pWriter->BeginBlock();
switch(eHtmlTag)
{
@@ -773,7 +828,7 @@ bool CHTMLReader::ReadInside(std::vector& arSelectors)
}
}
- m_pInterpretator->EndBlock(bResult);
+ m_pWriter->EndBlock(bResult);
}
}
@@ -792,12 +847,12 @@ bool CHTMLReader::ReadInside(std::vector& arSelectors)
bool CHTMLReader::ReadText(std::vector& arSelectors)
{
- if (nullptr == m_pInterpretator)
+ if (nullptr == m_pWriter)
return false;
GetSubClass(arSelectors);
- const bool bResult{m_pInterpretator->WriteText(m_oLightReader.GetText(), arSelectors)};
+ const bool bResult{m_pWriter->WriteText(m_oLightReader.GetText(), arSelectors)};
arSelectors.pop_back();
@@ -806,11 +861,11 @@ bool CHTMLReader::ReadText(std::vector& arSelectors)
bool CHTMLReader::ReadAnchor(std::vector& arSelectors)
{
- if (!m_mTags[HTML_TAG(A)]->Open(arSelectors))
+ if (nullptr == m_pWriter || !m_mTags[HTML_TAG(A)]->Open(arSelectors))
return false;
if (!ReadStream(arSelectors))
- m_pInterpretator->WriteEmptyParagraph(true);
+ m_pWriter->WriteEmptyParagraph(true);
m_mTags[HTML_TAG(A)]->Close(arSelectors);
@@ -819,7 +874,7 @@ bool CHTMLReader::ReadAnchor(std::vector& arSelectors)
bool CHTMLReader::ReadSVG(const std::vector& arSelectors)
{
- if (!m_mTags[HTML_TAG(IMAGE)]->Open(arSelectors, &m_oLightReader))
+ if (!m_mTags[HTML_TAG(IMAGE)]->Open(arSelectors, m_oLightReader.GetOuterXml()))
return false;
m_mTags[HTML_TAG(IMAGE)]->Close(arSelectors);
@@ -959,23 +1014,30 @@ bool CHTMLReader::ReadTable(std::vector& arSelectors)
\
for (UINT unRow = 0; unRow < arRows.size(); ++unRow)\
{\
- if (!m_mTags[HTML_TAG(TR)]->Open(arSelectors, boost::tuple(*arRows[unRow], oTable)))\
- continue;\
- \
- const std::vector& arCells{arRows[unRow]->GetCells()};\
ERowPosition eRowPosition{ERowPosition::Middle};\
- \
+ \
if (0 == unRow)\
eRowPosition = ERowPosition::First;\
else if (arRows.size() - 1 == unRow)\
eRowPosition = ERowPosition::Last;\
- \
+ \
+ if (!m_mTags[HTML_TAG(TR)]->Open(arSelectors, boost::tuple(arRows[unRow]->GetStyles(), oTable, parse_mode, eRowPosition)))\
+ continue;\
+ \
+ const std::vector& arCells{arRows[unRow]->GetCells()};\
+ \
for (UINT unCol = 0; unCol < arCells.size(); ++unCol)\
{\
m_mTags[HTML_TAG(TD)]->Open(arSelectors, boost::tuple(*arCells[unCol], oTable, unCol, parse_mode, eRowPosition));\
+ \
+ if (0 != arCells[unCol]->GetData()->GetCurSize())\
+ WriteToStringBuilder(*(arCells[unCol]->GetData()), *(m_pWriter->GetCurrentDocument()));\
+ else\
+ m_pWriter->WriteEmptyParagraph();\
+ \
m_mTags[HTML_TAG(TD)]->Close(arSelectors);\
}\
- \
+ \
m_mTags[HTML_TAG(TR)]->Close(arSelectors);\
}}
@@ -992,17 +1054,17 @@ bool CHTMLReader::ReadTable(std::vector& arSelectors)
void CHTMLReader::ReadTableCaption(CStorageTable& oTable, std::vector& arSelectors)
{
- if (nullptr == m_pInterpretator)
+ if (nullptr == m_pWriter)
return;
GetSubClass(arSelectors);
- m_pInterpretator->SetDataOutput(oTable.GetCaptionData());
+ m_pWriter->SetDataOutput(oTable.GetCaptionData());
arSelectors.back().m_pCompiledStyle->m_oDisplay.SetVAlign(L"center", arSelectors.size());
ReadDefaultTag(HTML_TAG(CAPTION), arSelectors);
- m_pInterpretator->RevertDataOutput();
+ m_pWriter->RevertDataOutput();
arSelectors.pop_back();
}
@@ -1036,6 +1098,9 @@ struct TRowspanElement
void CHTMLReader::ReadTableRows(CStorageTable& oTable, std::vector& arSelectors, ERowParseMode eMode)
{
+ if (nullptr == m_pWriter)
+ return;
+
std::vector arRowspanElements;
std::vector arRows;
@@ -1096,16 +1161,16 @@ void CHTMLReader::ReadTableRows(CStorageTable& oTable, std::vector
arSelectors.back().m_pCompiledStyle->m_oFont.SetWeight(L"bold", arSelectors.size());
- m_pInterpretator->SetDataOutput(pCell->GetData());
+ m_pWriter->SetDataOutput(pCell->GetData());
ReadStream(arSelectors, true);
- m_pInterpretator->RevertDataOutput();
+ m_pWriter->RevertDataOutput();
}
// Читаем td. Ячейка таблицы
else if(m_oLightReader.GetName() == L"td")
{
- m_pInterpretator->SetDataOutput(pCell->GetData());
+ m_pWriter->SetDataOutput(pCell->GetData());
ReadStream(arSelectors, true);
- m_pInterpretator->RevertDataOutput();
+ m_pWriter->RevertDataOutput();
}
if (pRow->GetIndex() == MAXCOLUMNSINTABLE - 1)
@@ -1116,9 +1181,9 @@ void CHTMLReader::ReadTableRows(CStorageTable& oTable, std::vector
continue;
GetSubClass(arSelectors);
- m_pInterpretator->SetDataOutput(pCell->GetData());
+ m_pWriter->SetDataOutput(pCell->GetData());
ReadStream(arSelectors);
- m_pInterpretator->RevertDataOutput();
+ m_pWriter->RevertDataOutput();
arSelectors.pop_back();
}
}
diff --git a/HtmlFile2/HTMLReader.h b/HtmlFile2/HTMLReader.h
index 8bacf599d0..7947360a2f 100644
--- a/HtmlFile2/HTMLReader.h
+++ b/HtmlFile2/HTMLReader.h
@@ -4,7 +4,7 @@
#include "../Common/3dParty/html/css/src/CCssCalculator.h"
#include "../DesktopEditor/xml/include/xmlutils.h"
-#include "Interpretators/HTMLInterpretator.h"
+#include "Writers/IWriter.h"
#include "Tags/HTMLTags.h"
#include "Table.h"
@@ -21,19 +21,20 @@ class CHTMLReader
std::wstring m_sBase; // Полный базовый адрес
std::wstring m_sCore; // Путь до корневого файла (используется для работы с Epub)
- IHTMLInterpretator *m_pInterpretator;
+ IWriter *m_pWriter;
std::unordered_map> m_mTags;
public:
CHTMLReader();
~CHTMLReader();
- void SetInterpretator(IHTMLInterpretator* pInterpretator);
-
HRESULT ConvertFromTo(const std::wstring& wsFrom, const std::wstring& wsTo);
NSCSS::CCssCalculator* GetCSSCalculator();
private:
+ void InitOOXMLTags();
+ void InitMDTags();
+
bool IsHTML();
bool HTML2XHTML(const std::wstring& wsFileName);
diff --git a/HtmlFile2/HtmlFile2.pro b/HtmlFile2/HtmlFile2.pro
index 8ff371f1dd..0c5f42e605 100644
--- a/HtmlFile2/HtmlFile2.pro
+++ b/HtmlFile2/HtmlFile2.pro
@@ -33,8 +33,10 @@ include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri)
ADD_DEPENDENCY(kernel, UnicodeConverter, graphics, kernel_network)
SOURCES += htmlfile2.cpp \
- ./Interpretators/OOXMLInterpretator.cpp \
+ ./Writers/OOXMLWriter.cpp \
HTMLReader.cpp \
+ Tags/MDTags.cpp \
+ Writers/MDWriter.cpp \
Table.cpp \
Tags/OOXMLTags.cpp
@@ -42,10 +44,12 @@ HEADERS += htmlfile2.h \
./src/StringFinder.h \
./src/Languages.h \
Common.h \
- ./Interpretators/OOXMLInterpretator.h \
- ./Interpretators/HTMLInterpretator.h \
+ ./Writers/OOXMLWriter.h \
+ ./Writers/IWriter.h \
HTMLParams.h \
HTMLReader.h \
./Tags/HTMLTags.h \
+ Tags/MDTags.h \
+ Writers/MDWriter.h \
Table.h \
Tags/OOXMLTags.h
diff --git a/HtmlFile2/Table.cpp b/HtmlFile2/Table.cpp
index 873660e47f..90ef6fea73 100644
--- a/HtmlFile2/Table.cpp
+++ b/HtmlFile2/Table.cpp
@@ -600,8 +600,15 @@ void CStorageTable::AddColgroup(CTableColgroup* pElement)
void CStorageTable::RecalculateMaxColumns()
{
+ for (const std::vector& arHeaders : m_arHeaders)
+ for (const CStorageTableRow* pHeader : arHeaders)
+ m_unMaxColumns = std::max(m_unMaxColumns, pHeader->GetIndex());
+
for (const CStorageTableRow* pRow : m_arRows)
m_unMaxColumns = std::max(m_unMaxColumns, pRow->GetIndex());
+
+ for (const CStorageTableRow* pFoother : m_arFoother)
+ m_unMaxColumns = std::max(m_unMaxColumns, pFoother->GetIndex());
}
void CStorageTable::Shorten()
diff --git a/HtmlFile2/Tags/HTMLTags.h b/HtmlFile2/Tags/HTMLTags.h
index fe568d2e63..f0ee9c9e9f 100644
--- a/HtmlFile2/Tags/HTMLTags.h
+++ b/HtmlFile2/Tags/HTMLTags.h
@@ -29,10 +29,10 @@ template
class CTag : public ITag
{
protected:
- T* m_pInterpretator;
+ T* m_pWriter;
public:
- CTag(T* pInterpretator)
- : m_pInterpretator(pInterpretator)
+ CTag(T* pWriter)
+ : m_pWriter(pWriter)
{}
virtual ~CTag() = default;
virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) = 0;
@@ -40,7 +40,7 @@ public:
bool ValidInterpretator() const
{
- return nullptr != m_pInterpretator;
+ return nullptr != m_pWriter;
}
};
diff --git a/HtmlFile2/Tags/MDTags.cpp b/HtmlFile2/Tags/MDTags.cpp
new file mode 100644
index 0000000000..3e7a47354a
--- /dev/null
+++ b/HtmlFile2/Tags/MDTags.cpp
@@ -0,0 +1,388 @@
+#include "MDTags.h"
+
+#include "../Table.h"
+
+#include
+
+namespace HTML
+{
+CAnchor::CAnchor(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CAnchor::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ m_pWriter->GetCurrentDocument()->AddCharSafe(L'[');
+ return true;
+}
+
+void CAnchor::Close(const std::vector& arSelectors)
+{
+ if (!ValidInterpretator())
+ return;
+
+ XmlString* pCurrentDocument{m_pWriter->GetCurrentDocument()};
+
+ pCurrentDocument->AddCharSafe(L']');
+
+ std::wstring wsHref, wsTitle;
+
+ if (!arSelectors.back().GetAttributeValue(L"href", wsHref) ||
+ !arSelectors.back().GetAttributeValue(L"title", wsTitle))
+ return;
+
+ pCurrentDocument->WriteString(L'(' + wsHref);
+
+ if (!wsTitle.empty())
+ pCurrentDocument->WriteString(L" \"" + wsTitle + L'"');
+
+ pCurrentDocument->AddCharSafe(L')');
+}
+
+CBold::CBold(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CBold::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ m_pWriter->GetCurrentDocument()->WriteString(L"**");
+
+ return true;
+}
+
+void CBold::Close(const std::vector& arSelectors)
+{
+ if (!ValidInterpretator())
+ return;
+
+ m_pWriter->GetCurrentDocument()->WriteString(L"**");
+}
+
+CBreak::CBreak(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CBreak::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ m_pWriter->GetCurrentDocument()->WriteString(m_pWriter->GetParametrs().m_wsLineBreak);
+
+ return true;
+}
+
+void CBreak::Close(const std::vector& arSelectors)
+{}
+
+CItalic::CItalic(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CItalic::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ m_pWriter->GetCurrentDocument()->AddCharSafe(L'*');
+
+ return true;
+}
+
+void CItalic::Close(const std::vector& arSelectors)
+{
+ if (!ValidInterpretator())
+ return;
+
+ m_pWriter->GetCurrentDocument()->AddCharSafe(L'*');
+}
+
+CStrike::CStrike(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CStrike::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ m_pWriter->GetCurrentDocument()->WriteString(L"~~");
+
+ return true;
+}
+
+void CStrike::Close(const std::vector& arSelectors)
+{
+ if (!ValidInterpretator())
+ return;
+
+ m_pWriter->GetCurrentDocument()->WriteString(L"~~");
+}
+
+CUnderline::CUnderline(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CUnderline::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ if (m_pWriter->GetParametrs().m_bUseAlternativeHTMLTags)
+ m_pWriter->GetCurrentDocument()->WriteString(L"");
+
+ return true;
+}
+
+void CUnderline::Close(const std::vector& arSelectors)
+{
+ if (!ValidInterpretator())
+ return;
+
+ if (m_pWriter->GetParametrs().m_bUseAlternativeHTMLTags)
+ m_pWriter->GetCurrentDocument()->WriteString(L"");
+}
+
+CQuotation::CQuotation(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CQuotation::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ m_pWriter->GetCurrentDocument()->AddCharSafe(L'>');
+
+ return true;
+}
+
+void CQuotation::Close(const std::vector& arSelectors)
+{}
+
+CPreformatted::CPreformatted(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CPreformatted::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ m_pWriter->GetCurrentDocument()->WriteString(L"```" + m_pWriter->GetParametrs().m_wsLineBreak);
+
+ return true;
+}
+
+void CPreformatted::Close(const std::vector& arSelectors)
+{
+ if (!ValidInterpretator())
+ return;
+
+ m_pWriter->GetCurrentDocument()->WriteString(m_pWriter->GetParametrs().m_wsLineBreak + L"```" + m_pWriter->GetParametrs().m_wsLineBreak);
+}
+
+CHeader::CHeader(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CHeader::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ switch(arSelectors.back().m_wsName[1])
+ {
+ case L'1' : m_pWriter->GetCurrentDocument()->WriteString(L"# "); break;
+ case L'2' : m_pWriter->GetCurrentDocument()->WriteString(L"## "); break;
+ case L'3' : m_pWriter->GetCurrentDocument()->WriteString(L"### "); break;
+ case L'4' : m_pWriter->GetCurrentDocument()->WriteString(L"#### "); break;
+ case L'5' : m_pWriter->GetCurrentDocument()->WriteString(L"##### "); break;
+ case L'6' : m_pWriter->GetCurrentDocument()->WriteString(L"###### "); break;
+ default:
+ return false;
+ }
+
+ return true;
+}
+
+void CHeader::Close(const std::vector& arSelectors)
+{}
+
+CImage::CImage(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CImage::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ std::wstring wsAlt, wsSrc, wsTitle;
+
+ if (!arSelectors.back().GetAttributeValue(L"src", wsSrc) &&
+ !arSelectors.back().GetAttributeValue(L"alt", wsAlt))
+ return false;
+
+ arSelectors.back().GetAttributeValue(L"title", wsTitle);
+
+ XmlString* pCurrentDocument{m_pWriter->GetCurrentDocument()};
+
+ pCurrentDocument->WriteString(L";
+
+ if (!wsTitle.empty())
+ pCurrentDocument->WriteString(L" \"" + wsTitle + L'"');
+
+ pCurrentDocument->AddCharSafe(L')');
+
+ return true;
+}
+
+void CImage::Close(const std::vector& arSelectors)
+{}
+
+CHorizontalRule::CHorizontalRule(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool HTML::CHorizontalRule::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ m_pWriter->GetCurrentDocument()->WriteString(L"\n\n---\n\n");
+
+ return true;
+}
+
+void CHorizontalRule::Close(const std::vector& arSelectors)
+{}
+
+CBlockquote::CBlockquote(CMDWriter* pWriter)
+ : CTag(pWriter), m_unIndex(0)
+{}
+
+bool CBlockquote::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ ++m_unIndex;
+
+ XmlString* pCurrentDocument{m_pWriter->GetCurrentDocument()};
+
+ pCurrentDocument->WriteString(m_pWriter->GetParametrs().m_wsLineBreak);
+
+ for (UINT unIndex = 0; unIndex < m_unIndex; ++m_unIndex)
+ pCurrentDocument->WriteString(L"> ");
+
+ return true;
+}
+
+void CBlockquote::Close(const std::vector& arSelectors)
+{
+ --m_unIndex;
+}
+
+CTable::CTable(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CTable::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ //В MD не поддерживаются вложенные таблицы
+ for (std::vector::const_iterator itElement = arSelectors.cbegin(); itElement < arSelectors.cend() - 1; ++itElement)
+ if (L"table" == itElement->m_wsName)
+ return false;
+
+ m_pWriter->GetCurrentDocument()->AddCharSafe(L'\n');
+
+ return true;
+}
+
+void CTable::Close(const std::vector& arSelectors)
+{
+ m_pWriter->GetCurrentDocument()->AddCharSafe(L'\n');
+}
+
+CTableRow::CTableRow(CMDWriter* pWriter)
+ : CTag(pWriter), m_unLastRowType(static_cast(ERowParseMode::Foother))
+{}
+
+bool CTableRow::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ using DataForRow = boost::tuple;
+
+ if (!ValidInterpretator() || oExtraData.empty() || typeid(DataForRow) != oExtraData.type())
+ return false;
+
+ const DataForRow& oDataForRow(boost::any_cast(oExtraData));
+ const CStorageTable& oStorageTable{boost::get<1>(oDataForRow)};
+ XmlString* pCurrentDocument{m_pWriter->GetCurrentDocument()};
+
+ if (m_unLastRowType == static_cast(ERowParseMode::Header))
+ {
+ for (UINT unIndex = 0; unIndex < oStorageTable.GetMaxColumns(); ++unIndex)
+ pCurrentDocument->WriteString(L"|-");
+
+ pCurrentDocument->WriteString(L"|\n");
+ }
+ else if (ERowParseMode::Header != boost::get<2>(oDataForRow) &&
+ ERowPosition::First == boost::get<3>(oDataForRow) &&
+ m_unLastRowType == static_cast(ERowParseMode::Foother))
+ {
+ for (UINT unIndex = 0; unIndex < oStorageTable.GetMaxColumns(); ++unIndex)
+ pCurrentDocument->WriteString(L"| ");
+
+ pCurrentDocument->WriteString(L"|\n");
+
+ for (UINT unIndex = 0; unIndex < oStorageTable.GetMaxColumns(); ++unIndex)
+ pCurrentDocument->WriteString(L"|-");
+
+ pCurrentDocument->WriteString(L"|\n");
+ }
+
+ m_unLastRowType = static_cast(boost::get<2>(oDataForRow));
+
+ pCurrentDocument->WriteString(L"| ");
+
+ return true;
+}
+
+void CTableRow::Close(const std::vector& arSelectors)
+{
+ if (!ValidInterpretator())
+ return;
+
+ m_pWriter->GetCurrentDocument()->AddCharSafe(L'\n');
+}
+
+CTableCell::CTableCell(CMDWriter* pWriter)
+ : CTag(pWriter)
+{}
+
+bool CTableCell::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+{
+ if (!ValidInterpretator())
+ return false;
+
+ return true;
+}
+
+void CTableCell::Close(const std::vector& arSelectors)
+{
+ if (!ValidInterpretator())
+ return;
+
+ m_pWriter->GetCurrentDocument()->WriteString(L" | ");
+}
+}
diff --git a/HtmlFile2/Tags/MDTags.h b/HtmlFile2/Tags/MDTags.h
new file mode 100644
index 0000000000..6aca499b75
--- /dev/null
+++ b/HtmlFile2/Tags/MDTags.h
@@ -0,0 +1,147 @@
+#ifndef MDTAGS_H
+#define MDTAGS_H
+
+#include "HTMLTags.h"
+#include "../Writers/MDWriter.h"
+
+namespace HTML
+{
+template<>
+class CAnchor : public CTag
+{
+public:
+ CAnchor(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CBold : public CTag
+{
+public:
+ CBold(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CBreak : public CTag
+{
+public:
+ CBreak(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CItalic : public CTag
+{
+public:
+ CItalic(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CStrike : public CTag
+{
+public:
+ CStrike(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CUnderline : public CTag
+{
+public:
+ CUnderline(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CQuotation : public CTag
+{
+public:
+ CQuotation(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CPreformatted : public CTag
+{
+public:
+ CPreformatted(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CHeader : public CTag
+{
+public:
+ CHeader(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CImage : public CTag
+{
+public:
+ CImage(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CHorizontalRule : public CTag
+{
+public:
+ CHorizontalRule(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CBlockquote : public CTag
+{
+ UINT m_unIndex;
+public:
+ CBlockquote(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CTable : public CTag
+{
+public:
+ CTable(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CTableRow : public CTag
+{
+ UINT m_unLastRowType;
+public:
+ CTableRow(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+
+template<>
+class CTableCell : public CTag
+{
+public:
+ CTableCell(CMDWriter* pWriter);
+ virtual bool Open(const std::vector& arSelectors, const boost::any& oExtraData = boost::any()) override;
+ virtual void Close(const std::vector& arSelectors) override;
+};
+}
+
+#endif // MDTAGS_H
diff --git a/HtmlFile2/Tags/OOXMLTags.cpp b/HtmlFile2/Tags/OOXMLTags.cpp
index 4a2d527afd..355d1301a0 100644
--- a/HtmlFile2/Tags/OOXMLTags.cpp
+++ b/HtmlFile2/Tags/OOXMLTags.cpp
@@ -5,7 +5,6 @@
#include "../../Common/Network/FileTransporter/include/FileTransporter.h"
-#include "../../DesktopEditor/xml/include/xmlutils.h"
#include "../../DesktopEditor/raster/BgraFrame.h"
#include "../../DesktopEditor/graphics/pro/Graphics.h"
#include "../../DesktopEditor/common/Base64.h"
@@ -34,11 +33,11 @@ bool UpdateImageData(const std::wstring& wsImagePath, TImageData& oImageData);
const static double HTML_FONTS[7] = {7.5, 10, 12, 13.5, 18, 24, 36};
-CAnchor::CAnchor(COOXMLInterpretator* pInterpretator)
- : CTag(pInterpretator)
+CAnchor::CAnchor(COOXMLWriter* pWriter)
+ : CTag(pWriter)
{}
-bool CAnchor::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+bool CAnchor::Open(const std::vector& arSelectors, const boost::any& oExtraData)
{
if (!ValidInterpretator())
return false;
@@ -50,29 +49,29 @@ bool CAnchor::Open(const std::vector& arSelec
bCross = true;
if (arSelectors.back().GetAttributeValue(L"name", wsName))
- m_pInterpretator->WriteBookmark(wsName);
+ m_pWriter->WriteBookmark(wsName);
arSelectors.back().GetAttributeValue(L"alt", wsAlt);
- if (!m_pInterpretator->OpenP())
- m_pInterpretator->CloseR();
+ if (!m_pWriter->OpenP())
+ m_pWriter->CloseR();
else
- m_pInterpretator->WritePPr(arSelectors);
+ m_pWriter->WritePPr(arSelectors);
if (bCross)
- m_pInterpretator->OpenCrossHyperlink(wsRef, arSelectors);
+ m_pWriter->OpenCrossHyperlink(wsRef, arSelectors);
else
{
std::wstring wsTooltip(wsRef);
arSelectors.back().GetAttributeValue(L"title", wsTooltip);
- m_pInterpretator->OpenExternalHyperlink(wsRef, wsTooltip, arSelectors);
+ m_pWriter->OpenExternalHyperlink(wsRef, wsTooltip, arSelectors);
}
return true;
}
-void CAnchor::Close(const std::vector& arSelectors)
+void CAnchor::Close(const std::vector& arSelectors)
{
if (!ValidInterpretator())
return;
@@ -101,17 +100,17 @@ void CAnchor::Close(const std::vector& arSele
if (wsFootnote == L"href")
wsFootnote = wsRef.substr(wsRef.find('#') + 1);
- m_pInterpretator->CloseCrossHyperlink(arSelectors, wsFootnote, wsRef);
+ m_pWriter->CloseCrossHyperlink(arSelectors, wsFootnote, wsRef);
}
else
- m_pInterpretator->CloseExternalHyperlink();
+ m_pWriter->CloseExternalHyperlink();
}
-CAbbr::CAbbr(COOXMLInterpretator* pInterpretator)
- : CTag(pInterpretator)
+CAbbr::CAbbr(COOXMLWriter* pWriter)
+ : CTag(pWriter)
{}
-bool CAbbr::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+bool CAbbr::Open(const std::vector& arSelectors, const boost::any& oExtraData)
{
if (!ValidInterpretator())
return false;
@@ -121,11 +120,11 @@ bool CAbbr::Open(const std::vector& arSelecto
if (!arSelectors.back().GetAttributeValue(L"title", wsTitle))
return false;
- m_pInterpretator->WritePPr(arSelectors);
+ m_pWriter->WritePPr(arSelectors);
- XmlString* pCurrentDocument{&m_pInterpretator->GetCurrentDocument()};
+ XmlString* pCurrentDocument{m_pWriter->GetCurrentDocument()};
- pCurrentDocument->WriteString(L"HYPERLINK \\l \"" + m_pInterpretator->AddLiteBookmark() + L"\" \\o \"");
+ pCurrentDocument->WriteString(L"HYPERLINK \\l \"" + m_pWriter->AddLiteBookmark() + L"\" \\o \"");
pCurrentDocument->WriteEncodeXmlString(wsTitle);
pCurrentDocument->WriteString(L"\"");
pCurrentDocument->WriteString(L"");
@@ -133,41 +132,41 @@ bool CAbbr::Open(const std::vector& arSelecto
return true;
}
-void CAbbr::Close(const std::vector& arSelectors)
+void CAbbr::Close(const std::vector& arSelectors)
{
if (!ValidInterpretator())
return;
- m_pInterpretator->GetCurrentDocument().WriteString(L"");
+ m_pWriter->GetCurrentDocument()->WriteString(L"");
}
-CBreak::CBreak(COOXMLInterpretator* pInterpretator)
- : CTag(pInterpretator)
+CBreak::CBreak(COOXMLWriter* pWriter)
+ : CTag(pWriter)
{}
-bool CBreak::Open(const std::vector& arSelectors, const boost::any& oExtraData)
+bool CBreak