-
Notifications
You must be signed in to change notification settings - Fork 909
WebHost/Core/Lingo: Render option documentation as reStructuredText in the WebView #3511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a181959
6dbb90a
7f0dbc3
657fb26
9b3d739
181aaec
daea045
11f80af
9f8fbfe
218524f
e07d1fc
90b97bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import os | ||
from textwrap import dedent | ||
from typing import Dict, Union | ||
from docutils.core import publish_parts | ||
|
||
import yaml | ||
from flask import redirect, render_template, request, Response | ||
|
@@ -66,6 +67,20 @@ def filter_dedent(text: str) -> str: | |
return dedent(text).strip("\n ") | ||
|
||
|
||
@app.template_filter("rst_to_html") | ||
def filter_rst_to_html(text: str) -> str: | ||
"""Converts reStructuredText (such as a Python docstring) to HTML.""" | ||
if text.startswith(" ") or text.startswith("\t"): | ||
text = dedent(text) | ||
elif "\n" in text: | ||
lines = text.splitlines() | ||
text = lines[0] + "\n" + dedent("\n".join(lines[1:])) | ||
|
||
return publish_parts(text, writer_name='html', settings=None, settings_overrides={ | ||
'output_encoding': 'unicode' | ||
})['body'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably want to avoid raw html for several reasons text = """.. raw:: html
<script>alert('pwned')</script>"""
publish_parts(text, writer_name="html", settings=None, settings_overrides={"output_encoding": "unicode"})["body"] returns "<script>alert('pwned')</script>" Security may be a concern, since the option export could be "safe" (i.e. jsonworlds), but even if it wasn't, we don't want to have people put raw html there to work around issues instead of fixing them in core. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fortunately this is an easy fix 🙂 |
||
|
||
|
||
@app.template_test("ordered") | ||
def test_ordered(obj): | ||
return isinstance(obj, collections.abc.Sequence) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This file triggers various "legacy modes" for worlds, so that breaking changes | ||
# can be made without needing to simultaneously update or break every exisitng | ||
# world. Authors of worlds listed here should remove their worlds when they have | ||
# time to update them to the new behavior. | ||
|
||
from Options import PerGameCommonOptions | ||
from worlds.AutoWorld import AutoWorldRegister | ||
|
||
# # Option docstring format | ||
# | ||
# These worlds still use the old-style plain text Option docstrings. All other | ||
# worlds' Option docstrings are parsed as reStructuredText (the standard Python | ||
# docstring format) and rendered as HTML in the WebHost. | ||
for world_name in [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks APWorlds. Please don't do this. Let the world opt in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imo breaking something purely visual for an apworld during AP's 0.# days, especially when apworld don't usually worry about being displayed on WebHost (cause how would they), needs to be okay There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, with Phar's alternate suggestion of how to implement this, I'm now on board with this being opt in. Just saying right now that I disagree with your philisophy in general and it will probably come up again in the future :P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering the long-term goal is decoupling worlds from core, I'm against adding anything that adds special privileges to worlds currently in the core repo (it also can't be edited easily from outside the apworld, if one of these world authors releases an updated apworld that would get placed in a webhost). So regardless of what is decided (breaking existing APworlds or not), I am firmly against this file existing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To give some background here, this was intended as a combined solution for two problems:
APWorlds could still easily keep the old behavior by adding All that said, it sounds like the consensus is that the core maintainers prefer this to be opt-out. I worry that's not the right call in the long-term when plain text option docs provide no benefits other than backwards-compatibility, but I'll bow to your decision and make the change. |
||
"Adventure", "A Hat in Time", "A Link to the Past", "Aquaria", "ArchipIDLE", "A Short Hike", | ||
"Blasphemous", "Bomb Rush Cyberfunk", "Bumper Stickers", "Castlevania 64", "Celeste 64", | ||
"ChecksFinder", "Clique", "Dark Souls III", "DLCQuest", "Donkey Kong Country 3", "DOOM 1993", | ||
"DOOM II", "Factorio", "Final Fantasy", "Final Fantasy Mystic Quest", "Heretic", | ||
"Hollow Knight", "Hylics 2", "Kingdom Hearts 2", "Kirby's Dream Land 3", | ||
"Landstalker - The Treasures of King Nole", "Lufia II Ancient Cave", | ||
"Mario & Luigi Superstar Saga", "MegaMan Battle Network 3", "Meritous", "Minecraft", | ||
"Muse Dash", "Noita", "Ocarina of Time", "Overcooked! 2", "Pokemon Emerald", | ||
"Pokemon Red and Blue", "Raft", "Risk of Rain 2", "Rogue Legacy", "Secret of Evermore", | ||
"Shivers", "Slay the Spire", "SMZ3", "Sonic Adventure 2 Battle", "Starcraft 2", | ||
"Stardew Valley", "Subnautica", "Sudoku", "Super Mario 64", "Super Mario World", | ||
"Super Metroid", "Terraria", "The Legend of Zelda", "The Messenger", "The Witness", | ||
"Timespinner", "TUNIC", "Undertale", "VVVVVV", "Wargroove", "Yoshi's Island", "Yu-Gi-Oh! 2006", | ||
"Zillion" | ||
]: | ||
common_options = set(option for option in PerGameCommonOptions.type_hints.values()) | ||
world = AutoWorldRegister.world_types[world_name] | ||
for option in world.options_dataclass.type_hints.values(): | ||
if option not in common_options: | ||
option.plain_text_doc = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than attach this to the
Option
class itself, wouldn't it make more sense to make this an attribute onWebWorld
itself that applies to all options?I don't see a reason why anyone migrating to reST formatting wouldn't just update all their doccomments, and depending on which becomes default (plain text should be default imo), if a dev decides to use the other, they'll have to set it on every option class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is such a better suggestion than what I've been suggesting holy damn
Yeah I think I'm now on board with this over my initial suggestion, and at that point, I think it's much better if this feature is opt-in than opt-out