mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Include language and compiler version in Remix code links
This commit is contained in:
parent
416b13850f
commit
b7942219df
@ -18,11 +18,11 @@ def insert_node_before(child, new_sibling):
|
||||
break
|
||||
|
||||
|
||||
def remix_code_url(source_code):
|
||||
def remix_code_url(source_code, language, solidity_version):
|
||||
# NOTE: base64 encoded data may contain +, = and / characters. Remix seems to handle them just
|
||||
# fine without any escaping.
|
||||
base64_encoded_source = base64.b64encode(source_code.encode('utf-8')).decode('ascii')
|
||||
return f"https://remix.ethereum.org/?code={base64_encoded_source}"
|
||||
return f"https://remix.ethereum.org/?language={language}&version={solidity_version}&code={base64_encoded_source}"
|
||||
|
||||
|
||||
def build_remix_link_node(url):
|
||||
@ -42,17 +42,18 @@ def build_remix_link_node(url):
|
||||
return paragraph_node
|
||||
|
||||
|
||||
def insert_remix_link(app, doctree):
|
||||
def insert_remix_link(app, doctree, solidity_version):
|
||||
if app.builder.format != 'html' or app.builder.name == 'epub':
|
||||
return
|
||||
|
||||
for literal_block_node in doctree.traverse(docutils.nodes.literal_block):
|
||||
assert 'language' in literal_block_node.attributes
|
||||
if literal_block_node.attributes['language'].lower() == 'solidity':
|
||||
language = literal_block_node.attributes['language'].lower()
|
||||
if language in ['solidity', 'yul']:
|
||||
text_nodes = list(literal_block_node.traverse(docutils.nodes.Text))
|
||||
assert len(text_nodes) == 1
|
||||
|
||||
remix_url = remix_code_url(text_nodes[0])
|
||||
remix_url = remix_code_url(text_nodes[0], language, solidity_version)
|
||||
url_length = len(remix_url.encode('utf-8'))
|
||||
if url_length > MAX_SAFE_URL_LENGTH:
|
||||
logger.warning(
|
||||
@ -67,14 +68,16 @@ def insert_remix_link(app, doctree):
|
||||
|
||||
|
||||
def setup(app):
|
||||
# NOTE: Need to access _raw_config here because setup() runs before app.config is ready.
|
||||
solidity_version = app.config._raw_config['version'] # pylint: disable=protected-access
|
||||
|
||||
app.connect(
|
||||
'doctree-resolved',
|
||||
lambda app, doctree, docname: insert_remix_link(app, doctree)
|
||||
lambda app, doctree, docname: insert_remix_link(app, doctree, solidity_version)
|
||||
)
|
||||
|
||||
return {
|
||||
# NOTE: Need to access _raw_config here because setup() runs before app.config is ready.
|
||||
'version': app.config._raw_config['version'], # pylint: disable=protected-access
|
||||
'version': solidity_version,
|
||||
'parallel_read_safe': True,
|
||||
'parallel_write_safe': True,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user