Remove cmark from root

master
Melroy van den Berg 2020-11-13 01:54:34 +01:00
parent 70d268315b
commit a9864dd5fd
10 changed files with 96 additions and 72 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "cmark"]
path = cmark
url = https://github.com/github/cmark-gfm

View File

@ -11,37 +11,6 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.
include(cmark/cmark.cmake)
#if(ANDROID)
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
# set(ANDROID_EXTRA_LIBS
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
# endif()
#endif()
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_library(libcmark-gfm libcmark-gfm.so REQUIRED)
find_library(libcmark-gfm-extensions libcmark-gfm-extensions.so REQUIRED)
if(ANDROID)
add_library(browser SHARED
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
)
else()
add_executable(browser
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
)
endif()
target_link_libraries(browser PRIVATE Qt5::Widgets libcmark-gfm.so libcmark-gfm-extensions.so)
add_subdirectory(src)

1
cmark

@ -1 +0,0 @@
Subproject commit b8eb2e00de094999f978e9cb02b1a78d810812d3

36
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,36 @@
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.
#if(ANDROID)
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
# set(ANDROID_EXTRA_LIBS
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
# endif()
#endif()
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_library(libcmark-gfm libcmark-gfm.so REQUIRED)
find_library(libcmark-gfm-extensions libcmark-gfm-extensions.so REQUIRED)
if(ANDROID)
add_library(browser SHARED
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
)
else()
add_executable(browser
main.cpp
markdown-render.cpp
markdown-render.h
mainwindow.cpp
mainwindow.h
mainwindow.ui
)
endif()
target_link_libraries(browser PRIVATE Qt5::Widgets libcmark-gfm.so libcmark-gfm-extensions.so)

14
src/main.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "mainwindow.h"
#include "markdown-render.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
MarkdownRender md;
w.show();
return a.exec();
}

View File

@ -1,24 +1,45 @@
#include "mainwindow.h"
#include "markdown-render.h"
#include <string.h>
#include <cmark-gfm.h>
#include <cmark-gfm-core-extensions.h>
#include <QApplication>
#include <string.h>
#include <QCoreApplication>
#include <QDebug>
#include <QFile>
#include <QDir>
#include <QTextStream>
MarkdownRender::MarkdownRender()
{
QString exePath = QCoreApplication::applicationDirPath();
QString filePath = exePath + QDir::separator() + "../../test.md";
QFile file(filePath);
if(!file.open(QIODevice::ReadOnly))
{
qDebug() << "error opening file: " << file.error();
}
QTextStream instream(&file);
QString line = instream.readLine();
const char *LineCStr = line.toStdString().c_str();
file.close();
char *html = to_html(LineCStr);
printf("%s", html);
free(html);
}
// This is a function that will make enabling extensions easier later on.
void addMarkdownExtension(cmark_parser *parser, char *extName) {
void MarkdownRender::addMarkdownExtension(cmark_parser *parser, char *extName) {
cmark_syntax_extension *ext = cmark_find_syntax_extension(extName);
if ( ext )
cmark_parser_attach_syntax_extension(parser, ext);
}
// A function to convert HTML to markdown
char *to_html(const char *markdown_string)
char * MarkdownRender::to_html(const char *markdown_string)
{
int options = CMARK_OPT_DEFAULT; // You can also use CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDE to enforce double tilde.
@ -38,40 +59,13 @@ char *to_html(const char *markdown_string)
cmark_parser_free(parser);
// no cmake_node_dump() ?
qDebug() << "AST" << doc << endl;
// qDebug() << "AST" << doc->content.mem << endl;
// Render
char *html = cmark_render_html(doc, options, NULL);
cmark_node_free(doc);
return html;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QString exePath = QCoreApplication::applicationDirPath();
QString filePath = exePath + QDir::separator() + "../test.md";
QFile file(filePath);
if(!file.open(QIODevice::ReadOnly))
{
qDebug() << "error opening file: " << file.error();
return -1;
}
QTextStream instream(&file);
QString line = instream.readLine();
const char *LineCStr = line.toStdString().c_str();
file.close();
char *html = to_html(LineCStr);
printf("%s", html);
free(html);
w.show();
return a.exec();
}

15
src/markdown-render.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef MARKDOWN_RENDER_H
#define MARKDOWN_RENDER_H
#include <cmark-gfm.h>
class MarkdownRender
{
public:
MarkdownRender();
private:
void addMarkdownExtension(cmark_parser *parser, char *extName);
char * to_html(const char *markdown_string);
};
#endif // MARKDOWN_RENDER_H