Author Options: Add independent sets of tags before and after a marked passage
Posted: Tue Jan 30, 2024 1:26 pm
Hello, I am completely new to Oxygen and I need to write an Author Option in an XML-File. The option shall add an anchor tag to the start of a marked passage and a note-tag to its end (in which the cursor shall be placed). Both the anchor and the note-tag shall carry the same random ID. In the end, it shall look like in the example below:
The current state of my code is given below. I would highly appreciate any help since I am not able to figure it out by myself. Thank you very much in advance!
Code: Select all
<anchor corresp="#sfsd98sdsds"/>section marked by the author<note type="editor" xml:id="sfsd98sdsds">Cursor here</note>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<a:authorAction id="erlaeuterung"
xmlns:a="http://www.oxygenxml.com/ns/author/external-action"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.oxygenxml.com/ns/author/external-action http://www.oxygenxml.com/ns/author/external-action/authorAction.xsd">
<a:name>Erläuterung_neu</a:name>
<a:description>Erläuterung_neu</a:description>
<a:operations>
<a:operation id="JSOperation">
<a:arguments>
<a:argument name="script"><![CDATA[function doOperation(){
documentController = authorAccess.getDocumentController();
workspaceAccess = authorAccess.getWorkspaceAccess();
// Function to make the random ID
function makeRandomID(length) {
var result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
var counter = 0;
while (counter < length) {
if (counter === 0){
result += characters.charAt(Math.floor(Math.random() * (charactersLength-10))); //No number as first
}
else{
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
counter += 1;
}
return result;
}
var noteID = makeRandomID(8);
var anchorID = "#" + noteID;
// Wrap
documentController.insertXMLFragment('<anchor type="comment" corresp="makeRandomID(8)"/>', authorAccess.getEditorAccess().getSelectionStart());
documentController.insertXMLFragment('<note type="comment" xml:id="rid">note</note>', authorAccess.getEditorAccess().getSelectionEnd());
}]]>
</a:argument>
</a:arguments>
</a:operation>
</a:operations>
<a:enabledInReadOnlyContext>false</a:enabledInReadOnlyContext>
</a:authorAction>