Skip to main content

A Python package aimed to simplify the processing of the mobiledoc format.

Project description

Mobiledoc

A Python package aimed to simplify the processing of the mobiledoc format.

Features

  • Simple API: Intuitive methods to easily add text, formatted text, dividers, and custom data.
  • Markdown-like Formatting: Write using familiar markdown-like syntax, and let the package do the heavy lifting.
  • Serialization: Serialize the mobiledoc object into a JSON-friendly format.

Installation

pip install mobiledoc PyPi

Example

from mobiledoc import Mobiledoc
import json

mobiledoc = Mobiledoc()
mobiledoc.add_basic_text("This is a basic text, which is not formatted.")
mobiledoc.add_basic_text(["You may also add a list of strings.", "To add multiple paragraphs."])
mobiledoc.add_divider()  # add a divider
mobiledoc.add_formatted_text("Using **markdown-like** syntax, you can *format* the text.")
mobiledoc.add_formatted_text(["You may also add a `list of strings`.", "To ^add^ ^^multiple^^ paragraphs.",
                              "You can also add [hyperlinks](https://python.org)."])

mobiledoc = mobiledoc.serialize()  # This will save the mobiledoc as a dictionary

with open('doc.json', 'w') as f:
    json.dump(mobiledoc, f, indent=4)  # check out the doc.json file to see the mobiledoc just created!

This will create redy-to-use mobiledoc like below. (click expand to see the mobiledoc)

Full mobiledoc
{
    "version": "0.3.2",
    "markups": [
        ["b"],
        ["i"],
        ["code"],
        ["sub"],
        ["sup"],
        ["a", ["href", "https://python.org"]]
    ],
    "atoms": [],
    "cards": [
        ["hr", {}]
    ],
    "sections": [
        [1, "p", [
            [0, [], 0, "This is a basic text, which is not formatted."]
        ]],
        [1, "p", [
            [0, [], 0, "You may also add a list of strings."]
        ]],
        [1, "p", [
            [0, [], 0, "To add multiple paragraphs."]
        ]],
        [10, 0],
        [1, "p", [
            [0, [], 0, "Using "],
            [0, [0], 1, "markdown-like"],
            [0, [], 0, " syntax, you can "],
            [0, [1], 1, "format"],
            [0, [], 0, " the text."]
        ]],
        [1, "p", [
            [0, [], 0, "You may also add a "],
            [0, [2], 1, "list of strings"],
            [0, [], 0, "."]
        ]],
        [1, "p", [
            [0, [], 0, "To "],
            [0, [3], 1, "add"],
            [0, [], 0, " "],
            [0, [4], 1, "multiple"],
            [0, [], 0, " paragraphs."]
        ]],
        [1, "p", [
            [0, [], 0, "You can also add "],
            [0, [5], 1, "hyperlinks"],
            [0, [], 0, "."]
        ]]
    ]
}

API

Composing mobiledoc

  • add_basic_text(text: Union[str, List[str]]): Adds basic text to mobiledoc.

  • add_formatted_text(text: Union[str, List[str]]): Adds markdown-like formatted text to mobiledoc.

    • Supported Markdown-like Patterns:
      **: bold
      *: italic
      ~~: strikethrough
      ^^: superscript
      ^: subscript
      __: underline
      `: code
      [text](link): hyperlink
      
  • add_divider(): Adds a divider to mobiledoc.

  • add_image(url: str, caption: str = None): Adds an image to mobiledoc.

  • add_button(text: str, url: str, alignment:str = "center"): Adds a button to mobiledoc.

  • add_HTML(self, html:str):: Adds raw HTML card to mobiledoc.

  • add_markdown(self, markdown:str):: Adds raw markdown card to mobiledoc.

  • add_file(self, url: str, filename: str, filetitle: str, filesize: int, filecaption: str = ""):: Adds a file to mobiledoc.

  • def add_callout(self, text: str, emoji: str = "", color: str = "accent"):: Adds a callout to mobiledoc.

  • custom_data(name: str, value): Adds custom data to mobiledoc.

Serializing mobiledoc

  • serialize(): Returns the serialized mobiledoc Python dictionary that can be passed to json.dump().

Checking mobiledoc

  • get_markups(): Returns the current markups.
  • get_sections(): Returns the current sections.
  • get_atoms(): Returns the current atoms.
  • get_cards(): Returns the current cards.
  • get_custom(): Returns the current custom data.

Contributing

Contributions are welcome! Please submit a pull request or open an issue on GitHub.


I hope this README provides a clear overview of the mobiledoc package. You can further customize it as per your needs!

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

mobiledoc-0.2.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

mobiledoc-0.2.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file mobiledoc-0.2.1.tar.gz.

File metadata

  • Download URL: mobiledoc-0.2.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for mobiledoc-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f0e7093ed7e15aac1d54b67cc18c65cec428f40b348d64957137c6cc1494cb31
MD5 77f21f23d5f092bddc7f44cb8d0c7bb3
BLAKE2b-256 b7704de4d7d948e9c7b48db79c1b7b7a4c41a3170fc0ea4518ac9d60d94b6532

See more details on using hashes here.

File details

Details for the file mobiledoc-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mobiledoc-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for mobiledoc-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b1a1d4571435e0fc330e9e15cb941d52809d548bede4da710fe3e79b2c730c8
MD5 d3b113809e8d8e844a3816120ed6c9d6
BLAKE2b-256 98b433212260347faad3fb1417df539631e2f90209ceba4db696dce09559fe3b

See more details on using hashes here.

Supported by

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