moved to shstk

This commit is contained in:
2020-08-25 22:24:02 +03:00
parent d4f1c78a6e
commit b92a1fa558
904 changed files with 2448 additions and 36452 deletions

27
libs/doc/CMakeLists.txt Normal file
View File

@@ -0,0 +1,27 @@
include(CheckIncludeFileCXX)
set(CHECK_INCLUDES "-include stdio.h")
if(WIN32)
set(CHECK_INCLUDES "-include windows.h -include stdio.h")
endif()
set(_mkd_header_found 0)
check_include_file_cxx("mkdio.h" MARKDOWN_HEADER_MKDIO ${CHECK_INCLUDES})
if (MARKDOWN_HEADER_MKDIO OR APPLE)
set(_mkd_header_found 1)
add_definitions("-DMARKDOWN_HEADER=\"mkdio.h\"")
else()
check_include_file_cxx("markdown/markdown.h" MARKDOWN_HEADER_MARKDOWN ${CHECK_INCLUDES})
if (MARKDOWN_HEADER_MARKDOWN)
set(_mkd_header_found 1)
add_definitions("-DMARKDOWN_HEADER=\"markdown/markdown.h\"")
endif()
endif()
find_library(MARKDOWN_LIBRARY markdown)
if (MARKDOWN_LIBRARY)
qad_library(doc "Core" "${MARKDOWN_LIBRARY}")
if(NOT _mkd_header_found)
message(STATUS "Found markdown library, but *.h missing!")
endif()
else()
add_definitions("-DNO_MARKDOWN")
qad_library(doc "Core" "")
endif()

87
libs/doc/markdown.cpp Normal file
View File

@@ -0,0 +1,87 @@
#include "markdown.h"
#include <QDebug>
#ifndef NO_MARKDOWN
extern "C" {
#include MARKDOWN_HEADER
}
#ifndef mkd_flags_are
# ifndef MKD_DLEXTRA
# define MKD_DLEXTRA 0x01000000
# endif
# ifndef MKD_FENCEDCODE
# define MKD_FENCEDCODE 0x02000000
# endif
# ifndef MKD_EXTRA_FOOTNOTE
# define MKD_EXTRA_FOOTNOTE 0x00200000
# endif
# ifndef MKD_TOC
# define MKD_TOC 0x00001000
# endif
# ifndef MKD_AUTOLINK
# define MKD_AUTOLINK 0x00004000
# endif
# ifndef MKD_GITHUBTAGS
# define MKD_GITHUBTAGS 0x08000000
# endif
#endif
static QString markdown_css = "table { margin: 5px; background-color: #cccccc; }"
"table tr { background-color: white; }"
"table td { vertical-align: middle; padding: 5px;}"
"table th { padding: 5px; };"
;
QString md2html(const QByteArray & src) {
static bool _is_mkd_init = false;
if (src.isEmpty()) return QString();
if (!_is_mkd_init) {
_is_mkd_init = true;
mkd_initialize();
}
#ifdef _MARKDOWN_D
DWORD flagm = (MKD_DLEXTRA | MKD_FENCEDCODE);
Document
#endif
#ifdef _MKDIO_D
#ifdef mkd_flags_are
mkd_flag_t * flagm = mkd_flags();
mkd_set_flag_num(flagm, MKD_DLEXTRA);
mkd_set_flag_num(flagm, MKD_FENCEDCODE);
#else
mkd_flag_t flagm = (MKD_DLEXTRA | MKD_FENCEDCODE | MKD_GITHUBTAGS | MKD_AUTOLINK);
#endif
MMIOT
#endif
* doc = mkd_string(src.constData(), src.size(), 0);
if (!doc) return QString();
mkd_compile(doc, flagm);
char * html = 0;
int len = mkd_document(doc, &html);
if (!html) {
mkd_cleanup(doc);
return QString();
}
QString ret = QString::fromUtf8(html, len);
mkd_cleanup(doc);
QString title = QTextStream(&ret, QIODevice::ReadOnly).readLine();
title = title.mid(title.indexOf(">")+1);
title = title.left(title.indexOf("<"));
QString header = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html>\n<head>\n"
"<meta name=\"qrichtext\" content=\"1\" />\n"
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
header.append("<title>" + title + "</title>\n");
header.append("<style>" + markdown_css + "</style>\n");
header.append("</head>\n<body>\n");
ret.prepend(header);
ret.append("</body>\n</html>\n");
return ret;
}
#else
QString md2html(const QByteArray & src) {
return src;
}
#endif

30
libs/doc/markdown.h Normal file
View File

@@ -0,0 +1,30 @@
/*
QAD - Qt ADvanced
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef QAD_MARKDOWN_H
#define QAD_MARKDOWN_H
#include <QString>
#include "qad_doc_export.h"
QAD_DOC_EXPORT QString md2html(const QByteArray & src);
#endif // QAD_MARKDOWN_H