fix parsing of attributes for nofollows
parent
7060a5905f
commit
826d9f18c5
|
@ -42,6 +42,19 @@ V{
|
||||||
}
|
}
|
||||||
] [ "<a href = \"http://factorcode.org/\" foo = bar baz='quux'a=pirsqd >" parse-html ] unit-test
|
] [ "<a href = \"http://factorcode.org/\" foo = bar baz='quux'a=pirsqd >" parse-html ] unit-test
|
||||||
|
|
||||||
|
[
|
||||||
|
V{
|
||||||
|
T{ tag f "a"
|
||||||
|
H{
|
||||||
|
{ "a" "pirsqd" }
|
||||||
|
{ "foo" "bar" }
|
||||||
|
{ "href" "http://factorcode.org/" }
|
||||||
|
{ "baz" "quux" }
|
||||||
|
{ "nofollow" f }
|
||||||
|
} f f }
|
||||||
|
}
|
||||||
|
] [ "<a href = \"http://factorcode.org/\" nofollow foo = bar baz='quux'a=pirsqd >" parse-html ] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
V{
|
V{
|
||||||
T{ tag f "html" H{ } f f }
|
T{ tag f "html" H{ } f f }
|
||||||
|
|
|
@ -6,7 +6,6 @@ unicode.case unicode.categories combinators.short-circuit
|
||||||
quoting fry ;
|
quoting fry ;
|
||||||
IN: html.parser
|
IN: html.parser
|
||||||
|
|
||||||
|
|
||||||
TUPLE: tag name attributes text closing? ;
|
TUPLE: tag name attributes text closing? ;
|
||||||
|
|
||||||
SINGLETON: text
|
SINGLETON: text
|
||||||
|
@ -52,7 +51,7 @@ SYMBOL: tagstack
|
||||||
skip-whitespace
|
skip-whitespace
|
||||||
[ current { [ CHAR: = = ] [ blank? ] } 1|| ] take-until ;
|
[ current { [ CHAR: = = ] [ blank? ] } 1|| ] take-until ;
|
||||||
|
|
||||||
: read-= ( state-parser -- )
|
: read-=1 ( state-parser -- )
|
||||||
skip-whitespace
|
skip-whitespace
|
||||||
[ [ current CHAR: = = ] take-until drop ] [ next drop ] bi ;
|
[ [ current CHAR: = = ] take-until drop ] [ next drop ] bi ;
|
||||||
|
|
||||||
|
@ -71,12 +70,8 @@ SYMBOL: tagstack
|
||||||
">" take-until-sequence dtd new-tag push-tag ;
|
">" take-until-sequence dtd new-tag push-tag ;
|
||||||
|
|
||||||
: read-bang ( state-parser -- )
|
: read-bang ( state-parser -- )
|
||||||
next dup { [ current CHAR: - = ] [ peek-next CHAR: - = ] } 1&& [
|
next dup { [ current CHAR: - = ] [ peek-next CHAR: - = ] } 1&&
|
||||||
next next
|
[ next next read-comment ] [ read-dtd ] if ;
|
||||||
read-comment
|
|
||||||
] [
|
|
||||||
read-dtd
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
: read-tag ( state-parser -- string )
|
: read-tag ( state-parser -- string )
|
||||||
[ [ current "><" member? ] take-until ]
|
[ [ current "><" member? ] take-until ]
|
||||||
|
@ -88,15 +83,17 @@ SYMBOL: tagstack
|
||||||
: parse-text ( state-parser -- )
|
: parse-text ( state-parser -- )
|
||||||
read-until-< [ text new-tag push-tag ] unless-empty ;
|
read-until-< [ text new-tag push-tag ] unless-empty ;
|
||||||
|
|
||||||
|
: parse-key/value ( state-parser -- key value )
|
||||||
|
[ read-key >lower ]
|
||||||
|
[ skip-whitespace "=" take-sequence ]
|
||||||
|
[ swap [ read-value ] [ drop f ] if ] tri ;
|
||||||
|
|
||||||
: (parse-attributes) ( state-parser -- )
|
: (parse-attributes) ( state-parser -- )
|
||||||
skip-whitespace
|
skip-whitespace
|
||||||
dup state-parse-end? [
|
dup state-parse-end? [
|
||||||
drop
|
drop
|
||||||
] [
|
] [
|
||||||
[
|
[ parse-key/value swap set ] [ (parse-attributes) ] bi
|
||||||
[ read-key >lower ] [ read-= ] [ read-value ] tri
|
|
||||||
swap set
|
|
||||||
] keep (parse-attributes)
|
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: parse-attributes ( state-parser -- hashtable )
|
: parse-attributes ( state-parser -- hashtable )
|
||||||
|
|
Loading…
Reference in New Issue