Table of Contents
Everything is functional. I must implement unit testing to ensure accurate and consistant bi-directional markdown/html conversion.
This library provides C, C++, and Qt5 enhanced bindings in order to make your life easier. This library can be installed by following through any of the installation sections of this readme.
To compile any of these examples, please follow the How to compile your program section.
Converting HTML to markdown:
#include <stdio.h>
#include <markdownpanda.h>
int main()
{
// HTML to Markdown
HtmlObject obj = load_html_from_string("<h1>Test</h1>");
// HtmlObject obj = load_html_from_file("myfile.html");
char *md = mdpanda_to_markdown(obj);
printf("%s", md);
destroy_html_object(obj);
// Markdown to HTML
char *html = mdpanda_to_html("# Test");
printf("%s", html);
free(html); // HTML is on the heap so we must free it.
}
#include <iostream>
#include <markdownpanda/cpp.hpp>
int main()
{
// HTML to Markdown
MarkdownPanda panda;
panda.loadHtmlFile("index.html");
// panda.loadHtmlString("<p>You could also use an std::string like this</p>");
std::cout << panda.markdown();
// Markdown to HTML
MarkdownPanda panda;
panda.loadMarkdownFile("index.md");
// panda.loadMarkdownString("You could also load an **std::string** like this.")
std::cout << panda.html();
}
#include <iostream>
#include <markdownpanda/qt.hpp>
int main()
{
// HTML to Markdown
MarkdownPandaQt panda;
panda.loadHtmlFile(":/index.html"); // Loading resource file or regular file
// panda.loadHtmlString("<p>You could also use a QString like this</p>");
std::cout << panda.markdown().toStdString();
// Markdown to HTML
MarkdownPandaQt panda;
panda.loadMarkdownFile(":/index.md"); // Loading resource file or regular file
// panda.loadMarkdownString("You could also use a **QString** like this");
std::cout << panda.html().toStdString();
}
A nice little shell script is available. It will build the dependencies and compile the entire project. MarkdownPanda will be installed to the build/ folder.
To install:
sh build.sh
Installing is pretty simple if you've got a little bit of experience with C/C++ libraries.
You will need the following C libraries:
If you don't want to install these on your own, you could install them locally in the following way.
In the following commands, you will clone the MarkdownPanda repository, change directory into it, pull down the MyHTML submodule (a dependency), compile MyHTML, and install it to the project root.
git clone https://gitlab.com/Open-App-Library/markdownpanda.git
cd markdownpanda
git submodule update --init
cd external-libraries/myhtml
make
make install prefix=../..
cd external-libraries/cmark-gfm
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=../../..
make
make install
With the following commands you will compile the project to a folder named "cmake" and then install the files into a folder named "dist".
mkdir cmake && cd cmake
cmake -DCMAKE_INSTALL_PREFIX=../build ..
make
make install
On Linux, you can compile with GCC.
gcc your-file.c -I /path-to/markdownpanda/dist/include/ -L /path-to/markdownpanda/dist/lib/ -lmarkdownpanda_static -lmyhtml_static -lcmark-gfm-extensions -lcmark-gfm -pthread
Note that you are specifying the path where the markdownpanda header files are, where the static libraries are, what static libraries to use, and you are finally specifying that you would like to use pthread.
Here is a CMake template as well.
CMakeLists.txt
cmake_minimum_required (VERSION 2.6)
project (MyApp)
include_directories("${PROJECT_SOURCE_DIR}/path-to/markdownpanda/dist/include")
find_package (Threads)
add_executable(myapp src/main.c)
target_link_libraries(mdpanda ${PROJECT_SOURCE_DIR}/path-to/markdownpanda/dist/lib/libmarkdownpanda_static.a)
target_link_libraries(mdpanda ${PROJECT_SOURCE_DIR}/path-to/markdownpanda/dist/lib/libmyhtml_static.a)
target_link_libraries(mdpanda ${PROJECT_SOURCE_DIR}/path-to/markdownpanda/dist/lib/libcmark-gfm-extensions.a)
target_link_libraries(mdpanda ${PROJECT_SOURCE_DIR}/path-to/markdownpanda/dist/lib/libcmark-gfm.a)
target_link_libraries (mdpanda ${CMAKE_THREAD_LIBS_INIT})
Pass EXCLUDE_MD2HTML=yes
to cmake. Ex. cmake .. -DEXCLUDE_MD2HTML=yes