当前位置: 首页>>代码示例>>Python>>正文


Python pandocfilters.Para方法代码示例

本文整理汇总了Python中pandocfilters.Para方法的典型用法代码示例。如果您正苦于以下问题:Python pandocfilters.Para方法的具体用法?Python pandocfilters.Para怎么用?Python pandocfilters.Para使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandocfilters的用法示例。


在下文中一共展示了pandocfilters.Para方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: tikz

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def tikz(key, value, format, meta):
    if key == 'RawBlock':
        [fmt, code] = value
        if fmt == "latex" and re.match("\\\\begin{tikzpicture}", code):
            outfile = imagedir + '/' + sha1(code)
            if format == "html":
                filetype = "png"
            elif format == "latex":
                filetype = "pdf"
            else:
                filetype = "png"
            src = outfile + '.' + filetype
            if not os.path.isfile(src):
                try:
                    os.mkdir(imagedir)
                    sys.stderr.write('Created directory ' + imagedir + '\n')
                except OSError:
                    pass
                tikz2image(code, filetype, outfile)
                sys.stderr.write('Created image ' + src + '\n')
            return Para([Image(['', [], []], [], [src, ""])]) 
开发者ID:sergiocorreia,项目名称:panflute,代码行数:23,代码来源:tikz.py

示例2: abc

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def abc(key, value, format, meta):
    if key == 'CodeBlock':
        [[ident, classes, keyvals], code] = value
        if "abc" in classes:
            outfile = imagedir + '/' + sha1(code)
            if format == "html":
                filetype = "png"
            elif format == "latex":
                filetype = "pdf"
            else:
                filetype = "png"
            src = outfile + '.' + filetype
            if not os.path.isfile(src):
                try:
                    os.mkdir(imagedir)
                    sys.stderr.write('Created directory ' + imagedir + '\n')
                except OSError:
                    pass
                abc2eps(code.encode("utf-8"), filetype, outfile)
                sys.stderr.write('Created image ' + src + '\n')
            return Para([Image(['', [], []], [], [src, ""])]) 
开发者ID:sergiocorreia,项目名称:panflute,代码行数:23,代码来源:abc.py

示例3: image

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def image(self):
        'gri {im_opt} -c 0 -b <fname>.gri'
        # -> <x>.ps -> <x>.{im_fmt} -> Para(Img(<x>.{im_fmt}))'
        args = self.im_opt + ['-c', '0', '-b', self.inpfile]
        if self.cmd(self.im_prg, *args):
            # gri insists on producing a .ps in current working dir
            dstfile = self.inpfile.replace('.gri', '.ps')
            srcfile = os.path.split(dstfile)[-1]   # the temp ps in working dir
            if os.path.isfile(srcfile):
                self.msg(3, 'moving', srcfile, dstfile)
                os.rename(srcfile, dstfile)
            if self.cmd('convert', dstfile, self.outfile):
                return self.result()
            else:
                self.msg(2, "could not convert gri's ps to", self.im_fmt)
        else:
            # relay gri's complaints on stdout to stderr.
            for line in self.stdout.splitlines():
                self.msg(1, line) 
开发者ID:hertogp,项目名称:imagine,代码行数:21,代码来源:pandoc_imagine.py

示例4: process_figures

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def process_figures(key, value, fmt, meta):  # pylint: disable=unused-argument
    """Processes the figures."""

    # Process figures wrapped in Para elements
    if key == 'Para' and len(value) == 1 and \
      value[0]['t'] == 'Image' and value[0]['c'][-1][1].startswith('fig:'):

        # Process the figure and add markup
        fig = _process_figure(key, value, fmt)
        if 'attrs' in fig:
            _adjust_caption(fmt, fig, value)
        return _add_markup(fmt, fig, value)

    if key == 'Div' and LABEL_PATTERN.match(value[0][0]):
        fig = _process_figure(key, value, fmt)
    
    return None


# TeX blocks -----------------------------------------------------------------

# Define an environment that disables figure caption prefixes.  Counters
# must be saved and later restored.  The \thefigure and \theHfigure counter
# must be set to something unique so that duplicate internal names are avoided
# (see Sect. 3.2 of
# http://ctan.mirror.rafal.ca/macros/latex/contrib/hyperref/doc/manual.html). 
开发者ID:tomduck,项目名称:pandoc-fignos,代码行数:28,代码来源:pandoc_fignos.py

示例5: plantuml

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def plantuml(key, value, format_, _):
    if key == 'CodeBlock':
        [[ident, classes, keyvals], code] = value

        if "plantuml" in classes:
            caption, typef, keyvals = get_caption(keyvals)

            filename = get_filename4code("plantuml", code)
            filetype = get_extension(format_, "png", html="svg", latex="png")

            src = filename + '.uml'
            dest = filename + '.' + filetype

            # Generate image only once
            if not os.path.isfile(dest):
                txt = code.encode(sys.getfilesystemencoding())
                if not txt.startswith(b"@start"):
                    txt = b"@startuml\n" + txt + b"\n@enduml\n"
                with open(src, "wb") as f:
                    f.write(txt)

                subprocess.check_call(PLANTUML_BIN.split() +
                                      ["-t" + filetype, src])
                sys.stderr.write('Created image ' + dest + '\n')

            # Update symlink each run
            for ind, keyval in enumerate(keyvals):
                if keyval[0] == 'plantuml-filename':
                    link = keyval[1]
                    keyvals.pop(ind)
                    rel_mkdir_symlink(dest, link)
                    dest = link
                    break

            return Para([Image([ident, [], keyvals], caption, [dest, typef])]) 
开发者ID:timofurrer,项目名称:pandoc-plantuml-filter,代码行数:37,代码来源:pandoc_plantuml_filter.py

示例6: graphviz

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def graphviz(key, value, format, meta):
    if key == 'CodeBlock':
        [[ident, classes, keyvals], code] = value
        caption = "caption"
        if "graphviz" in classes:
            G = pygraphviz.AGraph(string=code)
            G.layout()
            filename = sha1(code)
            if format == "html":
                filetype = "png"
            elif format == "latex":
                filetype = "pdf"
            else:
                filetype = "png"
            alt = Str(caption)
            src = imagedir + '/' + filename + '.' + filetype
            if not os.path.isfile(src):
                try:
                    os.mkdir(imagedir)
                    sys.stderr.write('Created directory ' + imagedir + '\n')
                except OSError:
                    pass
                G.draw(src)
                sys.stderr.write('Created image ' + src + '\n')
            tit = ""
            return Para([Image(['', [], []], [alt], [src, tit])]) 
开发者ID:sergiocorreia,项目名称:panflute,代码行数:28,代码来源:graphviz.py

示例7: tobullet

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def tobullet(term, defs):
    return([Para([Strong(term)])] + [b for d in defs for b in d]) 
开发者ID:sergiocorreia,项目名称:panflute,代码行数:4,代码来源:deflists.py

示例8: plantuml

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def plantuml(key, value, format, meta):
    if key == 'CodeBlock':
        [[ident, classes, keyvals], code] = value

        if "plantuml" in classes:
            caption, typef, keyvals = filter_keyvalues(keyvals)

            filename = sha1(code)
            if format == "html":
                filetype = "svg"
            elif format == "latex":
                filetype = "eps"
            else:
                filetype = "png"
            src = os.path.join(imagedir, filename + '.uml')
            dest = os.path.join(imagedir, filename + '.' + filetype)

            if not os.path.isfile(dest):
                try:
                    os.mkdir(imagedir)
                    sys.stderr.write('Created directory ' + imagedir + '\n')
                except OSError:
                    pass

                txt =  code.encode("utf-8")
                if not txt.startswith("@start"):
                    txt = "@startuml\n" + txt + "\n@enduml\n"
                with open(src, "w") as f:
                    f.write(txt)

                call(["java", "-jar", "plantuml.jar", "-t"+filetype, src])

                sys.stderr.write('Created image ' + dest + '\n')

            return Para([Image([ident, [], keyvals], caption, [dest, typef])]) 
开发者ID:sergiocorreia,项目名称:panflute,代码行数:37,代码来源:plantuml.py

示例9: url

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def url(self):
        'return an image link for existing/new output image-file'
        # pf.Image is an Inline element. Callers usually wrap it in a pf.Para
        return pf.Image([self.id_, self.classes, self.keyvals],
                        self.caption, [self.outfile, self.typef]) 
开发者ID:hertogp,项目名称:imagine,代码行数:7,代码来源:pandoc_imagine.py

示例10: result

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def result(self):
        'return FCB, Para(url()) and/or CodeBlock(stdout) as ordered'
        rv = []
        enc = sys.getdefaultencoding()  # result always unicode
        for output_elm in self.im_out:
            if output_elm == 'img':
                if os.path.isfile(self.outfile):
                    rv.append(pf.Para([self.url()]))
                else:
                    msg = '?? missing %s' % self.outfile
                    self.msg(1, msg)
                    rv.append(pf.Para([pf.Str(msg)]))

            elif output_elm == 'fcb':
                rv.append(self.anon_codeblock())

            elif output_elm == 'ocb':
                attr = ['', self.classes, self.keyvals]
                rv.append(pf.CodeBlock(attr, self.codec[1]))

            elif output_elm == 'stdout':
                if self.stdout:
                    attr = ['', self.classes, self.keyvals]
                    rv.append(pf.CodeBlock(attr, to_str(self.stdout, enc)))
                else:
                    self.msg(1, 'stdout requested, but saw nothing')

            elif output_elm == 'stderr':
                if self.stderr:
                    attr = ['', self.classes, self.keyvals]
                    rv.append(pf.CodeBlock(attr, to_str(self.stderr, enc)))
                else:
                    self.msg(1, 'stderr requested, but saw nothing')

        if not rv:
            return None               # no results; None keeps original FCB
        if len(rv) > 1:
            return rv                 # multiple results
        return rv[0]                  # just 1 block level element 
开发者ID:hertogp,项目名称:imagine,代码行数:41,代码来源:pandoc_imagine.py

示例11: _add_markup

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def _add_markup(fmt, fig, value):
    """Adds markup to the output."""

    # pylint: disable=global-statement
    global has_tagged_figures  # Flags a tagged figure was found

    if fig['is_unnumbered']:
        if fmt in ['latex', 'beamer']:
            # Use the no-prefix-figure-caption environment
            return [RawBlock('tex', r'\begin{fignos:no-prefix-figure-caption}'),
                    Para(value),
                    RawBlock('tex', r'\end{fignos:no-prefix-figure-caption}')]
        return None  # Nothing to do

    attrs = fig['attrs']
    ret = None

    if fmt in ['latex', 'beamer']:
        if fig['is_tagged']:  # A figure cannot be tagged if it is unnumbered
            # Use the tagged-figure environment
            has_tagged_figures = True
            ret = [RawBlock('tex', r'\begin{fignos:tagged-figure}[%s]' % \
                            str(targets[attrs.id].num)),
                   Para(value),
                   RawBlock('tex', r'\end{fignos:tagged-figure}')]
    elif fmt in ('html', 'html5', 'epub', 'epub2', 'epub3'):
        if LABEL_PATTERN.match(attrs.id):
            pre = RawBlock('html', '<div id="%s" class="fignos">'%attrs.id)
            post = RawBlock('html', '</div>')
            ret = [pre, Para(value), post]
            # Eliminate the id from the Image
            attrs.id = ''
            value[0]['c'][0] = attrs.list
    elif fmt == 'docx':
        # As per http://officeopenxml.com/WPhyperlink.php
        bookmarkstart = \
          RawBlock('openxml',
                   '<w:bookmarkStart w:id="0" w:name="%s"/>'
                   %attrs.id)
        bookmarkend = \
          RawBlock('openxml', '<w:bookmarkEnd w:id="0"/>')
        ret = [bookmarkstart, Para(value), bookmarkend]
    return ret 
开发者ID:tomduck,项目名称:pandoc-fignos,代码行数:45,代码来源:pandoc_fignos.py

示例12: gabc

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def gabc(key, value, fmt, meta):                   # pylint:disable=I0011,W0613
    """Handle gabc file inclusion and gabc code block."""
    if key == 'Code':
        [[ident, classes, kvs], contents] = value  # pylint:disable=I0011,W0612
        kvs = {key: value for key, value in kvs}
        if "gabc" in classes:
            if fmt == "latex":
                if ident == "":
                    label = ""
                else:
                    label = '\\label{' + ident + '}'
                return latex(
                    "\n\\smallskip\n{%\n" +
                    latexsnippet('\\gregorioscore{' + contents + '}', kvs) +
                    "%\n}" +
                    label
                )
            else:
                infile = contents + (
                    '.gabc' if '.gabc' not in contents else ''
                )
                with open(infile, 'r') as doc:
                    code = doc.read().split('%%\n')[1]
                return [Image(['', [], []], [], [
                    png(
                        contents,
                        latexsnippet('\\gregorioscore', kvs)
                    ),
                    ""
                ])]
    elif key == 'CodeBlock':
        [[ident, classes, kvs], contents] = value
        kvs = {key: value for key, value in kvs}
        if "gabc" in classes:
            if fmt == "latex":
                if ident == "":
                    label = ""
                else:
                    label = '\\label{' + ident + '}'
                return [latexblock(
                    "\n\\smallskip\n{%\n" +
                    latexsnippet('\\gabcsnippet{' + contents + '}', kvs) +
                    "%\n}" +
                    label
                    )]
            else:
                return Para([Image(['', [], []], [], [
                    png(
                        contents,
                        latexsnippet('\\gabcsnippet', kvs)
                    ),
                    ""
                ])]) 
开发者ID:sergiocorreia,项目名称:panflute,代码行数:55,代码来源:gabc.py

示例13: wrap_image_output

# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Para [as 别名]
def wrap_image_output(self, chunk_name, data, key, attrs):
        """
        Extra handling for images

        Parameters
        ----------
        chunk_name, data, key : str
        attrs: dict

        Returns
        -------
        Para[Image]
        """
        # TODO: interaction of output type and standalone.
        # TODO: this can be simplified, do the file-writing in one step
        def b64_encode(data):
            return base64.encodebytes(data.encode('utf-8')).decode('ascii')

        # TODO: dict of attrs on Stitcher.
        image_keys = {'width', 'height'}
        caption = attrs.get('fig.cap', '')

        def transform_key(k):
            # fig.width -> width, fig.height -> height;
            return k.split('fig.', 1)[-1]

        attrs = [(transform_key(k), v)
                 for k, v in attrs.items()
                 if transform_key(k) in image_keys]

        if self.self_contained:
            if 'png' in key:
                data = 'data:image/png;base64,{}'.format(data)
            elif 'svg' in key:
                data = 'data:image/svg+xml;base64,{}'.format(b64_encode(data))
            if 'png' in key or 'svg' in key:
                block = Para([Image([chunk_name, [], attrs],
                                    [Str(caption)],
                                    [data, ""])])
            else:
                raise TypeError("Unknown mimetype %s" % key)
        else:
            # we are saving to filesystem
            ext = mimetypes.guess_extension(key)
            filepath = os.path.join(self.resource_dir,
                                    "{}{}".format(chunk_name, ext))
            os.makedirs(self.resource_dir, exist_ok=True)
            if ext == '.svg':
                with open(filepath, 'wt') as f:
                    f.write(data)
            else:
                with open(filepath, 'wb') as f:
                    f.write(base64.decodebytes(data.encode('utf-8')))
            # Image :: alt text (list of inlines), target
            # Image :: Attr [Inline] Target
            # Target :: (string, string)  of (URL, title)
            block = Para([Image([chunk_name, [], []],
                                [Str(caption)],
                                [filepath, "fig: {}".format(chunk_name)])])

        return block 
开发者ID:pystitch,项目名称:stitch,代码行数:63,代码来源:stitch.py


注:本文中的pandocfilters.Para方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。