Documention for: quote-node-attributes.r
Created by: inetw3dm
on: 24-Nov-2020
Last updated by: inetw3dm on: 28-Nov-2020
Format: html
Downloaded on: 17-Apr-2024

In the markup-DOM parser:

*strip-chars-from: and *strip-obj-chars-from: are example helper 
funtions to control how and wich characters you may want to 
add/remove in different DOM parsers you create for proper element 
quoting to output your desired DSL syntax.

It's not used in the %HTML-view.r, %quote-node-attributes.r is. 


How to:

Replace markup-DOM.r function code
 

if string! = type? in-data [
			strip-obj-chars-from in-data 
			insert in-data  next reform [node-name " "]
			child: build-tag to-block in-data 
			;foreach [a b][" " " ."][replace/all child a b]
			replace data in-data child
			]
with....

if string! = type? in-data [
			in-node-element: rejoin [remove form node-name " " in-data]

   quote-node-attributes create-tag-element with-these-attributes  
			;foreach [a b][" " " ."][replace/all child a b]
			replace data in-data data-node
			]

repeat this for:

if string! = type? data 	
if string! = type? in-data
if string! = type? with-this-data





If using %quote-node-attributes.r with *make-DOM: function, i realized 
it may be easier to add parse-code for mongoDB BSON, lunajson, and 
json so

different syntax is transcoded into the Dialect Object Model instead 
of using
seperate DSL functions.

So, here is the updated %quote-node-attributes.r to be used with 
%HTML-view.r. I have not tested this update to be used with the 
%rebol-DOM.r function posted yet.


               ..................."*%quote-node-attributes.r".................. 
                  

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 { =">}

foreach [-char +char][
			#"^/" "" {:"} {"} ": {" "=true {"  
			{ ="" } {="" } { ="} " " {"=""} " " 
                        {="" } {" }
                        ][

                          replace/all in-node-element -char +char]

parse in-node-element [some [to 
			  "[" copy blk thru "," copy blk2 thru "]" (
			  replace in-node-element array: join blk blk2
			  replace/all trim/all copy array {","} "_")]skip
			  ]

			
if find/any this-node "style=" [	

                   parse/all this-node [[to {style="} | to "style="] 
                          copy style-obj 

                          [thru {;" } | 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/all 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  
]