-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMarkdown.cpp
More file actions
32 lines (31 loc) · 918 Bytes
/
Markdown.cpp
File metadata and controls
32 lines (31 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef LIPSUM_BUILD_STATIC
# define LIPSUM_IMPLEMENTATION
#endif
#include <memory>
#ifdef __EMSCRIPTEN__
# include <emscripten.h>
#endif
#include "lipsum.hpp"
#include "maddy/parser.h"
int main()
{
lpsm::Generator gen;
// generate markdown document with 20 elements
std::string text = gen.md_text(20);
std::cout << text;
// clang-format off
#ifdef __EMSCRIPTEN__
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
std::stringstream textStream = std::stringstream(text);
std::string htmlOutput = parser->Parse(textStream);
// js to put text in document
EM_ASM({
const htmlText = UTF8ToString($0);
const contentElem = document.createElement("div");
contentElem.innerHTML = htmlText;
document.querySelector("body").appendChild(contentElem);
}, htmlOutput.c_str());
#endif
// clang-format on
return 0;
}