in plugins/mkdocs-atlas-formatting-plugin/mkdocs_atlas_formatting_plugin/block.py [0:0]
def fmt_atlas_expr(self, uri: str, offset: int = 0) -> str:
"""
Given an Atlas URI, extract the query and convert it into a pre-formatted block.
There should be line breaks after each operator and each operator should link to the
Atlas Stack Language Reference. The output is intended to be wrapped in pre tags by
the caller.
Input:
/api/v1/graph?w=200&h=150&no_legend=1&s=e-3h&e=2012-01-01T07:00&tz=UTC&l=0&q=nf.app,alerttest,:eq,name,ssCpuUser,:eq,:and,:sum,80,:gt,5,:rolling-count
Output:
nf.app,alerttest,<a href="https://netflix.github.io/atlas-docs/asl/ref/eq/">:eq</a>,
name,ssCpuUser,<a href="https://netflix.github.io/atlas-docs/asl/ref/eq/">:eq</a>,
<a href="https://netflix.github.io/atlas-docs/asl/ref/and/">:and</a>,
<a href="https://netflix.github.io/atlas-docs/asl/ref/sum/">:sum</a>,
80,<a href="https://netflix.github.io/atlas-docs/asl/ref/gt/">:gt</a>,
5,<a href="https://netflix.github.io/atlas-docs/asl/ref/rolling-count/">:rolling-count</a>
"""
m = self.query_pattern.match(uri)
if not m:
return 'ERROR: query not found'
line = ''
pad = ' ' * offset if offset > 0 else ''
output_lines = []
# Short circuit for examples with a constant for the query or the color queries
if self.number_pattern.match(m.group(1)) or self.color_pattern.match(m.group(1)):
return f'{pad}{line}{m.group(1)}\n'
for item in m.group(1).split(','):
if item.startswith(':'):
output_lines.append(f'{pad}{line}{self.mk_asl_link(item)},')
line = ''
else:
line += f'{item},'
if line:
output_lines.append(f'{pad}{line}')
output_lines[-1] = output_lines[-1][:-1] # strip trailing comma
return '\n'.join(output_lines) + '\n'