0
Fork 0
mirror of https://projects.blender.org/infrastructure/gitea-custom.git synced 2025-01-02 21:00:05 -05:00

Fix issues with links, includes and notes in Sphinx .rst preview styling

This commit is contained in:
Brecht Van Lommel 2023-03-14 00:58:31 +01:00
parent c676b7b76c
commit da950a93e2
3 changed files with 37 additions and 4 deletions

View file

@ -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

View file

@ -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)

View file

@ -228,4 +228,31 @@
footer a {
color: var(--color-footer-links);
}
/* Manual preview tweaks. */
.restructuredtext a {
color: var(--color-accent) !important;
}
.restructuredtext :is(section, dd) > div {
background-color: var(--color-markup-code-block);
padding-bottom: 8px;
margin-bottom: 16px;
padding: 0;
border-radius: 5px;
}
.restructuredtext section div > p:first-child {
font-weight: 700;
}
.restructuredtext section div * {
margin: 0 !important;
}
.restructuredtext section div > :is(p, dl) {
padding: 8px 12px;
}
.restructuredtext section div > ul {
padding-bottom: 12px;
}
.restructuredtext section dl dt {
font-style: normal;
}
</style>