Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Filter jupyter nbconvert寄存器jinja滤波器_Filter_Jinja2_Jupyter_Nbconvert - Fatal编程技术网

Filter jupyter nbconvert寄存器jinja滤波器

Filter jupyter nbconvert寄存器jinja滤波器,filter,jinja2,jupyter,nbconvert,Filter,Jinja2,Jupyter,Nbconvert,对于jupyter sas_内核,我正在为nbconvert(版本4.2.0)编写一个模板。基本布局如下: {%- extends 'null.tpl' -%} {# Comment block #} {% block header %} /* coding: SAS utf-8 */ {% endblock header %} {% block in_prompt %} /* In[{{ cell.execution_count if cell.execution_count else

对于jupyter sas_内核,我正在为nbconvert(版本4.2.0)编写一个模板。基本布局如下:

{%- extends 'null.tpl' -%}
{#  Comment block #}

{% block header %}
/* coding: SAS utf-8 */
{% endblock header %}

{% block in_prompt %}
/* In[{{ cell.execution_count if cell.execution_count else ' ' }}]: */
{% endblock in_prompt %}

{% block input %}
{{ cell.source | ipython2python | sas_magic_regex }}
{% endblock input %}

{% block markdowncell scoped %}
/*
{{ cell.source | comment_lines(prefix='*') }}
*/
{% endblock markdowncell %}
在block input部分,我需要使用正则表达式来处理
ipython2python
中的文本,主要用于处理魔术调用。我无法从列表中看到正则表达式函数 所以我写了我自己的:

def sas_magic_regex(string:str) -> str:
    """ Replace Python Magics with a commented out version or the SAS x command """
    sas_magic=re.compile(r'^get_ipython.*?(\w+)\(\'(.*)\'\)')
    newStr=sas_magic.search(string)
    if len(newStr.groups())==2:
        if newStr.group(1)=='system':
            return 'x ' + newStr.group(2) + ';'
        else:
            return '/* Jupyter magic ' + string + ' */'
env = Environment()
env.filters['sas_magic_regex'] = sas_magic_regex
问题是nbconvert找不到这个jinja过滤器。
我收到以下错误消息:
jinja2.exceptions.TemplateAssertionError:没有名为“sas\u magic\u regex”的筛选器

您可能已经看到了这一点,但声明从中继承以添加筛选器。