text
stringlengths
0
828
if key != ""Div"" or format != ""latex"":
return None
[[_, classes, _], contents] = value
try:
alert_type = [name.split(""-"")[1] for name in classes if ""-"" in name][0]
except IndexError:
return None
if alert_type not in ALLOWED_ALERT_TYPES.__members__:
return None
filtered = [RawBlock(""latex"", rf""\begin{{{alert_type}box}}"")]
filtered.extend(contents)
filtered.append(RawBlock(""latex"", rf""\end{{{alert_type}box}}""))
return filtered"
1359,"def convert_div(text: str, format: Optional[str] = None) -> ""applyJSONFilters"":
""""""Apply the `dev_filter` action to the text.""""""
return applyJSONFilters([div_filter], text, format=format)"
1360,"def raw_html_filter(key: str, value: list, format: str, meta: Any) -> Optional[list]:
""""""Filter the JSON ``value`` for raw html to convert to LaTeX.
Arguments
---------
key
Key of the structure
value
Values in the structure
format
Output format of the processing
meta
Meta information
""""""
if key == ""RawInline"" and format == ""latex"" and value[0] == ""html"":
if value[1] == ""<sup>"":
filtered = [RawInline(""latex"", r""\textsuperscript{"")]
elif value[1] == ""</sup>"":
filtered = [RawInline(""latex"", ""}"")]
elif value[1] == ""<sub>"":
filtered = [RawInline(""latex"", r""\textsubscript{"")]
elif value[1] == ""</sub>"":
filtered = [RawInline(""latex"", ""}"")]
else:
return None
return filtered
return None"
1361,"def convert_raw_html(text: str, format: Optional[str] = None) -> ""applyJSONFilters"":
""""""Apply the `raw_html_filter` action to the text.""""""
return applyJSONFilters([raw_html_filter], text, format=format)"
1362,"def add(self, element):
""""""Add an element to this set.""""""
key = self._transform(element)
if key not in self._elements:
self._elements[key] = element"
1363,"def discard(self, element):
""""""Remove an element. Do not raise an exception if absent.""""""
key = self._transform(element)
if key in self._elements:
del self._elements[key]"
1364,"def add_items_to_message(msg, log_dict):
""""""Utility function to add dictionary items to a log message.""""""
out = msg
for key, value in log_dict.items():
out += "" {}={}"".format(key, value)
return out"
1365,"def log_event(event, logger=root_logger, **log_dict):
""""""
Utility function for logging an event (e.g. for metric analysis).
If no logger is given, fallback to the root logger.
""""""
msg = ""event={}"".format(event)
msg = add_items_to_message(msg, log_dict)
log_dict.update({'event': event})
logger.info(msg, extra=log_dict)"
1366,"def metric(cls, name, count, elapsed):
""""""A metric function that writes multiple CSV files
:arg str name: name of the metric
:arg int count: number of items
:arg float elapsed: time in seconds
""""""
if name is None:
warnings.warn(""Ignoring unnamed metric"", stacklevel=3)
return
with cls.lock:
if not cls.instances:
# first call
shutil.rmtree(cls.outdir, ignore_errors=True)
os.makedirs(cls.outdir)
if cls.dump_atexit: atexit.register(cls.dump)
try:
self = cls.instances[name]
except KeyError: