Package markdown2jira
Convert Markdown to Jira wiki markup.
markdown2jira
Convert Markdown to Jira wiki markup
Installation
You can install this package with pip.
$ pip install markdown2jira
Links
Usage
The simplest way to convert Markdown to Jira wiki markup is the convert() function.
from markdown2jira import convert
convert("# Title\n\nSome **bold** and _italic_ text.")
# 'h1. Title\n\nSome *bold* and _italic_ text.'
By default, convert() parses Markdown using GitHub-flavoured Markdown rules (tables, task
lists, strikethrough, autolinks, footnotes). For more control over parsing and rendering, use
the Markdown2Jira class directly.
from wenmode.presets import commonmark
from markdown2jira import Markdown2Jira
converter = Markdown2Jira(commonmark())
converter.convert("~~not a strikethrough~~")
# '~~not a strikethrough~~'
You can pass any wenmode rules, a custom set of rules, or plugins to customize parsing.
from wenmode.presets import commonmark
from wenmode.rules import Strikethrough
from markdown2jira import Markdown2Jira
converter = Markdown2Jira((*commonmark(), Strikethrough))
converter.convert("~~gone~~")
# '-gone-'
To customize rendering, for example to support custom node types introduced by your own
rules or plugins, subclass JiraRenderer and register handlers for the new node types.
from wenmode.nodes import Heading
from markdown2jira import JiraRenderContext, JiraRenderer, Markdown2Jira
class ShoutingRenderer(JiraRenderer):
pass
@ShoutingRenderer.register("heading")
def render_shouting_heading(
renderer: ShoutingRenderer, node: Heading, context: JiraRenderContext
) -> str:
title = renderer.render_children(node.children, context)
return f"h{node.depth}. {title.upper()}\n\n"
converter = Markdown2Jira(renderer=ShoutingRenderer())
converter.convert("# hello world")
# 'h1. HELLO WORLD'
Functions
def convert(content: str) ‑> str-
Convert a Markdown string to Jira wiki markup, using the default rules and renderer.
- Args
- -----=
content- The Markdown source to convert.
Returns -----= The equivalent Jira wiki markup.
Classes
class JiraRenderContext (list_markers: list[str] = <factory>)-
JiraRenderContext(list_markers: list[str] =
) Ancestors
- wenmode.renderers.base.RenderContext
Instance variables
var list_markers : list[str]-
The type of the None singleton.
class JiraRenderer-
Dispatch-based base class for renderers.
Subclasses register handlers with :meth:
register. A handler receives the renderer instance, the node, and the render context, and returns rendered text.Ancestors
- wenmode.renderers.base.BaseRenderer
Class variables
var handlers : ClassVar[dict[str, Callable[..., str]]]-
The type of the None singleton.
var name : ClassVar[str]-
The type of the None singleton.
var root_post_renderers : ClassVar[list[Callable[..., str]]]-
The type of the None singleton.
var root_pre_renderers : ClassVar[list[Callable[..., str]]]-
The type of the None singleton.
var streaming_safe_to_omit_class_root_hooks : ClassVar[bool]-
The type of the None singleton.
Methods
def create_context(self, node: wenmode.nodes.Node | None = None) ‑> markdown2jira._renderer.JiraRenderContext-
Create a render context for one render call.
:param node: Root node being rendered, when available. :returns: New render context.
class Markdown2Jira (rules: Iterable[type[wenmode._parser.rule_base.Rule] | wenmode._parser.rule_base.Rule] | Callable[[], tuple[type[wenmode._parser.rule_base.Rule] | wenmode._parser.rule_base.Rule, ...]] | None = None,
*,
renderer: wenmode.renderers.base.BaseRenderer | None = None,
plugins: Iterable[wenmode.plugins.types.PluginModule | module] = (),
positions: bool = False)-
Converts Markdown to Jira wiki markup, with configurable parsing rules and rendering.
- Args
- -----=
rules- The Markdown parsing rules to use. Defaults to the GitHub preset (tables, task lists, strikethrough, auto-links, footnotes).
renderer- The renderer used to turn the parsed Markdown into Jira wiki markup. Defaults to
JiraRenderer. SubclassJiraRendererto support custom node types. plugins- Wenmode plugins to extend parsing with, e.g. for custom syntax.
positions- Whether to track source positions on parsed nodes.
Methods
def convert(self, content: str) ‑> str-
Convert a Markdown string to Jira wiki markup.