mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
Copy react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67 (upstream software-mansion/enriched-markdown 766fc0e67) into packages/react-native-enriched-markdown, with patches/react-native-enriched-markdown+1.2.0-nightly-20261014-766fc0e67.patch applied. Nothing else changes in this commit; the package is not a workspace yet. Reproduce: npm pack react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67 tar xzf react-native-enriched-markdown-*.tgz mkdir -p t/node_modules && mv package t/node_modules/react-native-enriched-markdown (cd t && git init -q && git apply ../patches/react-native-enriched-markdown+*.patch) diff -r t/node_modules/react-native-enriched-markdown packages/react-native-enriched-markdown The diff is empty.
50 lines
2.0 KiB
C++
50 lines
2.0 KiB
C++
#include "../parser/MD4CParser.hpp"
|
|
#include "ASTSerializer.hpp"
|
|
#include <string>
|
|
|
|
// Static buffer for the JSON result.
|
|
// Safe for single-threaded WASM execution — the caller must consume (copy)
|
|
// the returned string before calling parseMarkdown again.
|
|
static std::string g_resultBuffer;
|
|
|
|
extern "C" {
|
|
|
|
/**
|
|
* Parse a markdown string and return its AST as a JSON string.
|
|
*
|
|
* @param markdown Null-terminated UTF-8 markdown input.
|
|
* @param underline 1 → enable __ underline extension; 0 → __ means emphasis.
|
|
* @param latexMath 1 → enable $…$ / $$…$$ LaTeX math spans; 0 → disable.
|
|
* @param superscript 1 → enable ^superscript^ spans; 0 → disable.
|
|
* @param subscript 1 → enable ~subscript~ spans; 0 → disable.
|
|
* @param highlight 1 → enable ==highlight== spans; 0 → disable.
|
|
* @param hardSoftBreaks 1 → treat soft breaks as hard breaks; 0 → collapse to space.
|
|
* @param preserveBlankLines 1 → report runs of blank lines as BlankLine nodes; 0 → collapse them.
|
|
* @param admonitions 1 → enable GitHub-style admonitions/alerts; 0 → disable.
|
|
* @return Null-terminated UTF-8 JSON string, valid until the next call.
|
|
*/
|
|
const char *parseMarkdown(const char *markdown, int underline, int latexMath, int superscript, int subscript,
|
|
int highlight, int hardSoftBreaks, int preserveBlankLines, int admonitions) {
|
|
if (!markdown) {
|
|
g_resultBuffer = "{\"type\":\"Document\"}";
|
|
return g_resultBuffer.c_str();
|
|
}
|
|
|
|
Markdown::Md4cFlags flags;
|
|
flags.underline = (underline != 0);
|
|
flags.latexMath = (latexMath != 0);
|
|
flags.superscript = (superscript != 0);
|
|
flags.subscript = (subscript != 0);
|
|
flags.highlight = (highlight != 0);
|
|
flags.hardSoftBreaks = (hardSoftBreaks != 0);
|
|
flags.preserveBlankLines = (preserveBlankLines != 0);
|
|
flags.admonitions = (admonitions != 0);
|
|
|
|
Markdown::MD4CParser parser;
|
|
auto root = parser.parse(std::string(markdown), flags);
|
|
g_resultBuffer = Markdown::ASTSerializer::serialize(*root);
|
|
return g_resultBuffer.c_str();
|
|
}
|
|
|
|
} // extern "C"
|