Hi,
I have problem to manage this anchors. When i have the doc file with headers in UTF-8 formats that contains local characters i get it into anchor of help. It's a problem because we need to link it in the url address and it's ASCII. So if there is somewhere option to set how the anchor will be generated pleas let me knove. For now i'm trying with JavaScript. It work nicely until i have to check if in the position in the string is number or not. I try use isnan(parseInt("somestring")) function but it's not supported, is there some function or way to check if it's number or not?
thanks for help, I'm new to RoboHelp and JavaScript
JK
ok I'm really noob
of course there is function isNaN(). Ok It's working now ![]()
If someone won change the anchors by js.
I'm changing it to lnk_v10, lnk_v11, lnk_v12 ........
var topicmgr;
var tocmanagr;
var links;
var linksCounter;
var FileLog;
var FileArray;
var projectPath;
var TAGITEM = 538548171;
main();
function main()
{
linksCounter =0;
var projName = RoboHelp.project.name;
RoboHelp.project.outputMessage("Project :"+projName+"\n");
projectPath = RoboHelp.project.path;
var logpath = projectPath + "\\BMScriptLog\\";
var logFolder = new Folder (logpath);
logFolder.create();
var currentTime = new Date();
FileLog = new File(logpath+"\\log.txt");
FileLog.open("e");
FileLog.seek(0,2);
FileLog.writeln(currentTime);
FileArray = new File(logpath+"\\LinkArray.txt");
FileArray.open("e");
InfoVypis();
links = new Array();
RoboHelp.project.outputMessage("Starting\n");
LoadArrayFromFile();
topicmgr = RoboHelp.project.TopicManager;
ConvertAllBookmarks();
tocmanagr = RoboHelp.project.TOCManager;
Converttoc();
FileLog.close();
FileArray.close();
RoboHelp.closeProject();
Removecpd();
RoboHelp.openProject(projectPath+"\\"+projName+".xpj");
RoboHelp.project.outputMessage("finished bookmarks changing\n");
}
function Removecpd()
{
var cpdpath = projectPath + "\\DMSHelp.cpd";
var cpdfile = new File(cpdpath);
if(cpdfile.exists)
while(cpdfile.remove());
}
function LoadArrayFromFile()
{
RoboHelp.project.outputMessage("Reading array file\n");
FileArray.seek(0);
while(!FileArray.eof)
{
var line = FileArray.readln();
links[linksCounter] = line.split(",",2);
linksCounter++;
}
FileArray.seek(0,2);
}
function ConvertAllBookmarks()
{
writeLog(topicmgr.count);
if(topicmgr.count>0)
{
var topic = topicmgr.item(1);
writeLog("Loading bookmarks Array");
RoboHelp.project.outputMessage("Loading bookmarks from hml files\n");
while(typeof(topic)!='undefined')
{
var tokenmgr = RoboHelp.getTokenManager(topic.path);
if(tokenmgr.count <= 0){
topic = topic.next;
continue;
}
var token = tokenmgr.item(1);
while(typeof(token)!='undefined')
{
if(token.tokenType != RoboHelp.TokenType.TOKENTAG || token.tagType != RoboHelp.TagType.TAGANCHOR){
token = token.next;
continue;
}
var tokenname = token.getAttribute('name');
if(tokenname && typeof(tokenname) != 'undefined'){
addItToArray(RemovePrefix(tokenname));
}
tokenname = token.getAttribute('href');
if(tokenname && typeof(tokenname) != 'undefined' && tokenname.lastIndexOf ("#") >= 0){
addItToArray(RemovePrefix(tokenname));
}
token = token.next;
}
topic = topic.next;
}
writeLog("Changing html bookmarks");
topic = topicmgr.item(1);
while(typeof(topic)!='undefined')
{
ConvertBookmarks(topic.path);
topic = topic.next;
}
}
}
function writeLog(str)
{
FileLog.writeln(str);
}
function ConvertBookmarks(filepath)
{
writeLog("file name :" + filepath);
RoboHelp.project.outputMessage("Changing :" + filepath + "\n");
var tokenmgr = RoboHelp.getTokenManager(filepath);
var token;
if(typeof(tokenmgr)!='undefined')
{
if(tokenmgr.count>0)
{
writeLog("token count :" + tokenmgr.count);
token = tokenmgr.item(1);
while(typeof(token)!='undefined')
{
if(token.tokenType == RoboHelp.TokenType.TOKENTAG && token.tagType == RoboHelp.TagType.TAGANCHOR)
{
writeLog(token.tokenname + ", " +token.name);
var tokenname = token.getAttribute('name');
if(tokenname && typeof(tokenname) !='undefined')
{
if(IsMyLink(tokenname)) {
token = token.next;
continue;
}
var pos = PosInArray(RemovePrefix(tokenname));
if(pos >=0)
{
token.setAttribute("name", links[pos][1]);
}
else
writeLog("dint faind name :" + LinkName);
}
tokenname = token.getAttribute('href');
if(tokenname && typeof(tokenname) !='undefined')
{
var hashPos = tokenname.lastIndexOf ("#");
var LinkName = tokenname.substr (hashPos+1);
var url = tokenname.substr (0, hashPos+1);
if(hashPos === -1 || IsMyLink(tokenname)) {
token = token.next;
continue;
}
var pos = PosInArray(RemovePrefix(LinkName));
if(pos >= 0){
token.setAttribute("href", url + links[pos][1]);
}
else
writeLog("dint faind href :" + LinkName);
}
}
token = token.next;
}
}
}
else
alert('there is some error in getting the token manager');
if(tokenmgr.valid)
tokenmgr.save();
wait(5000);
// alert('saved file '+filepath);
}
function wait(milisec)
{
var actualdate = new Date();
var toMillisec = actualdate.getTime() + actualdate.getMilliseconds() + milisec;
// RoboHelp.project.outputMessage(actualdate.getTime()+", "+toMillisec+"\n");
while(actualdate.getTime() < toMillisec)
actualdate = new Date();
// RoboHelp.project.outputMessage(actualdate.getTime()+", "+toMillisec+"\n");
return;
}
function IsMyLink(link)
{
if(link.substr(0,6) === "lnk_v1")
return true;
return false;
}
function addItToArray(link)
{
var hasPos = link.lastIndexOf ("#");
if(hasPos != -1) {
url = link.substr (0, hasPos+1);
link = link.substr (hasPos+1);
}
if(IsMyLink(link))
return;
var pos = PosInArray(link);
if(pos <0)
{
FileArray.writeln(link + ", lnk_v1"+linksCounter);
links[linksCounter] = new Array();
links[linksCounter][0] = link;
links[linksCounter][1] = "lnk_v1"+linksCounter;
linksCounter++;
}
}
function RemovePrefix(link)
{
var i=0;
for(i; (link.charAt(i) === "_" || !isNaN(parseInt(link.charAt(i)))); i++) ;
return link.substring (i);
}
function PosInArray(link)
{
for(var j=0; j<links.length; j++){
if(links[j][0] === link) {
return j;
}
}
return -1;
}
function Converttoc()
{
RoboHelp.project.outputMessage("Changing TOC : "+tocmanagr.count+"\n");
writeLog("Changing TOC : "+tocmanagr.count);
if(tocmanagr.count > 0)
{
var toc = tocmanagr.item(1);
while(typeof(toc)!= 'undefined')
{
ProcesingHHC(toc.path);
toc = toc.next;
}
}
}
function ProcesingHHC(filepath)
{
RoboHelp.project.outputMessage(filepath + "\n");
var tokenmgr = RoboHelp.getTokenManager(filepath);
var token ;
if(typeof(tokenmgr)!='undefined')
{
if(tokenmgr.count>0)
{
writeLog("token count :" + tokenmgr.count);
token = tokenmgr.item(1);
while(typeof(token)!='undefined')
{
writeLog(token.name);
if(token.tokenType == RoboHelp.TokenType.TOKENTAG && token.tagType == TAGITEM)
{
tokenname = token.getAttribute('link');
if(tokenname && typeof(tokenname) !='undefined')
{
var hashPos = tokenname.lastIndexOf ("#");
var LinkName = tokenname.substr (hashPos+1);
var url = tokenname.substr (0, hashPos+1);
if(hashPos == -1) {
token = token.next;
continue;
}
var pos = PosInArray(LinkName);
if(pos >= 0){
token.setAttribute("link", url + links[pos][1]);
}
else
writeLog("dint faind link :" + LinkName);
}
}
token = token.next;
}
}
}
else
alert('there is some error in getting the token manager');
if(tokenmgr.valid)
tokenmgr.save();
wait(5000);
//alert('saved file '+filepath);
}
function PrintTheArray()
{
RoboHelp.project.outputMessage("\nVypis jednotlivych znakov a ich nahradu\n");
for(var j=0; j<links.length; j++)
RoboHelp.project.outputMessage(links[j][0]+", "+links[j][1]+"\n");
RoboHelp.project.outputMessage("koniec vypisu jednotlivych znakov a ich nahradu\n\n");
}
function InfoVypis()
{
writeLog("Vypis jednotlivych tagov a ich hodnoty");
writeLog(RoboHelp.TokenType.TOKENTAG+"\n"
+"TAGNONE:\t"+RoboHelp.TagType.TAGNONE+"\n"
+"TAGIMAGE:\t"+RoboHelp.TagType.TAGIMAGE+"\n"
+"TAGHTML:\t"+RoboHelp.TagType.TAGHTML+"\n"
+"TAGHEAD:\t"+RoboHelp.TagType.TAGHEAD+"\n"
+"TAGBODY:\t"+RoboHelp.TagType.TAGBODY+"\n"
+"TAGTITLE:\t"+RoboHelp.TagType.TAGTITLE+"\n"
+"TAGMETA:\t"+RoboHelp.TagType.TAGMETA+"\n"
+"TAGLINK:\t"+RoboHelp.TagType.TAGLINK+"\n"
+"TAGANCHOR:\t"+RoboHelp.TagType.TAGANCHOR+"\n"
+"TAGPARAGRAPH:\t"+RoboHelp.TagType.TAGPARAGRAPH+"\n"
+"TAGTABLE:\t"+RoboHelp.TagType.TAGTABLE+"\n"
);
writeLog("Koniec vypisu jednotlivych tagov a ich hodnoty");
}
North America
Europe, Middle East and Africa
Asia Pacific