/* ** 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 "config.h" #include #include "wikiformat.h" #if INTERFACE /* ** Allowed wiki transformation operations */ #define WIKI_HTMLONLY 0x001 /* HTML markup only. No wiki */ #define WIKI_INLINE 0x002 /* Do not surround with

..

*/ #define WIKI_NOBLOCK 0x004 /* No block markup of any kind */ #define WIKI_BUTTONS 0x008 /* Allow sub-menu buttons */ #define WIKI_NOBADLINKS 0x010 /* Ignore broken hyperlinks */ #define WIKI_LINKSONLY 0x020 /* No markup. Only decorate links */ #endif /* ** These are the only markup attributes allowed. */ enum allowed_attr_t { ATTR_ALIGN = 1, ATTR_ALT, ATTR_BGCOLOR, ATTR_BORDER, ATTR_CELLPADDING, ATTR_CELLSPACING, ATTR_CLASS, ATTR_CLEAR, ATTR_COLOR, ATTR_COLSPAN, ATTR_COMPACT, ATTR_FACE, ATTR_HEIGHT, ATTR_HREF, ATTR_HSPACE, ATTR_ID, ATTR_LINKS, ATTR_NAME, ATTR_ROWSPAN, ATTR_SIZE, ATTR_SRC, ATTR_START, ATTR_STYLE, ATTR_TARGET, ATTR_TYPE, ATTR_VALIGN, ATTR_VALUE, ATTR_VSPACE, ATTR_WIDTH }; enum amsk_t { AMSK_ALIGN = 0x00000001, AMSK_ALT = 0x00000002, AMSK_BGCOLOR = 0x00000004, AMSK_BORDER = 0x00000008, AMSK_CELLPADDING = 0x00000010, AMSK_CELLSPACING = 0x00000020, AMSK_CLASS = 0x00000040, AMSK_CLEAR = 0x00000080, AMSK_COLOR = 0x00000100, AMSK_COLSPAN = 0x00000200, AMSK_COMPACT = 0x00000400, /* re-use = 0x00000800, */ AMSK_FACE = 0x00001000, AMSK_HEIGHT = 0x00002000, AMSK_HREF = 0x00004000, AMSK_HSPACE = 0x00008000, AMSK_ID = 0x00010000, AMSK_LINKS = 0x00020000, AMSK_NAME = 0x00040000, AMSK_ROWSPAN = 0x00080000, AMSK_SIZE = 0x00100000, AMSK_SRC = 0x00200000, AMSK_START = 0x00400000, AMSK_STYLE = 0x00800000, AMSK_TARGET = 0x01000000, AMSK_TYPE = 0x02000000, AMSK_VALIGN = 0x04000000, AMSK_VALUE = 0x08000000, AMSK_VSPACE = 0x10000000, AMSK_WIDTH = 0x20000000 }; static const struct AllowedAttribute { const char *zName; unsigned int iMask; } aAttribute[] = { /* These indexes MUST line up with their corresponding allowed_attr_t enum values. */ { 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 }, { "links", AMSK_LINKS }, { "name", AMSK_NAME }, { "rowspan", AMSK_ROWSPAN }, { "size", AMSK_SIZE }, { "src", AMSK_SRC }, { "start", AMSK_START }, { "style", AMSK_STYLE }, { "target", AMSK_TARGET }, { "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 = count(aAttribute) - 1; while( first<=last ){ i = (first+last)/2; c = fossil_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_HTML5_ARTICLE 3 #define MARKUP_HTML5_ASIDE 4 #define MARKUP_B 5 #define MARKUP_BIG 6 #define MARKUP_BLOCKQUOTE 7 #define MARKUP_BR 8 #define MARKUP_CENTER 9 #define MARKUP_CITE 10 #define MARKUP_CODE 11 #define MARKUP_COL 12 #define MARKUP_COLGROUP 13 #define MARKUP_DD 14 #define MARKUP_DFN 15 #define MARKUP_DIV 16 #define MARKUP_DL 17 #define MARKUP_DT 18 #define MARKUP_EM 19 #define MARKUP_FONT 20 #define MARKUP_HTML5_FOOTER 21 #define MARKUP_H1 22 #define MARKUP_H2 23 #define MARKUP_H3 24 #define MARKUP_H4 25 #define MARKUP_H5 26 #define MARKUP_H6 27 #define MARKUP_HTML5_HEADER 28 #define MARKUP_HR 29 #define MARKUP_I 30 #define MARKUP_IMG 31 #define MARKUP_KBD 32 #define MARKUP_LI 33 #define MARKUP_HTML5_NAV 34 #define MARKUP_NOBR 35 #define MARKUP_NOWIKI 36 #define MARKUP_OL 37 #define MARKUP_P 38 #define MARKUP_PRE 39 #define MARKUP_S 40 #define MARKUP_SAMP 41 #define MARKUP_HTML5_SECTION 42 #define MARKUP_SMALL 43 #define MARKUP_SPAN 44 #define MARKUP_STRIKE 45 #define MARKUP_STRONG 46 #define MARKUP_SUB 47 #define MARKUP_SUP 48 #define MARKUP_TABLE 49 #define MARKUP_TBODY 50 #define MARKUP_TD 51 #define MARKUP_TFOOT 52 #define MARKUP_TH 53 #define MARKUP_THEAD 54 #define MARKUP_TITLE 55 #define MARKUP_TR 56 #define MARKUP_TT 57 #define MARKUP_U 58 #define MARKUP_UL 59 #define MARKUP_VAR 60 #define MARKUP_VERBATIM 61 /* ** 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.
    ,