Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Hello Adepters,
I would like to delete attributes from a table on paste using 5.4M070. For example when copying & pasting a row, delete @id on all elements including row, entry, and para. I have tried:
1) ACL paste callback that modifies xml in buffer_doc
2) JS AOMPaste event that accesses pasted xml using relatedRange
I've learned from testing and the forum, table markup is not accessible by object id when formatted (table markup is off).
With ACL, using oid to access the table components I saw the behavior:
(1) if an entire table is copied/pasted, all attributes on elements are deleted as wanted;
(2) if a row is copied/pasted, only the para has the attribute deleted. Interestingly, if a row is copied the paste buffer row is wrapped in table markup.
This behavior makes sense because the table and para tags are displayed in the Editor, unlike the other table markup that is hidden. Since object id (oid) does not work, I speculate accessing the table object id (toid) of the hidden parts might be an option instead, but I'm uncertain how to do this and if it's possible at all.
With JS, I did not pursue that any further because the row markup was not accessible, at least when I checked the markup was existent via event.relatedRange.toMarkupString().
Any recommendations? To simplify the process I want to avoid turning table markup on and handle it "auto-magically."
Thank you!
Bryan
Hello Clay,
Here is my code:
function pasteCallback(doc, buffername, op) {
if ( op == 2 ) {
# create paste buffer doc
set paste = temp;
local bdoc = buffer_doc("default");
#response( "bdoc content pre-clean-up: " . doc_content(bdoc) );
# remove diffid, astid, modtime attributes on paste buffer
for (o = oid_first_tag(bdoc); oid_valid(o); o = oid_forward(o)) {
if (oid_has_attr(o, "id")) { oid_delete_attr(o, "id") }}
#response( "bdoc content post-clean-up: " . doc_content(bdoc) );
set paste=default;
paste default;
return -1;
}
}
# add callbacks
doc_add_callback(current_doc(), 'paste', 'pasteCallback');
Thanks,
Bryan
Clay,
I tried out your code. It still does not work on deleting attributes from a table. Granted, the code is correct but something about the buffer_doc containing a table causes different behavior. My response codeshows the attribute removal, but when I check the pasted xml, none of theattributes are deleted.
As clarification, I actually want to delete attributes named diffid, astid, and modtime, not id. I wanted to shorten the code example here and didn't expect a possible default behavior. These 3attributes are CDATA IMPLIED, so removal of them should not cause validation issues. Curious about your comment, I added @id to the DTD and xml and verified theautomatic deletion of ids from table. Is there a way to extend this default deletion to include these other attributes? I noticed though id was only deleted if it was set to ID in the DTD.
Also, the reason I chose to iterate over all the oids was because the paste buffer might not have a root, like if 2 paras were copied and pasted.
So, I'm still at a loss to a solution.
Thank you so far!
Bryan
I just wanted to close-out this thread by saying I resolved the issue by using another callback named tbl_obj_add_after, which iscalled after agrid, column, or row is inserted into an existing table. The functionprovides the toid of the newly inserted xml, which I can then use to access the oid to remove element attributes. Removal of attributes on rows is simple enough, but columns require using some table functions to access only the related column entries.
Best,
Bryan