Skip to main content

A tool supports converting dictionary to markdown, html and txt.

Project description

dict2str

Support converting dictionary to markdown, html and txt

Usage

Input list

d = dict2str(
    [
        {
            "taskList": {
                "contents": [
                    {
                        "content": "run 100 kilometers",
                        "style": "color: red",
                    },
                    {
                        "content": "do homeworks",
                        "complete": True,
                    },
                ]
            },
        },
    ],
    type="html",
)

print(d)

d.set("markdown")

print(d)

d.set("txt")

print(d)

# <label>
#   <input style='color: red' type='checkbox' disabled='true'>run 100 kilometers</input>
# </label>
# <label>
#   <input type='checkbox' disabled='true' checked>do homeworks</input>
# </label>

# - [ ] run 100 kilometers
# - [x] do homeworks

# 馃敶 run 100 kilometers
# 馃煝 do homeworks
d = dict2str(
    [
        {
            "orderedList": {
                "contents": [
                    {
                        "content": "A",
                        "items": {
                            "unOrderedList": {
                                "contents": [
                                    {
                                        "content": "B",
                                        "items": {
                                            "orderedList": {
                                                "contents": [
                                                    {
                                                        "content": "C",
                                                    },
                                                    {
                                                        "content": "D",
                                                    },
                                                ],
                                            }
                                        },
                                    },
                                    {
                                        "content": "E",
                                        "items": {
                                            "unOrderedList": {
                                                "contents": [
                                                    {
                                                        "content": "F",
                                                    },
                                                    {
                                                        "content": "G",
                                                    },
                                                ],
                                            }
                                        },
                                    },
                                ],
                            }
                        },
                    },
                    {
                        "content": "H",
                    },
                ],
            },
            "unOrderedList": {
                "contents": [
                    {
                        "content": "run 100 kilometers",
                    },
                    {
                        "content": "do homeworks",
                    },
                ],
            },
        },
    ],
    type="markdown",
)

print(d)

# 1. A
#   - B
#     1. C
#     2. D
#   - E
#     - F
#     - G
# 2. H
# - run 100 kilometers
# - do homeworks

Input dictionary

d = dict2str(
    {
        "img": {
            "url": "https://abc.png",
            "alt": "this is an image",
        }
    },
    type="markdown",
)

print(d)

# ![this is an image](https://abc.png)

Support elements

type Element Example
h1 Heading 1 { "h1": { "content": "title 1" } }
h2 Heading 2 { "h2": { "content": "title 2" } }
h3 Heading 3 { "h3": { "content": "title 3" } }
h4 Heading 4 { "h4": { "content": "title 4" } }
h5 Heading 5 { "h5": { "content": "title 5" } }
h6 Heading 6 { "h6": { "content": "title 6" } }
blockquote Blockquote { "blockquote": { "content": "This is a blockquote" } }
img Image { "img": { "url": "https://abc.png", "alt": "this is an image", } }
ul Unordered list { "unOrderedList": { "contents": [{"content": "run 100 kilometers"}, {"content": "do homeworks"}]}}
ol Ordered list { "orderedList": { "contents": [{"content": "run 100 kilometers"}, {"content": "do homeworks"}]}}
table Table { "table": { "contents": [("desc", "content"), ("A", "B")], "position": "left" }
link Link { "link": { "url": "https://google.com", "content": "this is a link" }
tasklist Task list { "tasklist": "contents": [{"content": "run 100 kilometers" },{ "content": "do homeworks", "complete": True }] }
code Code { "code": { "content": "print('hello')" } }
italic Italic { "italic": { "content": "good" } }
strikethrough Strikethrough { "strikethrough": { "content": "nice" } }
bold Bold { "bold": { "content": "excellent", "end": "\n" } }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dict2str-0.0.3.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file dict2str-0.0.3.tar.gz.

File metadata

  • Download URL: dict2str-0.0.3.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for dict2str-0.0.3.tar.gz
Algorithm Hash digest
SHA256 d7203f211607a9e9ebb862929b77bc95c67c14dcc09c3c347d1d64e911151091
MD5 217d5fdae5b3cc6f0a605a7802677c15
BLAKE2b-256 3f24d1c90f2de53b269fae0a993663bed486ab84d351e6df7924625b8faab1bd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page