How to use the panflute.TableCell function in panflute

To help you get started, we’ve selected a few panflute examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sergiocorreia / panflute / tests / test_regressions.py View on Github external
def test_all():
    x=pf.Para(pf.Str("a"))
    y=pf.Para(pf.Str("b"))
    c1=pf.TableCell(x)
    c2=pf.TableCell(y)
    row=pf.TableRow(c1,c2)
    t1 = pf.Table(row)
    t2 = pf.Table(row, header=row)

    print(t1.header)
    print(t2.header)

    with io.StringIO() as f:
        pf.dump(pf.Doc(t1), f)
        print(f.getvalue())

    with io.StringIO() as f:
        pf.dump(pf.Doc(t2), f)
        print(f.getvalue())
github sergiocorreia / panflute-filters / filters / div-tables.py View on Github external
headers = []
    header_found = False
    widths = []
    aligns = []
    caption = None
    for tbl_el in element.content:
        
        if isinstance(tbl_el, pf.Div) and "thead" in tbl_el.classes:
            headers = []
            assert isinstance(tbl_el.content[0], pf.Para), "the table header div must contain a paragraph"
            for head_el in tbl_el.content[0].content:

                if isinstance(head_el, pf.Span):
                    if list(head_el.content):
                        header_found = True              
                    headers.append(pf.TableCell(pf.Plain(*head_el.content))) 
                    if "width" in head_el.attributes:
                        widths.append(float(head_el.attributes["width"]))
                    else:
                        widths.append(0)
                    if "align" in head_el.attributes:
                        align = str(head_el.attributes["align"]).capitalize()
                        assert align in ["Left", "Right", "Center", "Default"], "table alignment must be one of left, right, center or default"
                        aligns.append("Align"+align)   
                    else:
                        aligns.append("AlignDefault")  
        
        elif isinstance(tbl_el, pf.Div) and "tcaption" in tbl_el.classes:
            assert isinstance(tbl_el.content[0], pf.Para), "the table caption div must contain a paragraph"
            caption = list(tbl_el.content[0].content)
                                 
        elif isinstance(tbl_el, pf.Div) and "trow" in tbl_el.classes:
github sergiocorreia / panflute-filters / filters / tabulate-elements.py View on Github external
def finalize(doc):
	c1 = pf.TableCell(pf.Plain(pf.Str("Element")))
	c2 = pf.TableCell(pf.Plain(pf.Str("Frequency")))
	header = pf.TableRow(c1, c2)
	rows = []
	for tag in doc.counter:
		c1 = pf.TableCell(pf.Plain(pf.Str(tag)))
		c2 = pf.TableCell(pf.Plain(pf.Str(str(doc.counter[tag]))))
		rows.append(pf.TableRow(c1, c2))
	table = pf.Table(*rows, header=header)
	doc.content = [table] # bugbug?
github ickc / pantable / pantable / pantable.py View on Github external
def markdown_to_table_cell(string):
        return panflute.TableCell(*panflute.convert_text(string))
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
DefinitionList,
            Div,
            Header,
            HorizontalRule,
            Image,
            LineBlock,
            LineBreak,
            LineItem,
            ListItem,
            Note,
            Para,
            RawBlock,
            RawInline,
            SoftBreak,
            Table,
            TableCell,
            TableRow,
        ),
    ):

        return []
    return None
github sergiocorreia / panflute-filters / filters / tabulate-elements.py View on Github external
def finalize(doc):
	c1 = pf.TableCell(pf.Plain(pf.Str("Element")))
	c2 = pf.TableCell(pf.Plain(pf.Str("Frequency")))
	header = pf.TableRow(c1, c2)
	rows = []
	for tag in doc.counter:
		c1 = pf.TableCell(pf.Plain(pf.Str(tag)))
		c2 = pf.TableCell(pf.Plain(pf.Str(str(doc.counter[tag]))))
		rows.append(pf.TableRow(c1, c2))
	table = pf.Table(*rows, header=header)
	doc.content = [table] # bugbug?
github sergiocorreia / panflute / docs / source / _static / csv-tables.py View on Github external
def fenced_action(options, data, element, doc):
    # We'll only run this for CodeBlock elements of class 'csv'
    title = options.get('title', 'Untitled Table')
    title = [pf.Str(title)]
    has_header = options.get('has-header', False)

    with io.StringIO(data) as f:
        reader = csv.reader(f)
        body = []
        for row in reader:
            cells = [pf.TableCell(pf.Plain(pf.Str(x))) for x in row]
            body.append(pf.TableRow(*cells))

    header = body.pop(0) if has_header else None
    table = pf.Table(*body, header=header, caption=title)
    return table