diff --git a/sphinx/README.md b/sphinx/README.md index 296a807..5aecf40 100644 --- a/sphinx/README.md +++ b/sphinx/README.md @@ -18,6 +18,11 @@ Add to Gitea app.ini. RENDER_COMMAND = "timeout 30s ./custom/sphinx/sphinx_to_html.py --user sphinx --user-work-dir /path/to/dir" IS_INPUT_FILE = true + [markup.sanitizer.restructuredtext] + ELEMENT = div + ALLOW_ATTR = class + REGEXP = ^(restructuredtext)$ + [repository.editor] LINE_WRAP_EXTENSIONS = .txt,.md,.markdown,.mdown,.mkd,.rst PREVIEWABLE_FILE_MODES = markdown,restructuredtext diff --git a/sphinx/sphinx_to_html.py b/sphinx/sphinx_to_html.py index c8b86b7..1107b30 100755 --- a/sphinx/sphinx_to_html.py +++ b/sphinx/sphinx_to_html.py @@ -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("
")[1].split("")[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 = '