Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_markdown.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
56
57#ifndef N_MARKDOWN_H
58#define N_MARKDOWN_H
59
60#include <stddef.h>
61
63#define N_MARKDOWN_BOLD (1u << 0)
65#define N_MARKDOWN_ITALIC (1u << 1)
67#define N_MARKDOWN_CODE (1u << 2)
69#define N_MARKDOWN_LINK (1u << 3)
71#define N_MARKDOWN_STRIKE (1u << 4)
72
74#define N_MARKDOWN_HEADINGS (1u << 0)
76#define N_MARKDOWN_TABLES (1u << 1)
81#define N_MARKDOWN_AUTOLINKS (1u << 2)
83#define N_MARKDOWN_STRIKETHROUGH (1u << 3)
86#define N_MARKDOWN_ESCAPES (1u << 4)
90#define N_MARKDOWN_ALL (N_MARKDOWN_HEADINGS | N_MARKDOWN_TABLES)
92#define N_MARKDOWN_INLINE_ALL \
93 (N_MARKDOWN_AUTOLINKS | N_MARKDOWN_STRIKETHROUGH | N_MARKDOWN_ESCAPES)
94
96#define N_MARKDOWN_ALIGN_LEFT 0
98#define N_MARKDOWN_ALIGN_CENTER 1
100#define N_MARKDOWN_ALIGN_RIGHT 2
101
113
117typedef struct n_markdown_span {
118 char* text;
119 char* url;
120 unsigned style;
122
128
152
158
169void n_markdown_parse(const char* text, size_t len, n_markdown_doc* out);
170
189void n_markdown_parse_ex(const char* text, size_t len, unsigned flags, n_markdown_doc* out);
190
196
205int n_markdown_has_markup(const char* text, size_t len);
206
218int n_markdown_has_markup_ex(const char* text, size_t len, unsigned flags);
219
220#endif /* N_MARKDOWN_H */
void n_markdown_free(n_markdown_doc *doc)
free everything a n_markdown_doc owns and zero it
Definition n_markdown.c:918
n_markdown_span * spans
Definition n_markdown.h:125
n_markdown_inline * items
Definition n_markdown.h:142
n_markdown_inline inl
Definition n_markdown.h:140
n_markdown_block_kind
Block kinds.
Definition n_markdown.h:104
@ N_MARKDOWN_HEADING
"## " heading (inl, level)
Definition n_markdown.h:110
@ N_MARKDOWN_OL
ordered list (items)
Definition n_markdown.h:109
@ N_MARKDOWN_QUOTE
Definition n_markdown.h:106
@ N_MARKDOWN_TABLE
pipe table (items, n_cols)
Definition n_markdown.h:111
@ N_MARKDOWN_UL
unordered list (items)
Definition n_markdown.h:108
@ N_MARKDOWN_CODE_BLOCK
``` fenced code (raw code)
Definition n_markdown.h:107
@ N_MARKDOWN_PARA
paragraph
Definition n_markdown.h:105
int kind
enum n_markdown_block_kind
Definition n_markdown.h:139
unsigned char * align
TABLE: N_MARKDOWN_ALIGN_* per column, n_cols entries, owned.
Definition n_markdown.h:150
int n_markdown_has_markup_ex(const char *text, size_t len, unsigned flags)
1 if text contains any markup the given flags would render, else 0
Definition n_markdown.c:940
void n_markdown_parse(const char *text, size_t len, n_markdown_doc *out)
parse text (len bytes, plain UTF-8) into out
Definition n_markdown.c:706
n_markdown_block * blocks
Definition n_markdown.h:155
void n_markdown_parse_ex(const char *text, size_t len, unsigned flags, n_markdown_doc *out)
parse text into out, choosing which optional block kinds to recognise
Definition n_markdown.c:710
size_t n_cols
TABLE: cells per row, always at least 1.
Definition n_markdown.h:147
int n_markdown_has_markup(const char *text, size_t len)
1 if text contains any renderable markup, else 0
Definition n_markdown.c:936
int level
HEADING: 1 to 6.
Definition n_markdown.h:145
A parsed document: an owned array of blocks.
Definition n_markdown.h:154
One flow of inline runs (a paragraph, a quote, or one list item).
Definition n_markdown.h:124
One inline run: visible text, a style bitmask, and (for a link) an already-http(s)-validated url.
Definition n_markdown.h:117