nyctergatis.com

Contact

Projects
Sysquake Remote Live
NME
PDF
Hike
Sudoku
GifBuilder
jpeglib for Palm OS
MySQL Client
Cross-GCC for Mac OS
NME.c File Reference

Nyctergatis Markup Engine (simple text markup formatting based on Creole) More...

#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)

Typedefs

typedef enum NMEState NMEState
 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)
typedef enum NMEToken NMEToken
 Parsed token.
typedef enum NMEStyle NMEStyle
 Text style.

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 void updateLineNum (NMEContext *context)
 Update srcLineNum and srcIndexForLineNum so that srcIndexForLineNum = srcIndex.
static NMEInt evalExpression (NMEConstText src, NMEInt srcLen, NMEContext *context)
 Evaluate expression (are supported: + - * / = !(ne) > < & | ? :, parenthesis, integers, l=level, i=item, s=size, o=src offset, L=line num, p=dest offset, x=xref).
NMEBoolean NMEAddString (NMEConstText str, NMEInt strLen, NMEChar ctrlChar, NMEContext *context)
 Add a string to output, converting eol and embedded expressions.
NMEErr NMEAddRawString (NMEConstText str, NMEInt strLen, NMEContext *context)
 Copy a raw string to output, without any conversion.
NMEErr NMECopySource (NMEInt length, NMEBoolean copy, NMEBoolean encodeChar, NMEContext *context)
 Copy or skip source to output.
void NMEResetOutput (NMEContext *context)
 Reset output (can be used in a hook).
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.
static NMEErr encodeCharFunNME (NMEConstText src, NMEInt srcLen, NMEInt *srcIx, NMEContext *context, void *data)
 encodeCharFunNME 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, NMEContext *context, void *data)
 NMEWordwrapCheckFun function to check valid wordwrap point for NME (don't break line before stars, sharps, eq, pipes, or in a table)
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, NMEContext *context, 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, NMEInt srcIndexEndPar)
 Add an endPar, endIndented, endULItem, endOLItem, endDT, endDD, or endTableRow.
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 NMECurrentInputIndex (NMEContext const *context)
 Accessor for input index.
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 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

NMEEncodeCharDict const NMEXMLCharDict []
 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 NMEOutputFormatDebug
 Format strings for debug output (valid XML)
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.

Detailed Description

Nyctergatis Markup Engine (simple text markup formatting based on Creole)

Author:
Yves Piguet.

Definition in file NME.c.


Define Documentation

#define HOOK (   e,
  st 
)
Value:
do { \
        if (outputFormat->spanHookFun) \
        { \
            NMEConstText styleStr = styleMarkerFromStyleID(st); \
            if (styleStr) \
            { \
                updateLineNum(context); \
                CheckError(outputFormat->spanHookFun(kNMEHookLevelSpan, 0, e, styleStr, \
                        i0 + context->srcIndexOffset, \
                        context->srcLineNum, \
                        context, \
                        outputFormat->hookData)); \
            } \
        } \
    } while (0)
#define HOOK (   cb,
  l,
  it,
  e,
 
)
Value:
do { \
        if (outputFormat->cb) \
        { \
            updateLineNum(context); \
            CheckError(outputFormat->cb(l, it, e, m, \
                    context->srcIndexOffset + srcIndexEndPar, \
                    context->srcLineNum, \
                    context, \
                    outputFormat->hookData)); \
        } \
    } while (0)
#define HOOK (   cb,
  l,
  it,
  e,
 
)
Value:
do { \
        if (outputFormat->cb) \
        { \
            updateLineNum(&context); \
            err = outputFormat->cb(l, it, e, m, \
                    i0 + context.srcIndexOffset, \
                    context.srcLineNum, \
                    &context, \
                    outputFormat->hookData); \
            if (err != kNMEErrOk) \
                return err; \
        } \
    } while (0)

Enumeration Type Documentation

anonymous enum

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 17 of file NME.c.

enum NMEStyle

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 97 of file NME.c.

enum NMEToken

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

kNMETokenHR 

at least 4 hyphens at beginning of line

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 71 of file NME.c.


Function Documentation

static NMEErr addEndPar ( NMEBoolean  forceEndOfList,
NMEOutputFormat const *  outputFormat,
NMEContext context,
NMEInt  srcIndexEndPar 
) [static]

Add an endPar, endIndented, endULItem, endOLItem, endDT, endDD, or endTableRow.

Parameters:
[in]forceEndOfListif TRUE, all current lists or table are ended
[in]outputFormatformat strings
[in,out]contextcurrent context
[in]srcIndexEndParvalue of srcIndex at end par
Returns:
error code (kNMEErrOk for success)

Definition at line 1825 of file NME.c.

static NMEErr addLink ( NMEContext context,
NMEOutputFormat const *  outputFormat 
) [static]

Add link to dest, substituting interwiki if necessary.

Parameters:
[in,out]contextcurrent context where link position and source is stored
[in]outputFormatformat strings, or NULL for default
Returns:
error code (kNMEErrOk for success)

Definition at line 1474 of file NME.c.

static NMEErr addLinkBegin ( NMEBoolean  isImage,
NMEStyle  styleStack[kNMEStylesCount],
NMEInt styleNesting,
NMEInt  i0,
NMEOutputFormat const *  outputFormat,
NMEContext context 
) [static]

Parse the beginning of a link and leave the parsing point at the beginning of the link text.

Parameters:
[in]isImageTRUE for image, FALSE for link
[in,out]styleStackstack of styles
[in,out]styleNestingnumber of styles in stack
[in]i0index in src of beginning of tag
[in]outputFormatformat strings, or NULL for default
[in,out]contextcurrent context (where link position is stored)
Returns:
error code (kNMEErrOk for success)

Definition at line 1997 of file NME.c.

static NMEErr addPlugin ( NMEBoolean  isBlock,
NMEBoolean  isPlaceholder,
NMEInt  options,
NMEOutputFormat const *  outputFormat,
NMEContext context,
NMEBoolean reparseOutput 
) [static]

Parse and process a plugin tag.

Parameters:
[in]isBlockif TRUE, end tag must be alone in a line
[in]isPlaceholderif TRUE, end tag must be triple right angle brackets
[in]optionskNMEProcessOptDefault or sum of options
[in]outputFormatformat strings, or NULL for default
[in,out]contextcurrent context
[out]reparseOutputTRUE if plugin's output is NME which should be parsed again
Returns:
error code (kNMEErrOk for success)

Definition at line 2179 of file NME.c.

static NMEErr checkWordwrap ( NMEContext context,
NMEOutputFormat const *  outputFormat 
) [static]

Check wordwrap, inserting an end-of-line and spaces for indenting if required.

Parameters:
[in,out]contextcurrent context
[in]outputFormatformat strings (can be NULL)
Returns:
error code (kNMEErrOk for success)

Definition at line 593 of file NME.c.

static NMEErr encodeCharFunNME ( NMEConstText  src,
NMEInt  srcLen,
NMEInt srcIx,
NMEContext context,
void *  data 
) [static]

encodeCharFunNME function for NME output; characters are left unescaped when possible.

Parameters:
[in]srcinput characters
[in]srcLensize of src in bytes
[in,out]srcIxindex in src (updated by one character)
[in,out]contextcontext used to deciding whether to escape
[in,out]datanot 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 720 of file NME.c.

static NMEErr encodeCharFunNull ( NMEConstText  src,
NMEInt  srcLen,
NMEInt srcIx,
NMEContext context,
void *  data 
) [static]

NMEEncodeCharFun function which encodes characters for null output, producing no output; the encodeCharData field is ignored (can be set to NULL).

Parameters:
[in]srcinput characters
[in]srcLensize of src in bytes
[in,out]srcIxindex in src (should be updated by one character)
[in,out]contextcurrent context
[in,out]dataignored
Returns:
error code (kNMEErrOk for success)
See also:
NMEOutputFormat

Definition at line 955 of file NME.c.

static NMEErr encodeCharRTFFun ( NMEConstText  src,
NMEInt  srcLen,
NMEInt srcIx,
NMEContext context,
void *  data 
) [static]

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]srcinput characters
[in]srcLensize of src in bytes
[in,out]srcIxindex in src (should be updated by one character)
[in,out]contextcurrent context
[in,out]dataignored
Returns:
error code (kNMEErrOk for success)
See also:
NMEOutputFormat

Definition at line 1169 of file NME.c.

static NMEErr encodeURLFunNull ( NMEConstText  link,
NMEInt  linkLen,
NMEContext context,
void *  data 
) [static]

NMEEncodeURLFun function which encodes link to a URL for null output, producing no output.

Parameters:
[in]linkinput characters (ignored)
[in]linkLenlength of link (ignored)
[in,out]contextcurrent context (ignored)
[in,out]datavalue specific to the callback (ignored)
Returns:
error code (always kNMEErrOk)

Definition at line 939 of file NME.c.

static NMEErr encodeURLFunRTF ( NMEConstText  link,
NMEInt  linkLen,
NMEContext context,
void *  data 
) [static]

NMEEncodeURLFun function which encodes link to a URL for RTF output.

Parameters:
[in]linkinput characters
[in]linkLenlength of link
[in,out]contextcurrent context
[in,out]datavalue specific to the callback (ignored)
Returns:
error code

Definition at line 1242 of file NME.c.

static NMEInt evalExpression ( NMEConstText  src,
NMEInt  srcLen,
NMEContext context 
) [static]

Evaluate expression (are supported: + - * / = !(ne) > < & | ? :, parenthesis, integers, l=level, i=item, s=size, o=src offset, L=line num, p=dest offset, x=xref).

Parameters:
[in]srcsource code
[in]srcLenlength of source code
[in,out]contextcontext for variables
Returns:
result, or 1 if error

< operator character (nul for end of list)

< operator priority

Definition at line 234 of file NME.c.

static void execOperator ( NMEInt  stack[],
NMEInt stackDepth,
NMEChar  op 
) [static]

Execute operator.

Parameters:
[in,out]stackoperand stack
[in,out]stackDepthoperand stack depth
[in]opoperator

Definition at line 169 of file NME.c.

static NMEInt findPlugin ( NMEConstText  src,
NMEInt  srcLen,
NMEInt  i,
NMEBoolean  isPlaceholder,
NMEOutputFormat const *  outputFormat 
) [static]

Find plugin.

Parameters:
[in]srcsource text with markup
[in]srcLensource text length
[in]iparsing point
[in]isPlaceholderif TRUE, end tag must be triple right angle brackets
[in]outputFormatformat strings, or NULL for default
Returns:
index of plugin in outputFormat->plugins, or -1 if not found

Definition at line 2128 of file NME.c.

static NMEBoolean findStyleInStyleStack ( NMEStyle const  styleStack[],
NMEInt  styleNesting,
NMEStyle  style,
NMEInt i 
) [static]

Find style in stack of styles.

Parameters:
[in]styleStackstack of styles
[in]styleNestingnumber of styles in stack
[in]stylestyle to find
[out]iset to index of index matching style if found and i not NULL
Returns:
TRUE if found, FALSE if not found

Definition at line 1535 of file NME.c.

static NMEErr flushStyleTags ( NMEStyle  styleStack[kNMEStylesCount],
NMEInt styleNesting,
NMEInt  i0,
NMEOutputFormat const *  outputFormat,
NMEContext context 
) [static]

Flush waiting style tags.

Parameters:
[in,out]styleStackstack of styles
[in,out]styleNestingnumber of styles in stack
[in]i0index in src of beginning of tag
[in]outputFormatformat strings
[in,out]contextcurrent context
Returns:
error code (kNMEErrOk for success)

Definition at line 1743 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]headingFlagsbit field with 1 if inside a section at that level ([0]=level 1)
[in,out]headingNumarray of heading numbers ([0]=level 1)
[in]headingLevelheading level to increment (1=level 1)

Definition at line 2287 of file NME.c.

NMEErr NMEAddRawString ( NMEConstText  str,
NMEInt  strLen,
NMEContext context 
)

Copy a raw string to output, without any conversion.

Parameters:
[in]strstring to append
[in]strLenlength of str in bytes, or -1 for null-terminated string
[in,out]contextcurrent context
Returns:
kNMEErrOk for success, else error code

Definition at line 509 of file NME.c.

NMEBoolean NMEAddString ( NMEConstText  str,
NMEInt  strLen,
NMEChar  ctrlChar,
NMEContext context 
)

Add a string to output, converting eol and embedded expressions.

Parameters:
[in]strstring to append
[in]strLenlength of str in bytes, or -1 for null-terminated string
[in]ctrlCharcontrol character for embedded expressions
[in,out]contextcurrent context
Returns:
TRUE for success, FALSE for failure (not enough space)

Definition at line 373 of file NME.c.

NMEErr NMECopySource ( NMEInt  length,
NMEBoolean  copy,
NMEBoolean  encodeChar,
NMEContext context 
)

Copy or skip source to output.

Parameters:
[in]lengthnumber of bytes of source to consume
[in]copyTRUE to copy source, FALSE to skip
[in]encodeCharTRUE to use encodeCharFun, FALSE for plain copy
[in,out]contextcurrent context
Returns:
kNMEErrOk for success, else error code

Definition at line 538 of file NME.c.

NMEInt NMECurrentInputIndex ( NMEContext const *  context)

Accessor for input index.

Parameters:
[in]contextcurrent context
Returns:
current input index

Definition at line 4212 of file NME.c.

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.

Parameters:
[in]contextcurrent context
[out]linkOffsetoffset of link in NME source text
[out]linkLengthlength of link

Definition at line 4227 of file NME.c.

NMEConstText NMECurrentListNesting ( NMEContext const *  context)

Accessor for current list nesting as a string of NME markup characters.

Parameters:
[in]contextcurrent context
Returns:
string (constant, valid until next call)

Definition at line 4243 of file NME.c.

void NMECurrentOutput ( NMEContext const *  context,
NMEConstText output,
NMEInt outputLength 
)

Accessor for output produced until now (provides context which can be used to decide if a character should be escaped).

Parameters:
[in]contextcurrent context
[out]outputaddress of output (not provided if NULL)
[out]outputLengthcurrent length of output in bytes (not provided if NULL)

Definition at line 4234 of file NME.c.

NMEInt NMECurrentOutputIndex ( NMEContext const *  context)

Accessor for output index.

Parameters:
[in]contextcurrent context
Returns:
current output index

Definition at line 4217 of file NME.c.

NMEInt NMECurrentOutputIndexUCS16 ( NMEContext const *  context)

Accessor for output index in unicode characters, assuming UTF-8 input.

Parameters:
[in]contextcurrent context
Returns:
current output index

Definition at line 4222 of file NME.c.

NMEErr NMEEncodeCharFunDict ( NMEConstText  src,
NMEInt  srcLen,
NMEInt srcIx,
NMEContext context,
void *  data 
)

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 encodeCharData field.

Parameters:
[in]srcinput characters
[in]srcLensize of src in bytes
[in,out]srcIxindex in src (updated by one character)
[in,out]contextcontext for embedded expressions
[in,out]dataaddress of substitution table, of type NMEEncodeCharDict[]
Returns:
error code (kNMEErrOk for success)
See also:
NMEOutputFormat

Definition at line 690 of file NME.c.

void NMEGetFormat ( NMEContext const *  context,
NMEOutputFormat const **  outputFormat,
NMEInt options,
NMEInt fontSize 
)

Get current output format and options.

Parameters:
[in]contextcurrent context
[out]outputFormatoutput format (not set if pointer is null)
[out]optionskNMEProcessOptDefault or sum of options
[out]fontSizefont size (not set if pointer is null)

Definition at line 4199 of file NME.c.

void NMEGetTempMemory ( NMEContext const *  context,
NMEText addr,
NMEInt len 
)

Get temporary memory which can be used in plugin, autolink and hook functions.

Parameters:
[in]contextcurrent context
[out]addrmemory address
[out]lennumber of bytes

Definition at line 4191 of file NME.c.

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.

This is the main and only required extern function of the parser.

Parameters:
[in]nmeTextsource text with markup
[in]nmeTextLensource text length
[out]bufbuffer used during conversion
[in]bufSizesize of buf
[in]optionskNMEProcessOptDefault or sum of options
[in]eolnull-terminated string used for end-of-line
[in]outputFormatformat strings, or NULL for default (NMEOutputFormatText)
[in]fontSizefont size of plain text in points (nonpositive -> default)
[out]outputformatted text (in buf), followed by null byte
[out]outputLenformatted text length, excluding final null byte
[out]outputUCS16Lenformatted text length in 16-bit unicode characters assuming input is in UTF-8, excluding final null byte (may be NULL)
Returns:
error code (kNMEErrOk for success)
Bug:
Links are copied verbatim, without processing the escape character (this means that pipes and double-closing-brackets cannot be included in a link).

Definition at line 2845 of file NME.c.

void NMEResetOutput ( NMEContext context)

Reset output (can be used in a hook).

Parameters:
[in,out]contextcurrent context

Definition at line 582 of file NME.c.

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 
) [static]

Parse next token, skipping it in the source code.

Parameters:
[in]srcsource text with markup
[in]srcLensource text length
[in,out]iindex in src (token to parse on input, next token on output)
[in]statecurrent state of the parser
[in]verbatimTRUE if in inline verbatim mode
[in]nestingcurrent list nesting
[in]listNumarray of current list item numbers or kNMEListNumUL/DT/DD/Indented
[in]styleStackstack of styles
[in]styleNestingnumber of styles in stack
[in]outputFormatformat strings (can be NULL)
[out]tokenkind of parsed token (details are in src[*i-1], *headingLevel, itemNesting, *style)
[out]headingLevelif token is a starting kNMETokenHeading, set to its level
[out]itemNestingif token is kNMETokenLI, set to its nesting level
[out]styleif token is kNMETokenStyle, set to its style
[in]optionspassed to NMEProcess
Returns:
TRUE to continue, FALSE if end of source has been reached

Definition at line 2328 of file NME.c.

static NMEErr processStyleTag ( NMEStyle  styleStack[],
NMEInt styleNesting,
NMEStyle  style,
NMEInt  i0,
NMEOutputFormat const *  outputFormat,
NMEContext context 
) [static]

Process style tag.

Parameters:
[in,out]styleStackstack of styles
[in,out]styleNestingnumber of styles in stack
[in]stylenew style (not kNMEStyleLink or kNMEStyleImage)
[in]i0index in src of beginning of tag
[in]outputFormatformat strings
[in,out]contextcurrent context
Returns:
error code (kNMEErrOk for success)

Definition at line 1591 of file NME.c.

static void skipBlanks ( NMEConstText  src,
NMEInt  srcLen,
NMEInt i 
) [static]

Skip spaces and tabs.

Parameters:
[in]srcsource text with markup
[in]srcLensource text length
[in,out]iindex in src

Definition at line 158 of file NME.c.

static NMEConstText styleMarkerFromStyleID ( NMEStyle  style) [static]

Get style marker string associated to a style constant.

Parameters:
[in]stylestyle
Returns:
style marker string, or NULL for nonbasic style

Definition at line 1557 of file NME.c.

static NMEErr swapBuffers ( NMEText src,
NMEInt srcLen,
NMEContext context,
NMEInt commonLen,
NMEInt  destLen0 
) [static]

Swap source and destination buffers after some plugin or autoconvert output must be reparsed.

Parameters:
[in,out]srcinput characters
[in,out]srcLenlength of src in bytes
[in,out]contextcurrent context
[in,out]commonLennumber of bytes at beginning of dest already copied in src
[in]destLen0value of destLen before plugin or autoconvert call
Returns:
error code (kNMEErrOk for success)
See also:
NMEProcess

Definition at line 2815 of file NME.c.

static void updateLineNum ( NMEContext context) [static]

Update srcLineNum and srcIndexForLineNum so that srcIndexForLineNum = srcIndex.

Parameters:
[in]srcsource code
[in,out]contextcontext

Definition at line 215 of file NME.c.

static NMEWordwrapPermission wordwrapCheckNMEFun ( NMEConstText  txt,
NMEInt  len,
NMEInt  i,
NMEContext context,
void *  data 
) [static]

NMEWordwrapCheckFun function to check valid wordwrap point for NME (don't break line before stars, sharps, eq, pipes, or in a table)

Parameters:
[in]txtoutput text
[in]lenlength of output text in bytes
[in]iline break to check (space to be removed or before char to push to next line)
[in,out]datavalue specific to the callback
Returns:
wordwrap kind (kNMEWordwrapNo if not permitted here)

Definition at line 1021 of file NME.c.

static NMEWordwrapPermission wordwrapCheckRTFFun ( NMEConstText  txt,
NMEInt  len,
NMEInt  i,
NMEContext context,
void *  data 
) [static]

NMEWordwrapCheckFun function to check valid wordwrap point for RTF (keep space)

Parameters:
[in]txtoutput text
[in]lenlength of output text in bytes
[in]iline break to check (space to be removed or before char to push to next line)
[in,out]contextcurrent context
[in,out]datavalue specific to the callback
Returns:
wordwrap kind (kNMEWordwrapNo if not permitted here)

Definition at line 1264 of file NME.c.


Variable Documentation

NMEEncodeCharDict const latexCharDict[] [static]
Initial value:
{
    {'#', "\\#"},
    {'^', "$\\,\\hat{}\\,$"},
    {'~', "$\\,\\tilde{}\\,$"},
    {'\\', "$\\backslash$"},
    {'|', "$|$"},
    {'\'', "\'{}"},
    {'`', "`{}"},
    {'<', "$<$"},
    {'>', "$>$"},
    {'{', "\\{"},
    {'}', "\\}"},
    {0, NULL}
}

Table of character substitutions for LaTeX.

Definition at line 674 of file NME.c.

Format strings for man page output.

Bug:
NMEOutputFormatMan needs more work or it will be discarded from the main code

Definition at line 1420 of file NME.c.

Initial value:
{
    {'<', "&lt;"},
    {'>', "&gt;"},
    {'"', "&quot;"},
    {'&', "&amp;"},
    {0, NULL}
}

Table of character substitutions for HTML or XML.

Definition at line 664 of file NME.c.

Generated by Doxygen.
Copyright 2007-2013, Yves Piguet.
All rights reserved.