def to_xml(text, sourcepos=False, smart=False): """Convert markup to XML. Parameters ---------- text: str Text marked up with `CommonMark <http://commonmark.org>`_. sourcepos: bool If ``True``, add ``sourcepos`` attribute to all block elements (that is, use ``CMARK_OPT_SOURCEPOS``). smart: bool Use :py:data:`~paka.cmark.lowlevel.OPT_SMART`. Returns ------- str XML """ opts = _add_smart_to_opts( smart, _add_sourcepos_to_opts(sourcepos, _lowlevel.OPT_DEFAULT)) text_bytes = _lowlevel.text_to_c(text) parsed = _lowlevel.parse_document(text_bytes, len(text_bytes), opts) root = _ffi.gc(parsed, _lowlevel.node_free) return _lowlevel.text_from_c(_lowlevel.render_xml(root, opts))
def to_latex(text, breaks=False, width=0, smart=False): r"""Convert markup to LaTeX. Parameters ---------- text: str Text marked up with `CommonMark <http://commonmark.org>`_. breaks: bool or LineBreaks How line breaks will be rendered. If ``True``, ``"soft"``, or :py:attr:`LineBreaks.soft` -- as newlines. If ``False`` -- “soft break nodes” (single newlines) are rendered as spaces. If ``"hard"`` or :py:attr:`LineBreaks.hard` -- “soft break nodes” are rendered as ``\\\n``. width: int Wrap width of output by inserting line breaks (default is ``0``—no wrapping). Has no effect if ``breaks`` are ``False``. smart: bool Use :py:data:`~paka.cmark.lowlevel.OPT_SMART`. Returns ------- str LaTeX document. """ opts = _add_smart_to_opts( smart, _add_breaks_to_opts(breaks, _lowlevel.OPT_DEFAULT)) text_bytes = _lowlevel.text_to_c(text) parsed = _lowlevel.parse_document(text_bytes, len(text_bytes), opts) root = _ffi.gc(parsed, _lowlevel.node_free) return _lowlevel.text_from_c(_lowlevel.render_latex(root, opts, width))