mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
fix preprocessor
This commit is contained in:
parent
8f2203fd5f
commit
a92f4c8447
@ -17,7 +17,7 @@ handler2.setLevel(logging.ERROR)
|
|||||||
logger.addHandler(handler2)
|
logger.addHandler(handler2)
|
||||||
|
|
||||||
|
|
||||||
def findtitle(search ,obj, key, path=(),):
|
def findtitle(search, obj, key, path=()):
|
||||||
# logger.debug(f"Looking for {search} in {path}")
|
# logger.debug(f"Looking for {search} in {path}")
|
||||||
if isinstance(obj, dict) and key in obj and obj[key] == search:
|
if isinstance(obj, dict) and key in obj and obj[key] == search:
|
||||||
return obj, path
|
return obj, path
|
||||||
@ -54,26 +54,42 @@ def ref(matchobj):
|
|||||||
if href.endswith("/"):
|
if href.endswith("/"):
|
||||||
href = href+"README.md" # Fix if ref points to a folder
|
href = href+"README.md" # Fix if ref points to a folder
|
||||||
if "#" in href:
|
if "#" in href:
|
||||||
chapter, _path = findtitle(href.split("#")[0], book, "source_path")
|
result = findtitle(href.split("#")[0], book, "source_path")
|
||||||
title = " ".join(href.split("#")[1].split("-")).title()
|
if result is not None:
|
||||||
logger.debug(f'Ref has # using title: {title}')
|
chapter, _path = result
|
||||||
|
title = " ".join(href.split("#")[1].split("-")).title()
|
||||||
|
logger.debug(f'Ref has # using title: {title}')
|
||||||
|
else:
|
||||||
|
raise Exception(f"Chapter not found for path: {href.split('#')[0]}")
|
||||||
else:
|
else:
|
||||||
chapter, _path = findtitle(href, book, "source_path")
|
result = findtitle(href, book, "source_path")
|
||||||
logger.debug(f'Recursive title search result: {chapter["name"]}')
|
if result is not None:
|
||||||
title = chapter['name']
|
chapter, _path = result
|
||||||
|
logger.debug(f'Recursive title search result: {chapter["name"]}')
|
||||||
|
title = chapter['name']
|
||||||
|
else:
|
||||||
|
raise Exception(f"Chapter not found for path: {href}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
dir = path.dirname(current_chapter['source_path'])
|
dir = path.dirname(current_chapter['source_path'])
|
||||||
rel_path = path.normpath(path.join(dir,href))
|
rel_path = path.normpath(path.join(dir,href))
|
||||||
try:
|
try:
|
||||||
logger.debug(f'Not found chapter title from: {href} -- trying with relative path {rel_path}')
|
logger.debug(f'Not found chapter title from: {href} -- trying with relative path {rel_path}')
|
||||||
if "#" in href:
|
if "#" in href:
|
||||||
chapter, _path = findtitle(path.normpath(path.join(dir,href.split('#')[0])), book, "source_path")
|
result = findtitle(path.normpath(path.join(dir,href.split('#')[0])), book, "source_path")
|
||||||
title = " ".join(href.split("#")[1].split("-")).title()
|
if result is not None:
|
||||||
logger.debug(f'Ref has # using title: {title}')
|
chapter, _path = result
|
||||||
|
title = " ".join(href.split("#")[1].split("-")).title()
|
||||||
|
logger.debug(f'Ref has # using title: {title}')
|
||||||
|
else:
|
||||||
|
raise Exception(f"Chapter not found for relative path: {path.normpath(path.join(dir,href.split('#')[0]))}")
|
||||||
else:
|
else:
|
||||||
chapter, _path = findtitle(path.normpath(path.join(dir,href.split('#')[0])), book, "source_path")
|
result = findtitle(path.normpath(path.join(dir,href)), book, "source_path")
|
||||||
title = chapter["name"]
|
if result is not None:
|
||||||
logger.debug(f'Recursive title search result: {chapter["name"]}')
|
chapter, _path = result
|
||||||
|
title = chapter["name"]
|
||||||
|
logger.debug(f'Recursive title search result: {chapter["name"]}')
|
||||||
|
else:
|
||||||
|
raise Exception(f"Chapter not found for relative path: {path.normpath(path.join(dir,href))}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(e)
|
logger.debug(e)
|
||||||
logger.error(f'Error getting chapter title: {rel_path}')
|
logger.error(f'Error getting chapter title: {rel_path}')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user