From 670d298a8752b0ee39805464ad0860b91dd0b38e Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Tue, 29 Aug 2006 02:01:58 +0000 Subject: [PATCH] Implement list-style shorthand. Also, updated devnetwork.html with more recent threads. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@337 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 3 +- TODO | 1 - docs/devnetwork.html | 4 +- docs/progress.html | 168 +++++++++++++-------------- library/HTMLPurifier/AttrDef/ListStyle.php | 78 +++++++++++++ library/HTMLPurifier/CSSDefinition.php | 5 + tests/HTMLPurifier/AttrDef/CSSTest.php | 1 + tests/HTMLPurifier/AttrDef/ListStyleTest.php | 26 +++++ tests/index.php | 1 + 9 files changed, 199 insertions(+), 88 deletions(-) create mode 100644 library/HTMLPurifier/AttrDef/ListStyle.php create mode 100644 tests/HTMLPurifier/AttrDef/ListStyleTest.php diff --git a/NEWS b/NEWS index 3215198a..c889eae2 100644 --- a/NEWS +++ b/NEWS @@ -5,8 +5,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier - Fixed broken numeric entity conversion - Malformed UTF-8 and non-SGML character detection and cleaning implemented - API documentation completed -- Shorthand CSS properties implemented: font, border -- A limited version of CSS background implemented, only color is supported +- Shorthand CSS properties implemented: font, border, background, list-style - Basic color keywords translated into hexadecimal values - Table CSS properties implemented diff --git a/TODO b/TODO index 370d089a..9ea3f1ff 100644 --- a/TODO +++ b/TODO @@ -6,7 +6,6 @@ Ongoing - Plugins for major CMSes (very tricky issue) 1.0 release - - Limited list-style shorthand CSS support - Lossy alternate character encoding support (characters not in the encoding will get silently dropped). - Revise (HTML|CSS)Definition and Config relationship (groundwork for 2.0) diff --git a/docs/devnetwork.html b/docs/devnetwork.html index c809f9ce..a2e01538 100644 --- a/docs/devnetwork.html +++ b/docs/devnetwork.html @@ -23,7 +23,9 @@ the development of this library in these forum threads:

  • HTMLPurifier - Take your best shot
  • Need help optimizing a block of code
  • Non-SGML characters +
  • Wordpress makes me cry +
  • Parameter Object vs. Parameter Array vs. Parameter Functions +
  • Convert encoding where output cannot represent characters - \ No newline at end of file diff --git a/docs/progress.html b/docs/progress.html index 5c067a74..749129bb 100644 --- a/docs/progress.html +++ b/docs/progress.html @@ -38,89 +38,6 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;} Feature, requires extra work -

    Interesting Attributes

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    AttributeTagsNotes
    CSS
    styleAllNot all properties may be implemented, parser is good though.
    Questionable
    accesskeyAMay interfere with main interface
    tabindexAMay interfere with main interface
    targetAConfig enabled, only useful for frame layouts
    Miscellaneous
    datetimeDEL, INSNo visible effect, ISO format
    relALargely user-defined: nofollow, tag (see microformats)
    revALargely user-defined: vote-*
    axisTD, THW3C only: No browser implementation
    charCOL, COLGROUP, TBODY, TD, TFOOT, TH, THEAD, TRW3C only: No browser implementation
    headersTD, THW3C only: No browser implementation
    scopeTD, THW3C only: No browser implementation
    URI
    citeBLOCKQUOTE, QFor attribution
    DEL, INSLink to explanation why it changed
    hrefA-
    longdescIMG-
    srcIMGRequired
    Transform, target milestone 1.2
    alignCAPTIONNear-equiv style 'caption-side', drop left and right
    IMGMargin-left and margin-right = auto or parent div
    TABLE
    HREquivalent style 'text-align' (IE tested)
    H1, H2, H3, H4, H5, H6, PEquivalent style 'text-align'
    altIMGRequired, insert image filename if src is present or default invalid image text
    bgcolorTABLEEquivalent style 'background-color' (IE tested)
    TREquivalent style 'background-color' (IE tested)
    TD, THEquivalent style 'background-color'
    borderIMGEquivalent style 'border-width', only applies when link present
    clearBRNear-equiv style 'clear', transform 'all' into 'both'
    compactDL, OL, ULBoolean, needs custom CSS class; rarely used anyway
    dirBDORequired, insert ltr (or configuration value) if none
    heightTD, THNear-equiv style 'height', needs px suffix if original was in pixels
    hspaceIMGNear-equiv styles 'margin-top' and 'margin-bottom', needs px suffix
    lang*Copy value to xml:lang
    nameIMGTurn into ID
    ATurn into ID? (not deprecated, though in which specs?)
    noshadeHRBoolean, style 'border-style:solid;'
    nowrapTD, THBoolean, style 'white-space:nowrap;' (not compat with IE5)
    sizeHRNear-equiv 'width', needs px suffix if original was pixels
    srcIMGRequired, insert blank or default img if not set
    startOLPoorly supported 'counter-reset', transform may not be desirable
    typeLIEquivalent style 'list-style-type', different allowed values though. (needs testing)
    OL
    UL
    valueLIPoorly supported 'counter-reset', transform may not be desirable, see ol.start. Configurable.
    vspaceIMGNear-equiv styles 'margin-left' and 'margin-right', needs px suffix, see hspace
    widthHRNear-equiv style 'width', needs px suffix if original was pixels
    TD, TH
    -

    CSS

    @@ -169,7 +86,7 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;} Well-supported values are: disc, circle, square, decimal, lower-roman, upper-roman, lower-alpha and upper-alpha. See also CSS 3. Mostly IE lack of support. - + @@ -289,4 +206,87 @@ Mozilla on inside and needs -moz-outline, no IE support.
    list-styleSHORTHAND, target milestone 1.0
    list-styleSHORTHAND, target milestone 1.0
    marginMULTIPLE
    margin-*COMPOSITE(<length>, <percentage>, auto)
    +

    Interesting Attributes

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    AttributeTagsNotes
    CSS
    styleAllNot all properties may be implemented, parser is good though.
    Questionable
    accesskeyAMay interfere with main interface
    tabindexAMay interfere with main interface
    targetAConfig enabled, only useful for frame layouts
    Miscellaneous
    datetimeDEL, INSNo visible effect, ISO format
    relALargely user-defined: nofollow, tag (see microformats)
    revALargely user-defined: vote-*
    axisTD, THW3C only: No browser implementation
    charCOL, COLGROUP, TBODY, TD, TFOOT, TH, THEAD, TRW3C only: No browser implementation
    headersTD, THW3C only: No browser implementation
    scopeTD, THW3C only: No browser implementation
    URI
    citeBLOCKQUOTE, QFor attribution
    DEL, INSLink to explanation why it changed
    hrefA-
    longdescIMG-
    srcIMGRequired
    Transform, target milestone 1.2
    alignCAPTIONNear-equiv style 'caption-side', drop left and right
    IMGMargin-left and margin-right = auto or parent div
    TABLE
    HREquivalent style 'text-align' (IE tested)
    H1, H2, H3, H4, H5, H6, PEquivalent style 'text-align'
    altIMGRequired, insert image filename if src is present or default invalid image text
    bgcolorTABLEEquivalent style 'background-color' (IE tested)
    TREquivalent style 'background-color' (IE tested)
    TD, THEquivalent style 'background-color'
    borderIMGEquivalent style 'border-width', only applies when link present
    clearBRNear-equiv style 'clear', transform 'all' into 'both'
    compactDL, OL, ULBoolean, needs custom CSS class; rarely used anyway
    dirBDORequired, insert ltr (or configuration value) if none
    heightTD, THNear-equiv style 'height', needs px suffix if original was in pixels
    hspaceIMGNear-equiv styles 'margin-top' and 'margin-bottom', needs px suffix
    lang*Copy value to xml:lang
    nameIMGTurn into ID
    ATurn into ID? (not deprecated, though in which specs?)
    noshadeHRBoolean, style 'border-style:solid;'
    nowrapTD, THBoolean, style 'white-space:nowrap;' (not compat with IE5)
    sizeHRNear-equiv 'width', needs px suffix if original was pixels
    srcIMGRequired, insert blank or default img if not set
    startOLPoorly supported 'counter-reset', transform may not be desirable
    typeLIEquivalent style 'list-style-type', different allowed values though. (needs testing)
    OL
    UL
    valueLIPoorly supported 'counter-reset', transform may not be desirable, see ol.start. Configurable.
    vspaceIMGNear-equiv styles 'margin-left' and 'margin-right', needs px suffix, see hspace
    widthHRNear-equiv style 'width', needs px suffix if original was pixels
    TD, TH
    + \ No newline at end of file diff --git a/library/HTMLPurifier/AttrDef/ListStyle.php b/library/HTMLPurifier/AttrDef/ListStyle.php new file mode 100644 index 00000000..a310db2a --- /dev/null +++ b/library/HTMLPurifier/AttrDef/ListStyle.php @@ -0,0 +1,78 @@ +info['list-style-type'] = $def->info['list-style-type']; + $this->info['list-style-position'] = $def->info['list-style-position']; + } + + function validate($string, $config, &$context) { + + // regular pre-processing + $string = $this->parseCDATA($string); + if ($string === '') return false; + + $bits = explode(' ', strtolower($string)); // bits to process + + $caught_type = false; + $caught_position = false; + $caught_none = false; // as in keyword none, which is in all of them + + $ret = ''; + + foreach ($bits as $bit) { + if ($caught_none && ($caught_type || $caught_position)) break; + if ($caught_type && $caught_position) break; + + if ($bit === '') continue; + + if ($bit === 'none') { + if ($caught_none) continue; + $caught_none = true; + $ret .= 'none '; + continue; + } + + // if we add anymore, roll it into a loop + + $r = $this->info['list-style-type']->validate($bit, $config, $context); + if ($r !== false) { + if ($caught_type) continue; + $caught_type = true; + $ret .= $r . ' '; + continue; + } + + $r = $this->info['list-style-position']->validate($bit, $config, $context); + if ($r !== false) { + if ($caught_position) continue; + $caught_position = true; + $ret .= $r . ' '; + continue; + } + } + + $ret = rtrim($ret); + return $ret ? $ret : false; + + } + +} + +?> \ No newline at end of file diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php index 97c9e0a0..6f982bfa 100644 --- a/library/HTMLPurifier/CSSDefinition.php +++ b/library/HTMLPurifier/CSSDefinition.php @@ -10,6 +10,7 @@ require_once 'HTMLPurifier/AttrDef/TextDecoration.php'; require_once 'HTMLPurifier/AttrDef/FontFamily.php'; require_once 'HTMLPurifier/AttrDef/Font.php'; require_once 'HTMLPurifier/AttrDef/Border.php'; +require_once 'HTMLPurifier/AttrDef/ListStyle.php'; /** * Defines allowed CSS attributes and what their values are. @@ -66,11 +67,15 @@ class HTMLPurifier_CSSDefinition array('normal', 'italic', 'oblique'), false); $this->info['font-variant'] = new HTMLPurifier_AttrDef_Enum( array('normal', 'small-caps'), false); + $this->info['list-style-position'] = new HTMLPurifier_AttrDef_Enum( array('inside', 'outside'), false); $this->info['list-style-type'] = new HTMLPurifier_AttrDef_Enum( array('disc', 'circle', 'square', 'decimal', 'lower-roman', 'upper-roman', 'lower-alpha', 'upper-alpha'), false); + + $this->info['list-style'] = new HTMLPurifier_AttrDef_ListStyle(); + $this->info['text-transform'] = new HTMLPurifier_AttrDef_Enum( array('capitalize', 'uppercase', 'lowercase', 'none'), false); $this->info['color'] = new HTMLPurifier_AttrDef_Color(); diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php index 0b3b659b..ad4ce738 100644 --- a/tests/HTMLPurifier/AttrDef/CSSTest.php +++ b/tests/HTMLPurifier/AttrDef/CSSTest.php @@ -20,6 +20,7 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness $this->assertDef('font-weight:bold;'); $this->assertDef('list-style-position:outside;'); $this->assertDef('list-style-type:upper-roman;'); + $this->assertDef('list-style:upper-roman inside;'); $this->assertDef('text-transform:capitalize;'); $this->assertDef('background-color:rgb(0,0,255);'); $this->assertDef('background-color:transparent;'); diff --git a/tests/HTMLPurifier/AttrDef/ListStyleTest.php b/tests/HTMLPurifier/AttrDef/ListStyleTest.php new file mode 100644 index 00000000..3ce74af5 --- /dev/null +++ b/tests/HTMLPurifier/AttrDef/ListStyleTest.php @@ -0,0 +1,26 @@ +def = new HTMLPurifier_AttrDef_ListStyle(); + + $this->assertDef('lower-alpha'); + $this->assertDef('upper-roman inside'); + $this->assertDef('circle outside'); + $this->assertDef('inside'); + $this->assertDef('none'); + + $this->assertDef('outside inside', 'outside'); + $this->assertDef('circle lower-alpha', 'circle'); + + } + +} + +?> \ No newline at end of file diff --git a/tests/index.php b/tests/index.php index 560ba90b..39ef5a6d 100644 --- a/tests/index.php +++ b/tests/index.php @@ -77,6 +77,7 @@ $test_files[] = 'AttrDef/IPv4Test.php'; $test_files[] = 'AttrDef/IPv6Test.php'; $test_files[] = 'AttrDef/FontTest.php'; $test_files[] = 'AttrDef/BorderTest.php'; +$test_files[] = 'AttrDef/ListStyleTest.php'; $test_files[] = 'IDAccumulatorTest.php'; $test_files[] = 'TagTransformTest.php'; $test_files[] = 'AttrTransform/LangTest.php'; -- 2.11.4.GIT