XML tags or Character Style to comment

Keyboard macros or custom scripts

XML tags or Character Style to comment

Postby Jhon Smith » Thu Nov 15, 2018 1:58 pm

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
Jhon Smith
 
Posts: 2
Joined: Thu Nov 15, 2018 1:35 pm

Re: XML tags or Character Style to comment

Postby JeJe » Thu Nov 15, 2018 11:45 pm

Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 551
Joined: Wed Mar 09, 2016 2:40 pm

Re: XML tags or Character Style to comment

Postby Jhon Smith » Fri Nov 16, 2018 4:47 pm

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[i].pageReferences.length-1; j > -1; j--) {
try {
topics[i].pageReferences[j].sourceText.contents = '<!-- ' + topicPath (topics[i], addSortOrder (topics[i])) + ' -->';
//topics[i].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
Jhon Smith
 
Posts: 2
Joined: Thu Nov 15, 2018 1:35 pm

Re: XML tags or Character Style to comment

Postby FJCC » Fri Nov 16, 2018 7:01 pm

Expanding on my code from the link above provided by JeJe
Code: Select all   Expand viewCollapse view
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
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7224
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: Majestic-12 [Bot] and 4 guests