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:
parent
c676b7b76c
commit
da950a93e2
3 changed files with 37 additions and 4 deletions
|
@ -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"
|
RENDER_COMMAND = "timeout 30s ./custom/sphinx/sphinx_to_html.py --user sphinx --user-work-dir /path/to/dir"
|
||||||
IS_INPUT_FILE = true
|
IS_INPUT_FILE = true
|
||||||
|
|
||||||
|
[markup.sanitizer.restructuredtext]
|
||||||
|
ELEMENT = div
|
||||||
|
ALLOW_ATTR = class
|
||||||
|
REGEXP = ^(restructuredtext)$
|
||||||
|
|
||||||
[repository.editor]
|
[repository.editor]
|
||||||
LINE_WRAP_EXTENSIONS = .txt,.md,.markdown,.mdown,.mkd,.rst
|
LINE_WRAP_EXTENSIONS = .txt,.md,.markdown,.mdown,.mkd,.rst
|
||||||
PREVIEWABLE_FILE_MODES = markdown,restructuredtext
|
PREVIEWABLE_FILE_MODES = markdown,restructuredtext
|
||||||
|
|
|
@ -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
|
# Disable include directives and raw for security. They are already disabled
|
||||||
# by docutils.py, this is just to be extra careful.
|
# by docutils.py, this is just to be extra careful.
|
||||||
def include_directive(matchobj):
|
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):
|
def raw_directive(matchobj):
|
||||||
return f"warning:: raw disabled: {html.escape(matchobj.group(1))}"
|
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("literalinclude::(.*)", include_directive, page_contents)
|
||||||
page_contents = re.sub("include::(.*)", include_directive, page_contents)
|
page_contents = re.sub("include::(.*)", include_directive, page_contents)
|
||||||
page_contents = re.sub("raw::(.*)", raw_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():
|
if result.returncode == 0 and out_filepath.is_file():
|
||||||
contents = out_filepath.read_text()
|
contents = out_filepath.read_text()
|
||||||
body = contents.split("<body>")[1].split("</body>")[0]
|
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 = body.replace('href="http', 'target="_blank" href="http')
|
||||||
|
body = '<div class="restructuredtext">' + body + '</div>'
|
||||||
print(body)
|
print(body)
|
||||||
|
|
|
@ -228,4 +228,31 @@
|
||||||
footer a {
|
footer a {
|
||||||
color: var(--color-footer-links);
|
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>
|
</style>
|
||||||
|
|
Loading…
Reference in a new issue