Fix issues with links, includes and notes in Sphinx .rst preview styling
This commit is contained in:
@@ -69,10 +69,10 @@ with tempfile.TemporaryDirectory(dir=args.user_work_dir) as tmp_dir:
|
||||
# Disable include directives and raw for security. They are already disabled
|
||||
# by docutils.py, this is just to be extra careful.
|
||||
def include_directive(matchobj):
|
||||
return f"warning:: include directives disabled: {html.escape(matchobj.group(1))}"
|
||||
return f"warning:: include not available in preview: {html.escape(matchobj.group(1))}"
|
||||
def raw_directive(matchobj):
|
||||
return f"warning:: raw disabled: {html.escape(matchobj.group(1))}"
|
||||
page_contents = re.sub("literalinclude::.*", include_directive, page_contents)
|
||||
return f"warning:: raw not available in preview: {html.escape(matchobj.group(1))}"
|
||||
page_contents = re.sub("literalinclude::(.*)", include_directive, page_contents)
|
||||
page_contents = re.sub("include::(.*)", include_directive, page_contents)
|
||||
page_contents = re.sub("raw::(.*)", raw_directive, page_contents)
|
||||
|
||||
@@ -105,6 +105,7 @@ with tempfile.TemporaryDirectory(dir=args.user_work_dir) as tmp_dir:
|
||||
if result.returncode == 0 and out_filepath.is_file():
|
||||
contents = out_filepath.read_text()
|
||||
body = contents.split("<body>")[1].split("</body>")[0]
|
||||
body = body.replace(placeholder_url, "#")
|
||||
body = body.replace(f'href="{placeholder_url}', 'href="#link-not-available-in-preview"')
|
||||
body = body.replace('href="http', 'target="_blank" href="http')
|
||||
body = '<div class="restructuredtext">' + body + '</div>'
|
||||
print(body)
|
||||
|
||||
Reference in New Issue
Block a user