View in color | View documentation | License |
Download script | History | Other scripts by: inetw3dm |
27-Jan 8:58 UTC
[0.091] 14.318k
[0.091] 14.318k
quote-node-attributes.rREBOL [
File: %quote-node-attributes.r
Date: 23-11-2020
Title: "Dialect Object Model"
Author: daniel murrill
Emai: %inetw3--dm--gmail--com
Purpose: {
This script is used on variable values, key value pairs that are written in different syntax styles such as
<tag style = html elem.,xml,css>, objects, arrays, json, rebol series, etc. It will properly format mixed, malformed,
mixed, key value data found in a DSL that's a parsed series or loaded by file or Url. It requotes *" "* and
creates it as a taged node-element for look up in a Dialect Object Model to be used with rebol-DOM functions.
It's not perfect, it could/should be improved, but it's a beginning. }
]
library: [
level: 'intermediate
platform: 'all
type: function
domain: [html vid css json js array]
tested-under: 'windows
support: none
license: none
see-also: %HTML-view.r
]
;;;;;this should use "quote-node-attributes: func [in-node-element] in order to select a
;;;;;paramater to quote-to-tag.
tag-tokens: to-hash [
style-obj-chars [
"<" "" {style="} " " {style=} " " " : " { "} ": " { "} ":" {*"}
" " {__} {=""} " " "=" {*"} ";" {"*} {""} {"} { "} {"}
{*"} { "} {"*} {" } " >" "" ">" "" "rgb" "" {__"} {"} {" "} {"}
]
]
quote-node-attributes: does [with-these-attributes: copy ""
trim/tail in-node-element
if #"/" = last in-node-element [remove back tail in-node-element]
this-node: find/match in-node-element node-name: first parse/all in-node-element { =">}
replace/all this-node {:"} {"}
replace/all this-node {,} " "
if find/any this-node "style=" [
parse/all this-node [[to {style="} | to "style="] copy style-obj [thru {;" } | thru {;">} | thru {;>} | thru {;"} | thru {" } | thru {>} | to end](*style.node: copy style-obj
foreach [style-chars found-with-in] tag-tokens/style-obj-chars [replace/all *style.node style-chars found-with-in]
replace this-node style-obj *style.node
)]
]
replace node-name "<" ""
;replace/all this-node {=""} {=null}
replace/all this-node "://" "&&"
foreach part replace/all this-node: parse/all this-node {<{} "=:;[]>} [""] [] [
part: any [if find/match part "'" [
replace/all part "'" ""
]
part
]
;replace part {,} " "
replace/all part {__} " "
replace/all part "&&" "://"
replace part {=null} {=""}
append with-these-attributes mold part
]
]
create-tag-element: func [these-attr][
in-attribute-blk: to-block these-attr
foreach [attr-name attr-value] in-attribute-blk [
replace in-attribute-blk attr-name to-word attr-name
attempt [trim attr-value]
]
attempt [insert in-attribute-blk to-word node-name]
data-node: build-tag in-attribute-blk
]
with-these-attributes: copy ""
;;;In the DOM everything grouped is a node. individual key value pairs are elements of a group.
;;;so we are *in a *node to requote *elements
;;;How to use: "this is a node full of messed up elements from a bad robot."
in-node-element: {p "color":= "#0000ff" bgcolor="yellow",, "width" : "399" "height":"100", "font-styles" : "big"
style={"color: green; bgcolor: purple;"}
}
quote-node-attributes create-tag-element with-these-attributes
or...
change "quote-node-attributes: does" to "quote-node-attributes: func [in-node-element]" Notes
|