當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。