XML tags or Character Style to comment

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Jhon Smith
Posts: 2
Joined: Thu Nov 15, 2018 1:35 pm

XML tags or Character Style to comment

Post by Jhon Smith »

Hello!
Please do you know how can I create automatically a comments in Openoffice Writer?
I have a huge document like this:
Image

And I need convert the XML tags into comments, like this:
Image

Thanks so much!
OpenOffice 3.1 on MacOS 10.4
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: XML tags or Character Style to comment

Post by JeJe »

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Jhon Smith
Posts: 2
Joined: Thu Nov 15, 2018 1:35 pm

Re: XML tags or Character Style to comment

Post by Jhon Smith »

I show you how to convert Adobe InDesign index into Word or Google Doc comments.

1º VIDEO:
https://youtu.be/_M1TaOgCYkU


2º IMAGES GALLERY:
https://photos.app.goo.gl/W2uvndiyujFby1X8A


3º ADOBE INDESIGN SCRIPT :

// Project name: id0000131-convert-index-entries-into-Word-or-Google-Doc-comments
// Github: Adobe Indesign Script examples: https://github.com/firedevelop/id000001 ... s-Examples
// Github of this project: id0000131-convert-adobe-indesign-index-into-Word-or-Google-Doc-comments
// YouTube Playlist: https://www.youtube.com/playlist?list=P ... NoGMLwYeFf
// Blog: https://www.firedevelop.com/2018/11/id0 ... -into.html

// Script Author:
// Peter Kahrel -- www.kahrel.plus.com
// http://www.kahrel.plus.com/indesign/index-to-text.jsx
// http://www.kahrel.plus.com/indesign/index_to_text.html



(function () {

function addSortOrder (topic) {
var s = topic.name;
if (topic.sortOrder !== '') {
s += '@' + topic.sortOrder;
}
return s;
}

function topicPath (topic, str) {
if (topic.parent.constructor.name == 'Index') {
return str;
} else {
return topicPath (topic.parent, addSortOrder (topic.parent) + '#' + str);
}
}

function main () {
var i, j;
var topics;
var err = false;
if (app.documents[0].indexes.length === 0) {
alert ('Document doesn\'t have an index.');
exit();
}
topics = app.documents[0].indexes[0].allTopics;
for (i = topics.length-1; i >= 0; i--) {
for (j = topics.pageReferences.length-1; j > -1; j--) {
try {
topics.pageReferences[j].sourceText.contents = '<!-- ' + topicPath (topics, addSortOrder (topics)) + ' -->';
//topics.pageReferences[j].remove();
} catch (_) {
err = true;
}
}
}
if (err) {
alert ('Some markers could not be converted. Please check the Index panel');
}
}

main();

}());


[enter image description here][1]


[enter image description here][2]
OpenOffice 3.1 on MacOS 10.4
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: XML tags or Character Style to comment

Post by FJCC »

Expanding on my code from the link above provided by JeJe

Code: Select all

oSDesc = ThisComponent.createSearchDescriptor()
oSDesc.SearchString = "(?<=<ix>)[^<]+(?=</ix>)"
oSDesc.SearchRegularExpression = TRUE

oText = ThisComponent.Text

oFound = ThisComponent.findFirst(oSDesc)
While Not IsNull(oFound)
  oAnno = ThisComponent.createInstance("com.sun.star.text.textfield.Annotation")
  oAnno.Content = oFound.String
  oAnno.Author = "f c"
  oText.insertTextContent(oFound.End, oAnno, False)
  oFound = ThisComponent.findNext(oFound.End, oSDesc)
WEnd
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Post Reply