Skip to content

Commit

Permalink
Tools: Added link fix tool to offlinedoc tools
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Feb 22, 2021
1 parent 1241752 commit 872a1a3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Tools/offlinedoc/README
Expand Up @@ -10,6 +10,9 @@ download and another to actually download the files.

2) run "downloadwiki.py". If connection drops, run it again,
the already downloaded files will be skipped.

2b) Dirty hack: run "fixlinks.py" to fix wrong html links
(downloadwiki.py should be fixed in the future)

3) run "buildqhelp.py" to generate freecad.qhc and freecad.qch
files
Expand Down
13 changes: 10 additions & 3 deletions src/Tools/offlinedoc/buildqhelp.py
Expand Up @@ -103,7 +103,7 @@ def createCollProjectFile():
<assistant>
<title>FreeCAD User Manual</title>
<applicationIcon>freecad-icon-64.png</applicationIcon>
<cacheDirectory>freecad/freecad</cacheDirectory>
<cacheDirectory base="collection">freecad/freecad</cacheDirectory>
<startPage>qthelp://org.freecad.usermanual/doc/Online_Help_Startpage.html</startPage>
<aboutMenuText>
<text>About FreeCAD</text>
Expand Down Expand Up @@ -177,10 +177,17 @@ def getname(line):
if "<a" in line:
title = re.findall('<a[^>]*>(.*?)</a>',line)[0].strip()
link = re.findall('href="(.*?)"',line)[0].strip()
if link:
if not link.endswith(".html"):
link = link + ".html"
if link.startswith("/"):
link = link[1:]
if not link: link = 'default.html'
if title.startswith("<img"):
title=None
link=None
# workbenches
wb = re.findall("Workbench\_(.*?)\.svg",title)[0]
title = wb + " Workbench"
link = wb + "_Workbench.html"
return title,link

if VERBOSE: print ("Building table of contents...")
Expand Down
45 changes: 45 additions & 0 deletions src/Tools/offlinedoc/fixlinks.py
@@ -0,0 +1,45 @@
#!/usr/bin/env python3

#***************************************************************************
#* *
#* Copyright (c) 2021 Yorik van Havre <yorik@uncreated.net> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************

"""This script fixes links like href="/Arch_Wall" into href="/Arch_Wall.html" where needed. Dirty hack, downloadwiki.py should be fixed instead"""

import os,re
files = [f for f in os.listdir("localwiki") if f.endswith(".html")]
for fn in files:
f = open(os.path.join("localwiki",fn))
b = f.read()
f.close()
b = b.replace("\n","--endl--")
for href in re.findall("href=\".*?\"",b):
if (not "." in href) and (not "#" in href):
repl = href[:-1]+".html\""
if "href=\"/" in repl:
repl = repl.replace("href=\"/","href=\"")
print(fn," : replacing",href,"with",repl)
b = b.replace(href,repl)
b = b.replace("--endl--","\n")
f = open(os.path.join("localwiki",fn),"w")
f.write(b)
f.close()

0 comments on commit 872a1a3

Please sign in to comment.