|
|
NME.c File Reference
Detailed Description
Nyctergatis Markup Engine (simple text markup formatting based on Creole).
- Author:
- Yves Piguet. Copyright 2007-2008, Yves Piguet.
Definition in file NME.c.
#include "NME.h"
Go to the source code of this file.
|
Defines |
|
#define | kMaxNesting 8 |
| | maximum nesting of lists
|
|
#define | isBlank(c) ((c) == ' ' || (c) == '\t') |
| | Test if a character is a space or a tab.
|
|
#define | isEol(c) ((c) == '\r' || (c) == '\n') |
| | Test if a character is an eol.
|
|
#define | isDigit(c) ((c) >= '0' && (c) <= '9') |
| | Test if a character is a digit.
|
|
#define | isAlphaNum(c) ((c) >= 'a' && (c) <= 'z' || (c) >= 'A' && (c) <= 'Z' || isDigit(c)) |
| | Test if a character is alphabetic (ASCII) or numeric.
|
|
#define | isFirstUTF8Byte(c) (((c) & 0x80) == 0 || ((c) & 0xe0) == 0xc0 || ((c) & 0xf0) == 0xe0) |
| | Test if a byte is the first byte of a UTF-8 character.
|
|
#define | kMaxNumberedHeadingLevels 2 |
| | Maximum number of numbered heading levels.
|
|
#define | kMaxSectionLevels 4 |
| | Maximum number of heading-separated section levels.
|
|
#define | kTabWidth 4 |
| | Tabulator width.
|
|
#define | CheckError(c) do { err = (c); if (err != kNMEErrOk) return err; } while (0) |
| | Assign return value to err and return it unless kNMEErrOk.
|
|
#define | setContext(c, l, i) do { (c).level = l; (c).item = (i) < 0 ? 0 : (i); } while (0) |
| | Set the context level and item number.
|
|
#define | kExprStackSize 16 |
|
#define | kExprErrorValue 1 |
|
#define | SIZE "%{2*s}" |
|
#define | SIZEH "%{l=1&3*s|l=2&5*s/2|l=3&2*s|3*s/2}" |
| #define | HOOK(e, st) |
| #define | HOOK(cb, l, it, e, m) |
| #define | HOOK(cb, l, it, e, m) |
Enumerations |
| enum | {
kNMEListNumUL = -100,
kNMEListNumDT,
kNMEListNumDD,
kNMEListIndented,
kNMEListNumTableCell,
kNMEListNumTableHCell
} |
| | Special codes for list items (positive values are item numbers for OL). More...
|
| enum | NMEState {
kNMEStatePar,
kNMEStatePre,
kNMEStateHeading,
kNMEStateParAfterEol,
kNMEStatePreAfterEol,
kNMEStateBetweenPar
} |
| | Parser states (the whole state includes the current nested lists with item numbers for ordered lists, the stack of styles in the current paragraph and the URL location in the source code while decoding the link text).
|
| enum | NMEToken {
kNMETokenChar,
kNMETokenSpace,
kNMETokenTab,
kNMETokenEOL,
kNMETokenHeading,
kNMETokenLineBreak,
kNMETokenLI,
kNMETokenDD,
kNMETokenTableCell,
kNMETokenTableHCell,
kNMETokenHR,
kNMETokenPre,
kNMETokenStyle,
kNMETokenLinkBegin,
kNMETokenLinkEnd,
kNMETokenImageBegin,
kNMETokenImageEnd,
kNMETokenPlugin,
kNMETokenPluginBlock,
kNMETokenPlaceholder,
kNMETokenPlaceholderBlock
} |
| | Parsed token. More...
|
| enum | NMEStyle {
kNMEStyleBold = 0,
kNMEStyleItalic,
kNMEStyleUnderline,
kNMEStyleSuperscript,
kNMEStyleSubscript,
kNMEStyleMonospace,
kNMEStyleVerbatim,
kNMEStyleLink,
kNMEStyleImage,
kNMEStylesCount
} |
| | Text style. More...
|
Functions |
| static void | skipBlanks (NMEConstText src, NMEInt srcLen, NMEInt *i) |
| | Skip spaces and tabs.
|
| static void | execOperator (NMEInt stack[], NMEInt *stackDepth, NMEChar op) |
| | Execute operator.
|
| static NMEInt | evalExpression (NMEConstText src, NMEInt srcLen, NMEContext const *context) |
| | Evaluate expression (Are supported: + - * / = !(ne) > < & |, parenthesis, integers, l=level, i=item, s=size).
|
| NMEBoolean | NMEAddString (NMEConstText str, NMEInt strLen, NMEChar ctrlChar, NMEContext *context) |
| | Add a string to output, converting eol and embedded expressions.
|
| NMEErr | NMECopySource (NMEInt length, NMEBoolean copy, NMEBoolean encodeChar, NMEContext *context) |
| | Copy or skip source to output.
|
| static NMEErr | checkWordwrap (NMEContext *context, NMEOutputFormat const *outputFormat) |
| | Check wordwrap, inserting an end-of-line and spaces for indenting if required.
|
| NMEErr | NMEEncodeCharFunDict (NMEConstText src, NMEInt srcLen, NMEInt *srcIx, NMEContext *context, void *data) |
| | NMEEncodeCharFun function which replaces characters listed in a table with strings.
|
| NMEErr | encodeCharFunNME (NMEConstText src, NMEInt srcLen, NMEInt *srcIx, NMEContext *context, void *data) |
| | NMEEncodeCharFun function for NME output; characters are left unescaped when possible.
|
| static NMEErr | encodeURLFunNull (NMEConstText link, NMEInt linkLen, NMEContext *context, void *data) |
| | NMEEncodeURLFun function which encodes link to a URL for null output, producing no output.
|
| static NMEErr | encodeCharFunNull (NMEConstText src, NMEInt srcLen, NMEInt *srcIx, NMEContext *context, void *data) |
| | NMEEncodeCharFun function which encodes characters for null output, producing no output; the encodeCharData field is ignored (can be set to NULL).
|
| static NMEWordwrapPermission | wordwrapCheckNMEFun (NMEConstText txt, NMEInt len, NMEInt i, void *data) |
| | NMEWordwrapCheckFun function to check valid wordwrap point for NME (don't break line before stars, sharps, eq, pipes).
|
| static NMEErr | encodeCharRTFFun (NMEConstText src, NMEInt srcLen, NMEInt *srcIx, NMEContext *context, void *data) |
| | NMEEncodeCharFun function which encodes characters for RTF.
|
| static NMEErr | encodeURLFunRTF (NMEConstText link, NMEInt linkLen, NMEContext *context, void *data) |
| | NMEEncodeURLFun function which encodes link to a URL for RTF output.
|
| static NMEWordwrapPermission | wordwrapCheckRTFFun (NMEConstText txt, NMEInt len, NMEInt i, void *data) |
| | NMEWordwrapCheckFun function to check valid wordwrap point for RTF (keep space).
|
| static NMEErr | addLink (NMEContext *context, NMEOutputFormat const *outputFormat) |
| | Add link to dest, substituting interwiki if necessary.
|
| static NMEBoolean | findStyleInStyleStack (NMEStyle const styleStack[], NMEInt styleNesting, NMEStyle style, NMEInt *i) |
| | Find style in stack of styles.
|
| static NMEConstText | styleMarkerFromStyleID (NMEStyle style) |
| | Get style marker string associated to a style constant.
|
| static NMEErr | processStyleTag (NMEStyle styleStack[], NMEInt *styleNesting, NMEStyle style, NMEInt i0, NMEOutputFormat const *outputFormat, NMEContext *context) |
| | Process style tag.
|
| static NMEErr | flushStyleTags (NMEStyle styleStack[kNMEStylesCount], NMEInt *styleNesting, NMEInt i0, NMEOutputFormat const *outputFormat, NMEContext *context) |
| | Flush waiting style tags.
|
| static NMEErr | addEndPar (NMEBoolean forceEndOfList, NMEOutputFormat const *outputFormat, NMEContext *context) |
| | Add an endPar, endIndented, endULItem or endOLItem.
|
| static NMEErr | addLinkBegin (NMEBoolean isImage, NMEStyle styleStack[kNMEStylesCount], NMEInt *styleNesting, NMEInt i0, NMEOutputFormat const *outputFormat, NMEContext *context) |
| | Parse the beginning of a link and leave the parsing point at the beginning of the link text.
|
| static NMEInt | findPlugin (NMEConstText src, NMEInt srcLen, NMEInt i, NMEBoolean isPlaceholder, NMEOutputFormat const *outputFormat) |
| | Find plugin.
|
| static NMEErr | addPlugin (NMEBoolean isBlock, NMEBoolean isPlaceholder, NMEInt options, NMEOutputFormat const *outputFormat, NMEContext *context, NMEBoolean *reparseOutput) |
| | Parse and process a plugin tag.
|
| static void | nextHeading (NMEInt *headingFlags, NMEInt headingNum[], NMEInt headingLevel) |
| | Update heading index and Increment heading number at the specified level, resetting higher levels.
|
| static NMEBoolean | parseNextToken (NMEConstText src, NMEInt srcLen, NMEInt *i, NMEState state, NMEBoolean verbatim, NMEInt nesting, NMEInt const listNum[], NMEStyle const styleStack[], NMEInt styleNesting, NMEOutputFormat const *outputFormat, NMEToken *token, NMEInt *headingLevel, NMEInt *itemNesting, NMEStyle *style, NMEInt options) |
| | Parse next token, skipping it in the source code.
|
| static NMEErr | swapBuffers (NMEText *src, NMEInt *srcLen, NMEContext *context, NMEInt *commonLen, NMEInt destLen0) |
| | Swap source and destination buffers after some plugin or autoconvert output must be reparsed.
|
| NMEErr | NMEProcess (NMEConstText nmeText, NMEInt nmeTextLen, NMEText buf, NMEInt bufSize, NMEInt options, NMEConstText eol, NMEOutputFormat const *outputFormat, NMEInt fontSize, NMEText *output, NMEInt *outputLen, NMEInt *outputUCS16Len) |
| | Transform text by interpreting markup.
|
| void | NMEGetTempMemory (NMEContext const *context, NMEText *addr, NMEInt *len) |
| | Get temporary memory which can be used in plugin, autolink and hook functions.
|
| void | NMEGetFormat (NMEContext const *context, NMEOutputFormat const **outputFormat, NMEInt *options, NMEInt *fontSize) |
| | Get current output format and options.
|
| NMEInt | NMECurrentOutputIndex (NMEContext const *context) |
| | Accessor for output index.
|
| NMEInt | NMECurrentOutputIndexUCS16 (NMEContext const *context) |
| | Accessor for output index in unicode characters, assuming UTF-8 input.
|
| void | NMECurrentLink (NMEContext const *context, NMEInt *linkOffset, NMEInt *linkLength) |
| | Accessor for current link or image (can be called from hook "[[" or "{{"), before any processing by NMEEncodeURLFun.
|
| void | NMECurrentOutput (NMEContext const *context, NMEConstText *output, NMEInt *outputLength) |
| | Accessor for output produced until now (provides context which can be used by to decide if a character should be escaped).
|
| NMEConstText | NMECurrentListNesting (NMEContext const *context) |
| | Accessor for current list nesting as a string of NME markup characters.
|
Variables |
| static NMEEncodeCharDict const | htmlCharDict [] |
| | Table of character substitutions for HTML or XML.
|
| static NMEEncodeCharDict const | latexCharDict [] |
| | Table of character substitutions for LaTeX.
|
|
NMEOutputFormat const | NMEOutputFormatText |
| | Format strings for plain text output.
|
|
NMEOutputFormat const | NMEOutputFormatTextCompact |
| | Format strings for plain text output with fewer blank lines.
|
|
NMEOutputFormat const | NMEOutputFormatNull |
| | Format strings for no output.
|
|
NMEOutputFormat const | NMEOutputFormatNME |
| | Format strings for NME text output.
|
|
NMEOutputFormat const | NMEOutputFormatHTML |
| | Format strings for HTML output.
|
|
NMEOutputFormat const | NMEOutputFormatRTF |
| | Format strings for RTF output.
|
|
NMEOutputFormat const | NMEOutputFormatLaTeX |
| | Format strings for LaTeX output.
|
| NMEOutputFormat const | NMEOutputFormatMan |
| | Format strings for man page output.
|
Define Documentation
| #define HOOK |
( |
cb, |
|
|
l, |
|
|
it, |
|
|
e, |
|
|
m |
|
) |
|
Value: do { \
if (outputFormat->cb) \
{ \
err = outputFormat->cb(l, it, e, m, i0 + context.srcIndexOffset, \
&context, \
outputFormat->hookData); \
if (err != kNMEErrOk) \
return err; \
} \
} while (0)
| #define HOOK |
( |
cb, |
|
|
l, |
|
|
it, |
|
|
e, |
|
|
m |
|
) |
|
Value: do { \
if (outputFormat->cb) \
CheckError(outputFormat->cb(l, it, e, m, \
context->srcIndexOffset + context->srcIndex, \
context, \
outputFormat->hookData)); \
} while (0)
Value: do { \
if (outputFormat->spanHookFun) \
{ \
NMEConstText styleStr = styleMarkerFromStyleID(st); \
if (styleStr) \
CheckError(outputFormat->spanHookFun(kNMEHookLevelSpan, 0, e, styleStr, \
i0 + context->srcIndexOffset, \
context, \
outputFormat->hookData)); \
} \
} while (0)
Enumeration Type Documentation
Special codes for list items (positive values are item numbers for OL).
- Enumerator:
-
| kNMEListNumUL |
unnumbered list item |
| kNMEListNumDT |
title in definition list |
| kNMEListNumDD |
definition in definition list |
| kNMEListIndented |
indented paragraph |
| kNMEListNumTableCell |
table cell |
| kNMEListNumTableHCell |
table heading cell |
Definition at line 14 of file NME.c.
Text style.
- Enumerator:
-
| kNMEStyleBold |
bold |
| kNMEStyleItalic |
italic |
| kNMEStyleUnderline |
underline |
| kNMEStyleSuperscript |
superscript |
| kNMEStyleSubscript |
subscript |
| kNMEStyleMonospace |
monospace (code) |
| kNMEStyleVerbatim |
verbatim |
| kNMEStyleLink |
link text |
| kNMEStyleImage |
image alt text |
| kNMEStylesCount |
number of different styles (max. nesting) |
Definition at line 94 of file NME.c.
Parsed token.
- Enumerator:
-
| kNMETokenChar |
any other character |
| kNMETokenSpace |
space |
| kNMETokenTab |
tab |
| kNMETokenEOL |
CR or LF or CRLF. |
| kNMETokenHeading |
one or more '=' |
| kNMETokenLineBreak |
double backslash |
| kNMETokenLI |
*, #, ;, or : (indenting) at beginning of line (not ** without space) |
| kNMETokenDD |
: after a space in the context of kNMEListNumDT |
| kNMETokenTableCell |
single pipe |
| kNMETokenTableHCell |
double pipe |
| kNMETokenPre |
{{{ or }}} alone in a line |
| kNMETokenStyle |
any style (including verbatim) but link |
| kNMETokenLinkBegin |
[[ |
| kNMETokenLinkEnd |
]] |
| kNMETokenImageBegin |
{{ |
| kNMETokenImageEnd |
}} |
| kNMETokenPlugin |
<< with other data on the same line |
| kNMETokenPluginBlock |
<< alone on a line (end tag must also be alone) |
| kNMETokenPlaceholder |
<<< with other data on the same line |
| kNMETokenPlaceholderBlock |
<<< alone on a line (end tag must also be alone) |
Definition at line 68 of file NME.c.
Function Documentation
Add an endPar, endIndented, endULItem or endOLItem.
- Parameters:
-
| [in] | forceEndOfList | if TRUE, all current lists are ended |
| [in] | outputFormat | format strings |
| [in,out] | context | current context |
- Returns:
- error code (kNMEErrOk for success)
Definition at line 1687 of file NME.c.
Add link to dest, substituting interwiki if necessary.
- Parameters:
-
| [in,out] | context | current context where link position and source is stored |
| [in] | outputFormat | format strings, or NULL for default |
- Returns:
- error code (kNMEErrOk for success)
Definition at line 1345 of file NME.c.
Parse the beginning of a link and leave the parsing point at the beginning of the link text.
- Parameters:
-
| [in] | isImage | TRUE for image, FALSE for link |
| [in,out] | styleStack | stack of styles |
| [in,out] | styleNesting | number of styles in stack |
| [in] | i0 | index in src of beginning of tag |
| [in] | outputFormat | format strings, or NULL for default |
| [in,out] | context | current context (where link position is stored) |
- Returns:
- error code (kNMEErrOk for success)
Definition at line 1814 of file NME.c.
Parse and process a plugin tag.
- Parameters:
-
| [in] | isBlock | if TRUE, end tag must be alone in a line |
| [in] | isPlaceholder | if TRUE, end tag must be triple right angle brackets |
| [in] | options | kNMEProcessOptDefault or sum of options |
| [in] | outputFormat | format strings, or NULL for default |
| [in,out] | context | current context |
| [out] | reparseOutput | TRUE if plugin's output is NME which should be parsed again |
- Returns:
- error code (kNMEErrOk for success)
Definition at line 1963 of file NME.c.
Check wordwrap, inserting an end-of-line and spaces for indenting if required.
- Parameters:
-
| [in,out] | context | current context |
| [in] | outputFormat | format strings (can be NULL) |
- Returns:
- error code (kNMEErrOk for success)
Definition at line 538 of file NME.c.
NMEEncodeCharFun function for NME output; characters are left unescaped when possible.
- Parameters:
-
| [in] | src | input characters |
| [in] | srcLen | size of src in bytes |
| [in,out] | srcIx | index in src (updated by one character) |
| [in,out] | context | context used to deciding whether to escape |
| [in,out] | data | not used (NULL) |
- Returns:
- error code (kNMEErrOk for success)
- See also:
- NMEOutputFormat
< character which must be escaped
< previous character, or '
' for line beginning (w/ leading spaces), or 0 for any
Definition at line 665 of file NME.c.
NMEEncodeCharFun function which encodes characters for null output, producing no output; the encodeCharData field is ignored (can be set to NULL).
- Parameters:
-
| [in] | src | input characters |
| [in] | srcLen | size of src in bytes |
| [in,out] | srcIx | index in src (should be updated by one character) |
| [in,out] | context | current context |
| [in,out] | data | ignored |
- Returns:
- error code (kNMEErrOk for success)
- See also:
- NMEOutputFormat
Definition at line 849 of file NME.c.
NMEEncodeCharFun function which encodes characters for RTF.
Special RTF characters (backslash and braces) are escaped and multibyte characters are written in hexadecimal. Its address should be stored in the encodeCharFun field of NMEOutputFormat; the encodeCharData field is ignored (can be set to NULL). - Parameters:
-
| [in] | src | input characters |
| [in] | srcLen | size of src in bytes |
| [in,out] | srcIx | index in src (should be updated by one character) |
| [in,out] | context | current context |
| [in,out] | data | ignored |
- Returns:
- error code (kNMEErrOk for success)
- See also:
- NMEOutputFormat
Definition at line 1045 of file NME.c.
NMEEncodeURLFun function which encodes link to a URL for null output, producing no output.
- Parameters:
-
| [in] | link | input characters (ignored) |
| [in] | linkLen | length of link (ignored) |
| [in,out] | context | current context (ignored) |
| [in,out] | data | value specific to the callback (ignored) |
- Returns:
- error code (always kNMEErrOk)
Definition at line 833 of file NME.c.
NMEEncodeURLFun function which encodes link to a URL for RTF output.
- Parameters:
-
| [in] | link | input characters |
| [in] | linkLen | length of link |
| [in,out] | context | current context |
| [in,out] | data | value specific to the callback (ignored) |
- Returns:
- error code
Definition at line 1118 of file NME.c.
Evaluate expression (Are supported: + - * / = !(ne) > < & |, parenthesis, integers, l=level, i=item, s=size).
- Parameters:
-
| [in] | src | source code |
| [in] | srcLen | length of source code |
| [in] | context | context for variables |
- Returns:
- result, or 1 if error
< operator character (nul for end of list)
< operator priority
Definition at line 211 of file NME.c.
Execute operator.
- Parameters:
-
| [in,out] | stack | operand stack |
| [in,out] | stackDepth | operand stack depth |
| [in] | op | operator |
Definition at line 164 of file NME.c.
Find plugin.
- Parameters:
-
| [in] | src | source text with markup |
| [in] | srcLen | source text length |
| [in] | i | parsing point |
| [in] | isPlaceholder | if TRUE, end tag must be triple right angle brackets |
| [in] | outputFormat | format strings, or NULL for default |
- Returns:
- index of plugin in outputFormat->plugins, or -1 if not found
Definition at line 1912 of file NME.c.
Find style in stack of styles.
- Parameters:
-
| [in] | styleStack | stack of styles |
| [in] | styleNesting | number of styles in stack |
| [in] | style | style to find |
| [out] | i | set to index of index matching style if found and i not NULL |
- Returns:
- TRUE if found, FALSE if not found
Definition at line 1406 of file NME.c.
Flush waiting style tags.
- Parameters:
-
| [in,out] | styleStack | stack of styles |
| [in,out] | styleNesting | number of styles in stack |
| [in] | i0 | index in src of beginning of tag |
| [in] | outputFormat | format strings |
| [in,out] | context | current context |
- Returns:
- error code (kNMEErrOk for success)
Definition at line 1610 of file NME.c.
| static void nextHeading |
( |
NMEInt * |
headingFlags, |
|
|
NMEInt |
headingNum[], |
|
|
NMEInt |
headingLevel | |
|
) |
| | [static] |
Update heading index and Increment heading number at the specified level, resetting higher levels.
- Parameters:
-
| [in,out] | headingFlags | bit field with 1 if inside a section at that level ([0]=level 1) |
| [in,out] | headingNum | array of heading numbers ([0]=level 1) |
| [in] | headingLevel | heading level to increment (1=level 1) |
Definition at line 2071 of file NME.c.
Add a string to output, converting eol and embedded expressions.
- Parameters:
-
| [in] | str | null-terminated string to append |
| [in] | strLen | length of str, or -1 for null-terminated string |
| [in] | ctrlChar | control character for embedded expressions |
| [in,out] | context | current context |
- Returns:
- TRUE for success, FALSE for failure (not enough space)
Definition at line 345 of file NME.c.
Copy or skip source to output.
- Parameters:
-
| [in] | length | number of bytes of source to consume |
| [in] | copy | TRUE to copy source, FALSE to skip |
| [in] | encodeChar | TRUE to use encodeCharFun, FALSE for plain copy |
| [in,out] | context | current context |
- Returns:
- TRUE for success, FALSE for failure (not enough space)
Definition at line 488 of file NME.c.
Accessor for current link or image (can be called from hook "[[" or "{{"), before any processing by NMEEncodeURLFun.
- Parameters:
-
| [in] | context | current context |
| [out] | linkOffset | offset of link in NME source text |
| [out] | linkLength | length of link |
Definition at line 3771 of file NME.c.
Accessor for current list nesting as a string of NME markup characters.
- Parameters:
-
| [in] | context | current context |
- Returns:
- string (constant, valid until next call)
Definition at line 3787 of file NME.c.
Accessor for output produced until now (provides context which can be used by to decide if a character should be escaped).
- Parameters:
-
| [in] | context | current context |
| [out] | output | address of output (not provided if NULL) |
| [out] | outputLength | current length of output in bytes (not provided if NULL) |
Definition at line 3778 of file NME.c.
Accessor for output index.
- Parameters:
-
| [in] | context | current context |
- Returns:
- current output index
Definition at line 3761 of file NME.c.
Accessor for output index in unicode characters, assuming UTF-8 input.
- Parameters:
-
| [in] | context | current context |
- Returns:
- current output index
Definition at line 3766 of file NME.c.
NMEEncodeCharFun function which replaces characters listed in a table with strings.
Characters not in the table are copied unmodified. Its address should be stored in the encodeCharFun field of NMEOutputFormat, while the adresse of a table of type NMEEncodeCharDict[] ending with {0,NULL} should be stored in the encodeCha | |