/* ** Copyright (c) 2007 D. Richard Hipp ** ** This program is free software; you can redistribute it and/or ** modify it under the terms of the Simplified BSD License (also ** known as the "2-Clause License" or "FreeBSD License".) ** This program is distributed in the hope that it will be useful, ** but without any warranty; without even the implied warranty of ** merchantability or fitness for a particular purpose. ** ** Author contact information: ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ******************************************************************************* ** ** This file contains code to do formatting of wiki text. */ #include #include "config.h" #include "wikiformat.h" #if INTERFACE /* ** Allowed wiki transformation operations */ #define WIKI_NOFOLLOW 0x001 #define WIKI_HTML 0x002 #define WIKI_INLINE 0x004 /* Do not surround with

..

*/ #define WIKI_NOBLOCK 0x008 /* No block markup of any kind */ #endif /* ** These are the only markup attributes allowed. */ #define ATTR_ALIGN 1 #define ATTR_ALT 2 #define ATTR_BGCOLOR 3 #define ATTR_BORDER 4 #define ATTR_CELLPADDING 5 #define ATTR_CELLSPACING 6 #define ATTR_CLASS 7 #define ATTR_CLEAR 8 #define ATTR_COLOR 9 #define ATTR_COLSPAN 10 #define ATTR_COMPACT 11 #define ATTR_FACE 12 #define ATTR_HEIGHT 13 #define ATTR_HREF 14 #define ATTR_HSPACE 15 #define ATTR_ID 16 #define ATTR_NAME 17 #define ATTR_ROWSPAN 18 #define ATTR_SIZE 19 #define ATTR_SRC 20 #define ATTR_START 21 #define ATTR_TYPE 22 #define ATTR_VALIGN 23 #define ATTR_VALUE 24 #define ATTR_VSPACE 25 #define ATTR_WIDTH 26 #define AMSK_ALIGN 0x0000001 #define AMSK_ALT 0x0000002 #define AMSK_BGCOLOR 0x0000004 #define AMSK_BORDER 0x0000008 #define AMSK_CELLPADDING 0x0000010 #define AMSK_CELLSPACING 0x0000020 #define AMSK_CLEAR 0x0000040 #define AMSK_COLOR 0x0000080 #define AMSK_COLSPAN 0x0000100 #define AMSK_COMPACT 0x0000200 #define AMSK_FACE 0x0000400 #define AMSK_HEIGHT 0x0000800 #define AMSK_HREF 0x0001000 #define AMSK_HSPACE 0x0002000 #define AMSK_ID 0x0004000 #define AMSK_NAME 0x0008000 #define AMSK_ROWSPAN 0x0010000 #define AMSK_SIZE 0x0020000 #define AMSK_SRC 0x0040000 #define AMSK_START 0x0080000 #define AMSK_TYPE 0x0100000 #define AMSK_VALIGN 0x0200000 #define AMSK_VALUE 0x0400000 #define AMSK_VSPACE 0x0800000 #define AMSK_WIDTH 0x1000000 #define AMSK_CLASS 0x2000000 static const struct AllowedAttribute { const char *zName; unsigned int iMask; } aAttribute[] = { { 0, 0 }, { "align", AMSK_ALIGN, }, { "alt", AMSK_ALT, }, { "bgcolor", AMSK_BGCOLOR, }, { "border", AMSK_BORDER, }, { "cellpadding", AMSK_CELLPADDING, }, { "cellspacing", AMSK_CELLSPACING, }, { "class", AMSK_CLASS, }, { "clear", AMSK_CLEAR, }, { "color", AMSK_COLOR, }, { "colspan", AMSK_COLSPAN, }, { "compact", AMSK_COMPACT, }, { "face", AMSK_FACE, }, { "height", AMSK_HEIGHT, }, { "href", AMSK_HREF, }, { "hspace", AMSK_HSPACE, }, { "id", AMSK_ID, }, { "name", AMSK_NAME, }, { "rowspan", AMSK_ROWSPAN, }, { "size", AMSK_SIZE, }, { "src", AMSK_SRC, }, { "start", AMSK_START, }, { "type", AMSK_TYPE, }, { "valign", AMSK_VALIGN, }, { "value", AMSK_VALUE, }, { "vspace", AMSK_VSPACE, }, { "width", AMSK_WIDTH, }, }; /* ** Use binary search to locate a tag in the aAttribute[] table. */ static int findAttr(const char *z){ int i, c, first, last; first = 1; last = sizeof(aAttribute)/sizeof(aAttribute[0]) - 1; while( first<=last ){ i = (first+last)/2; c = strcmp(aAttribute[i].zName, z); if( c==0 ){ return i; }else if( c<0 ){ first = i+1; }else{ last = i-1; } } return 0; } /* ** Allowed markup. ** ** Except for MARKUP_INVALID, this must all be in alphabetical order ** and in numerical sequence. The first markup type must be zero. ** The value for MARKUP_XYZ must correspond to the entry ** in aAllowedMarkup[]. */ #define MARKUP_INVALID 0 #define MARKUP_A 1 #define MARKUP_ADDRESS 2 #define MARKUP_B 3 #define MARKUP_BIG 4 #define MARKUP_BLOCKQUOTE 5 #define MARKUP_BR 6 #define MARKUP_CENTER 7 #define MARKUP_CITE 8 #define MARKUP_CODE 9 #define MARKUP_COL 10 #define MARKUP_COLGROUP 11 #define MARKUP_DD 12 #define MARKUP_DFN 13 #define MARKUP_DIV 14 #define MARKUP_DL 15 #define MARKUP_DT 16 #define MARKUP_EM 17 #define MARKUP_FONT 18 #define MARKUP_H1 19 #define MARKUP_H2 20 #define MARKUP_H3 21 #define MARKUP_H4 22 #define MARKUP_H5 23 #define MARKUP_H6 24 #define MARKUP_HR 25 #define MARKUP_I 26 #define MARKUP_IMG 27 #define MARKUP_KBD 28 #define MARKUP_LI 29 #define MARKUP_NOBR 30 #define MARKUP_NOWIKI 31 #define MARKUP_OL 32 #define MARKUP_P 33 #define MARKUP_PRE 34 #define MARKUP_S 35 #define MARKUP_SAMP 36 #define MARKUP_SMALL 37 #define MARKUP_SPAN 38 #define MARKUP_STRIKE 39 #define MARKUP_STRONG 40 #define MARKUP_SUB 41 #define MARKUP_SUP 42 #define MARKUP_TABLE 43 #define MARKUP_TBODY 44 #define MARKUP_TD 45 #define MARKUP_TFOOT 46 #define MARKUP_TH 47 #define MARKUP_THEAD 48 #define MARKUP_TR 49 #define MARKUP_TT 50 #define MARKUP_U 51 #define MARKUP_UL 52 #define MARKUP_VAR 53 #define MARKUP_VERBATIM 54 /* ** The various markup is divided into the following types: */ #define MUTYPE_SINGLE 0x0001 /* ,
, or
*/ #define MUTYPE_BLOCK 0x0002 /* Forms a new paragraph. ex:

,

*/ #define MUTYPE_FONT 0x0004 /* Font changes. ex: , , */ #define MUTYPE_LIST 0x0010 /* Lists.
    ,