Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Html Help utils


  • Please log in to reply
1 reply to this topic
T800
  • Members
  • 107 posts
  • Last active: Feb 01 2014 11:14 PM
  • Joined: 15 Oct 2006
I hope these small utils will help you if you work with compiled html help (chm) files, or you just want all your offline web pages together in a single file.
I like to save web pages on my hard drive as I surf (through AHK forum :) , so I can read them later, since I'm on a slow dial-up connection (paying for minutes spent on my phone line-Aaargh!).
Besides, it's better to have one compiled html help file than dozens of web files + accompanying folders with huge number of small files.
So I made these scripts to help me manipulate all that stuff. They are all meant to be compiled since they all accept sommand line parameters.
Compile scripts and add them to your open with list (right click on a htm/html file-> open with->browse->locate exe file)

"WWWlauncher" will open html files in html help so you can check how it works when you include them in a chm file.

"html2CHm converter" will write a hhp file to compile a single html/htm file into a chm file.

"HHPpacker" makes hhp file for all html/htm files in a folder that contains selected default topic file (NO RECURSING into subfolders!)

Note: make sure your web files are all pre-mastered (their content, beware of javascript errors...)


;______WWWlauncher
#NoEnv 
SendMode Input 

;_CMD TOOL!

if 0 < 1  ; The left side of a non-expression if-statement is always the name of a variable.
{
msgbox, No command line parameters specified!
}
else
{
		run, C:\windows\hh.exe "%1%", UseErrorLevel
	   if errorlevel=1
		{
		err=1
		}
}

;__html2CHM converter
#NoEnv 
SendMode Input 

#NoTrayIcon 



if 0 < 1  ; _The left side of a non-expression if-statement is always the name of a variable.
{
null=5
Msgbox, No command line parameters specified!
exitapp
}
else
{
webfile=%1%
void:=makeHHP(webfile)


exitapp
}






;________________________________________________________________________________________________
makeHHP(filepath)
{


loop, %filepath%, 0
{
HHPfile=%A_LoopFileFullPath%.HHP


IfExist, %HHPfile%
	{
  MsgBox, 8240, Operation aborted, HHP already exists
	}


IfNotExist, %HHPfile%
 {
FileAppend,
(

[FILES]
%A_LoopFileFullPath%

), %HHPfile%

 }
}
}		


;__HHPpacker

#NoEnv
SendMode Input

;____________________________________________
MsgBox, 4, Option, Extract web page titles?
IfMsgBox Yes
izvuciwebnaslov:=1
else
izvuciwebnaslov=0
;_____________________________________________


if 0 < 1  ; _The left side of a non-expression if-statement is always the name of a variable.
{

FileSelectfile, defaultTopicFile, 1, %a_scriptdir%, Select default topic file, *.htm;*.html; *.txt; *.jpg; *.bmp; *.png; *.tiff; *.gif


}
else
{

defaultTopicFile=%1%

}







if (defaultTopicFile="")
  {
  MsgBox, 8240, Operation aborted, No file selected
  exitapp
  }

SplitPath, defaultTopicFile, fileName, workfolder, fileExtension, rawFilename, workDrive
FileSelectFile, projectName, S16, %workfolder%\%rawFilename%.hhp, Save Html help project file, *.hhp



IfInString, projectName, .hhp
StringTrimRight, projectName, projectName, 4
HHPfile=%projectName%.hhp
INDEXfile=%projectName%.hhk
TOCfile=%projectName%.hhc


;___msgbox, projectName:%projectName%`nHHPfile:%HHPfile%`nTOC%TOCfile%`nINDX%INDEXfile%



IfExist, %HHPfile% ;___________________FILEs HHP,TOC,INDEX
	{
	filedelete %HHPfile%
	}
FileAppend, , %HHPfile%
IfExist, %TOCfile%
	{
	filedelete %TOCfile%
	}
FileAppend, , %TOCfile%
IfExist, %INDEXfile%
	{
	filedelete %INDEXfile%
	}
FileAppend, , %INDEXfile%



; ______________________________________________________________
FileAppend,
(
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<meta name="GENERATOR" content="Microsoft® HTML Help Workshop 4.1">
<!-- Sitemap 1.0 -->
</HEAD><BODY>
), %INDEXfile%


void:=dodajFileove(workfolder, INDEXfile)



FileAppend,
(
</BODY></HTML>
), %INDEXfile%
;_____________________________CLOSE INDEX


; ______________________________ HHP
FileAppend,
(
[OPTIONS]
Auto Index=Yes
Binary TOC=Yes
Compatibility=1.1 or later
Compiled file=%projectName%.chm
Contents file=%TOCfile%
Default Font=Arial,8,0
Default Window=GlavniWintype
Default topic=%defaultTopicFile%
Display compile progress=Yes
Enhanced decompilation=Yes
Full-text search=Yes
Index file=%INDEXfile%
Language=0x41a Croatian
Title=Naslov projekta

[WINDOWS]
GlavniWintype=,"%TOCfile%","%INDEXfile%","%defaultTopicFile%",,,,,,0x23520,,0x387e,,,,,,,,0


[FILES]
%defaultTopicFile%

), %HHPfile%
void:=dodajuHHP(workfolder, HHPfile)

;_____________________________ CLOSE HHP



; ______________________________TOC
FileAppend,
(
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<meta name="GENERATOR" content="Microsoft® HTML Help Workshop 4.1">
<!-- Sitemap 1.0 -->
</HEAD><BODY>
<OBJECT type="text/site properties">
	<param name="ImageType" value="Folder">
</OBJECT>

), %TOCfile%


void:=dodajFileove(workfolder, TOCfile)




FileAppend,
(
</BODY></HTML>
), %TOCfile%
;_____________________________CLOSE TOC



;_________________________________FCIJA EXTRACT TITLE
webNASLOV(filepath) 
{
naslovheaderA:="<TITLE>" ;____delimiters
naslovheaderB:="</TITLE>"
ekstenzija:="htm"
loop, %filepath%, 0
{
naslov=%A_LoopFileName%

global izvuciWebNaslov

if izvuciwebnaslov
{
IfNotInString, A_LoopFileExt, %ekstenzija% 
  {  
  naslov=%A_LoopFileName%
  }
else
 {
naslov=%A_LoopFileName% 
   FileRead, sadrzaj, %filepath%
   IfInString, sadrzaj, %naslovheaderA% 
      {
   IfInString, sadrzaj, %naslovheaderB% 
	{
	naslovpocetak:=InStr(sadrzaj, naslovheaderA, CaseSensitive = false)
	naslovpocetak+=7
	naslovkraj:=InStr(sadrzaj, naslovheaderB, CaseSensitive = false)
	duzina:=naslovkraj-naslovpocetak
	naslov:=SubStr(sadrzaj, naslovpocetak, duzina) 
StringReplace, naslov, naslov, %a_tab%, %A_Space%, All 
StringReplace, naslov, naslov, `r,, All
StringReplace, naslov, naslov, `n,, All
	StringReplace, naslovcheck, naslov, %A_Space%,, All
	if (strlen(naslov)=0) 
	  naslov=%A_LoopFileName%
	}
      }
   }
}
}
return naslov ;__________________________________GET  TITLE
}


;_____________________________________________________ADD TO FILE
dodajFileove(Cworkfolder, Sfile)
{
FileAppend,
(

<UL>

), %Sfile%

indeXekstenzije:=".htm.html.txt.jpg.bmp.png.tiff.gif"

Loop, %Cworkfolder%\*, 0, 0
{

IfInString, indeXekstenzije, %A_LoopFileExt%
{

webime:=webNASLOV(A_LoopFileLongPath)
FileAppend,
(

	<LI> <OBJECT type="text/sitemap">
		<param name="Name" value="%webime%">
		<param name="Local" value="%A_LoopFileLongPath%">
		</OBJECT>

), %Sfile%

}

IfInString, A_LoopFileAttrib, D
 {
  IfNotInString, A_LoopFileAttrib, _files
   dodajFileove(A_LoopFileFullPath, Sfile)
 }

}




FileAppend,
(

</UL>

), %Sfile%
}
;___________________________________________

;_____________________________________________________ADD TO HHP
dodajuHHP(Cworkfolder, Sfile)
{


indeXekstenzije:=".htm.html.txt.jpg.bmp.png.tiff.gif"

Loop, %Cworkfolder%\*, 0, 0
{

  IfInString, indeXekstenzije, %A_LoopFileExt%
  {
  webime:=webNASLOV(A_LoopFileLongPath)
  FileAppend,%A_LoopFileLongPath%`n, %Sfile%
  }

  IfInString, A_LoopFileAttrib, D
  {
  IfNotInString, A_LoopFileAttrib, _files
   dodajuHHP(A_LoopFileFullPath, Sfile)
  }

}

}


Elevator_Hazard
  • Members
  • 297 posts
  • Last active: Feb 07 2011 12:10 AM
  • Joined: 28 Oct 2006
I haven't tested these out yet but they look great! I may implement them in my html editor I'm working on, which will be great!
Changed siggy at request of ahklerner :D