-! Copyright (C) 2006, 2008 Slava Pestov.
+! Copyright (C) 2006, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: fry accessors sequences parser kernel help help.markup
 help.topics words strings classes tools.vocabs namespaces make

        dup '[
            _ dup word-help
            [ check-values ]
            [ nip [ check-see-also ] [ check-markup ] bi ] 2bi
        ] check-something
    ] [ drop ] if ;

: check-words ( words -- ) [ check-word ] each ;

: check-article ( article -- )
    [ with-interactive-vocabs ] vocabs-quot set
    dup '[ _ article-content check-markup ] check-something ;

: files>vocabs ( -- assoc )
    vocabs

: check-rendering ( element -- )
    [ print-content ] with-string-writer drop ;

: check-strings ( str -- )
    [
        "\n\t" intersects?
        [ "Paragraph text should not contain \\n or \\t" throw ] when
    ] [
        "  " swap subseq?
        [ "Paragraph text should not contain double spaces" throw ] when
    ] bi ;

: check-whitespace ( str1 str2 -- )
    [ " " tail? ] [ " " head? ] bi* or
    [ "Missing whitespace between strings" throw ] unless ;

: check-bogus-nl ( element -- )
    { { $nl } { { $nl } } } [ head? ] with contains?
    [ "Simple element should not begin with a paragraph break" throw ] when ;

: check-elements ( element -- )
    {
        [ check-bogus-nl ]
        [ [ string? ] filter [ check-strings ] each ]
        [ [ simple-element? ] filter [ check-elements ] each ]
        [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
    } cleave ;

: check-markup ( element -- )
    {
        [ check-elements ]
        [ check-rendering ]
        [ check-examples ]
        [ check-modules ]
    } cleave ;

: all-word-help ( words -- seq )
    [ word-help ] filter ;
