Change markdown parser.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#include <QMetaObject>
|
||||
#include <QMimeDatabase>
|
||||
|
||||
#include "cmark.h"
|
||||
#include "html.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
@@ -205,8 +205,20 @@ QVariantList SpectralRoom::getUsers(const QString& prefix) {
|
||||
}
|
||||
|
||||
QString SpectralRoom::postMarkdownText(const QString& markdown) {
|
||||
QByteArray local = markdown.toLocal8Bit();
|
||||
const char* data = local.data();
|
||||
QString html = cmark_markdown_to_html(data, local.length(), 0);
|
||||
return postHtmlText(markdown, html);
|
||||
unsigned char *sequence = (unsigned char *) qstrdup(markdown.toUtf8().constData());
|
||||
qint64 length = strlen((char *) sequence);
|
||||
|
||||
hoedown_renderer* renderer = hoedown_html_renderer_new(HOEDOWN_HTML_USE_XHTML, 32);
|
||||
hoedown_extensions extensions = (hoedown_extensions) ((HOEDOWN_EXT_BLOCK | HOEDOWN_EXT_SPAN | HOEDOWN_EXT_MATH_EXPLICIT) & ~HOEDOWN_EXT_QUOTE);
|
||||
hoedown_document* document = hoedown_document_new(renderer, extensions, 32);
|
||||
hoedown_buffer* html = hoedown_buffer_new(length);
|
||||
hoedown_document_render(document, html, sequence, length);
|
||||
QString result = QString::fromUtf8((char *) html->data, html->size);
|
||||
|
||||
free(sequence);
|
||||
hoedown_buffer_free(html);
|
||||
hoedown_document_free(document);
|
||||
hoedown_html_renderer_free(renderer);
|
||||
|
||||
return postHtmlText(markdown, result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user