Skip to main content

使用解析表达式语法将文本从 JIRA 标记转换为 Markdown

项目描述

概述

jira2markdown是一个使用解析表达式语法从JIRA 标记YouTrack Markdown的文本转换器。YouTrack 中的 Markdown 实现遵循带有扩展的CommonMark 规范。因此,jira2markdown可以用最少的修改将文本转换为任何 Markdown 语法。

目录

先决条件

  • Python 3.6+

安装

pip install jira2markdown

用法

from jira2markdown import convert

convert("Some *Jira text* formatting [example|https://example.com].")
# >>> Some **Jira text** formatting [example](https://example.com).

# To convert user mentions provide a mapping Jira internal account id to username 
# as a second argument to convert function
convert("[Winston Smith|~accountid:internal-id] woke up with the word 'Shakespeare' on his lips", {
    "internal-id": "winston",
})
# >>> @winston woke up with the word 'Shakespeare' on his lips

换算表

标题

吉拉 降价
h1. Biggest heading # Biggest heading
h2. Bigger heading ## Bigger heading
h3. Big heading ### Big heading
h4. Normal heading #### Normal heading
h5. Small heading ##### Small heading
h6. Smallest heading ###### Smallest heading

文字效果

吉拉 降价
*strong* **strong**
_emphasis_ 未转换(相同的语法)
??citation?? <q>citation</q>
-deleted- ~~deleted~~
+inserted+ inserted
^superscript^ <sup>superscript</sup>
~subscript~ <sub>subscript</sub>
{{monospaced}} `monospaced`
bq. Some block quoted text > Some block quoted text
{quote}Content to be quoted{quote} > Content to be quoted
{color:red}red text!{color} <font color="red">red text!</font>

文本中断

吉拉 降价
\\ 越线
---
--

链接

吉拉 降价
[#anchor] 未转换
[^attachment.ext] [attachment.ext](attachment.ext)
[http://www.example.com] <http://www.example.com>
[Example|http://example.com] [Example](http://example.com)
[mailto:box@example.com] <box@example.com>
[file:///c:/temp/foo.txt] 未转换
{anchor:anchorname} 未转换
[~username] @username

列表

吉拉 降价
* some
* bullet
** indented
** bullets
* points
- some
- bullet
  - indented
  - bullets
- points
# a
# numbered
# list
1. a
1. numbered
1. list
# a
# numbered
#* with
#* nested
#* bullet
# list
1. a
1. numbered
   - with
   - nested
   - bullet
1. list
* a
* bulleted
*# with
*# nested
*# numbered
* list
- a
- bulleted
  1. with
  1. nested
  1. numbered
- list

图片

吉拉 降价
!image.jpg!
!image.jpg|thumbnail!
!image.gif|align=right, vspace=4!
![image.jpg](image.jpg)

吉拉 降价
||heading 1||heading 2||heading 3||
|col A1|col A2|col A3|
|col B1|col B2|col B3|

|heading 1|heading 2|heading 3|
|-|-|-|
|col A1|col A2|col A3|
|col B1|col B2|col B3|

高级格式化

吉拉 降价
{noformat}
preformatted piece of text
 so *no* further _formatting_ is done here
{noformat}
```
preformatted piece of text
 so *no* further _formatting_ is done here
```
{panel:title=My Title}
Some text with a title
{panel}
> **My Title**
> Some text with a title
{code:xml}
    <test>
        <another tag="attribute"/>
    </test>
{code}
```xml
    <test>
        <another tag="attribute"/>
    </test>
```

定制

要自定义标记元素列表,请将其作为可选参数发送到convert

from jira2markdown import convert
from jira2markdown.elements import MarkupElements
from jira2markdown.markup.links import Link
from jira2markdown.markup.text_effects import Bold

# Only bold and link tokens will be converted here
elements = MarkupElements([Link, Bold])
convert("Some Jira text here", elements=elements)

请记住,标记元素的顺序很重要!元素首先在列表中从上到下匹配。

要覆盖默认元素列表中的某些元素,请使用insert_after/replace方法:

from jira2markdown import convert
from jira2markdown.elements import MarkupElements
from jira2markdown.markup.base import AbstractMarkup
from jira2markdown.markup.links import Link
from jira2markdown.markup.text_effects import Color

class CustomColor(Color):
    ...

class MyElement(AbstractMarkup):
    ...

elements = MarkupElements()
elements.replace(Color, CustomColor)
elements.insert_after(Link, MyElement)
convert("Some Jira text here", elements=elements)

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

jira2markdown-0.2.1.tar.gz (11.1 kB 查看哈希

已上传 source

内置分布

jira2markdown-0.2.1-py3-none-any.whl (12.8 kB 查看哈希

已上传 py3