mformat 0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mformat-0.2/PKG-INFO +130 -0
- mformat-0.2/README_pypi.md +110 -0
- mformat-0.2/mformat.egg-info/PKG-INFO +130 -0
- mformat-0.2/mformat.egg-info/SOURCES.txt +18 -0
- mformat-0.2/mformat.egg-info/dependency_links.txt +1 -0
- mformat-0.2/mformat.egg-info/requires.txt +4 -0
- mformat-0.2/mformat.egg-info/top_level.txt +1 -0
- mformat-0.2/pyproject.toml +22 -0
- mformat-0.2/setup.cfg +4 -0
- mformat-0.2/setup.py +22 -0
- mformat-0.2/src/mformat/__init__.py +6 -0
- mformat-0.2/src/mformat/factory.py +185 -0
- mformat-0.2/src/mformat/mformat.py +719 -0
- mformat-0.2/src/mformat/mformat_html.py +245 -0
- mformat-0.2/src/mformat/mformat_lists_impl.py +368 -0
- mformat-0.2/src/mformat/mformat_md.py +384 -0
- mformat-0.2/src/mformat/mformat_state.py +39 -0
- mformat-0.2/src/mformat/mformat_textbased.py +69 -0
- mformat-0.2/src/mformat/py.typed +0 -0
- mformat-0.2/src/mformat/reg_pkg_formats.py +23 -0
mformat-0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mformat
|
|
3
|
+
Version: 0.2
|
|
4
|
+
Summary: Uniform way to write simple text to different file formats
|
|
5
|
+
Author: Tom Björkholm
|
|
6
|
+
Author-email: Tom Björkholm <klausuler_linnet0q@icloud.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Source code, https://bitbucket.org/tom-bjorkholm/mformat
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: pip
|
|
14
|
+
Requires-Dist: setuptools
|
|
15
|
+
Requires-Dist: build
|
|
16
|
+
Requires-Dist: wheel
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: requires-dist
|
|
19
|
+
Dynamic: requires-python
|
|
20
|
+
|
|
21
|
+
# mformat
|
|
22
|
+
|
|
23
|
+
The mformat package contains a number of classes providing a uniform way for a python program to write to a number of different file formats.
|
|
24
|
+
|
|
25
|
+
The primary intended use is for text output from a python program, where the programmer would like the user to be able to select the output file formats. Some users may want the text as a Microsoft Word file, others as a LibreOffice Open Document Text file, while still others might want it as Markdown. By using the uniform way of writing provided by mformat the same python code can produce output in a number of different formats.
|
|
26
|
+
|
|
27
|
+
This is intended to provide an easy and uniform way to produce information in different formats. The emphasis is on getting the same information into the different formats. This will allow you to get a correct (but perhaps rudimentary) document in several formats. If you want to produce the most estetically pleasing document in a particular format, this is not the correct library to use.
|
|
28
|
+
|
|
29
|
+
## Installing mformat (base package, this package)
|
|
30
|
+
|
|
31
|
+
The base package contains support for the output formats that are supported with a minimum of dependencies. Use this if you for some reason want to avoid extra dependencies.
|
|
32
|
+
|
|
33
|
+
If you want to use it, install it using pip from [https://pypi.org/project/mformat](https://pypi.org/project/mformat). There is no need to download anything from Bitbucket to write Python programs that use the library.
|
|
34
|
+
|
|
35
|
+
### Installing base mformat on mac and Linux
|
|
36
|
+
|
|
37
|
+
````sh
|
|
38
|
+
pip3 install --upgrade mformat
|
|
39
|
+
````
|
|
40
|
+
|
|
41
|
+
### Installing base mformat on Microsoft Windows
|
|
42
|
+
|
|
43
|
+
````sh
|
|
44
|
+
pip install --upgrade mformat
|
|
45
|
+
````
|
|
46
|
+
|
|
47
|
+
## Installing mformat-ext (extended package)
|
|
48
|
+
|
|
49
|
+
The extended package contains support also for output formats that require some additional dependencies. Use this if you want the full selection of output formats.
|
|
50
|
+
|
|
51
|
+
If you want to use it, install it using pip from [https://pypi.org/project/mformat-ext](https://pypi.org/project/mformat-ext). There is no need to download anything from Bitbucket to write Python programs that use the library.
|
|
52
|
+
|
|
53
|
+
### Installing extended mformat on mac and Linux
|
|
54
|
+
|
|
55
|
+
````sh
|
|
56
|
+
pip3 install --upgrade mformat-ext
|
|
57
|
+
````
|
|
58
|
+
|
|
59
|
+
### Installing extended mformat on Microsoft Windows
|
|
60
|
+
|
|
61
|
+
````sh
|
|
62
|
+
pip install --upgrade mformat-ext
|
|
63
|
+
````
|
|
64
|
+
|
|
65
|
+
## What it does
|
|
66
|
+
|
|
67
|
+
The main features supported in a uniform way for all supported output file formats are:
|
|
68
|
+
|
|
69
|
+
* Factory function that takes file format and output file name as arguments
|
|
70
|
+
* It opens and closes a file in the selected format, with protection against accidentically overwriting an existing file
|
|
71
|
+
* The recommended way to use it is as a context manager in a with-clause, opening and closing the file
|
|
72
|
+
* Headings (several levels)
|
|
73
|
+
* Paragraphs
|
|
74
|
+
* Nested bullet point lists
|
|
75
|
+
* Nested numbered point lists
|
|
76
|
+
* Mixed nested numbered point and bullet point lists
|
|
77
|
+
* Tables
|
|
78
|
+
* URLs in paragraphs, headings, numbered point list items and in bullet point list items
|
|
79
|
+
|
|
80
|
+
## Design of program that uses mformat
|
|
81
|
+
|
|
82
|
+
It is recommended that the ouput function(s) of the a Python program using mformat should have a with-clause getting the formatting object from the factory (easiest with `with create_mf(file_format=fmt, file_name=output_file_name) as`).
|
|
83
|
+
In the context of the with-clause the programmer just calls a minimum of member functions:
|
|
84
|
+
|
|
85
|
+
* `start_paragraph` to start a new paragraph with some provided text content.
|
|
86
|
+
* `start_heading`to start a new heading with some provided text content.
|
|
87
|
+
* `start_bullet_item` to start a new bullet point list item with some provided text content, and if needed to start the bullet point list with the bullet point item.
|
|
88
|
+
* `start_numbered_point_item` to start a new numbered point list item with some provided text content, and if needed to start the numbered point list with the number point list item.
|
|
89
|
+
* `add_text` to add more text to an already started paragraph, heading, bullet point list item or numbered point list item.
|
|
90
|
+
* `add_url` to add a URL (link) to an already started paragraph, heading, bullet point list item or numbered point list item.
|
|
91
|
+
* `start_table` to start a new table with the provided first row.
|
|
92
|
+
* `add_table_row` to add another row to an already started table.
|
|
93
|
+
* `write_complete_table` to write a table all at once.
|
|
94
|
+
* `write_code_block` to write some preformatted text as a code block
|
|
95
|
+
|
|
96
|
+
There are no member functions to end or close any document item. Each document item is automatically closed as another docuemnt item is started (or when closing the file at the end of the context manager scope). `start_bullet_item`and `start_numbered_point_item` take an optional level argument, that is used to change to another nesting level.
|
|
97
|
+
|
|
98
|
+
## Example programs
|
|
99
|
+
|
|
100
|
+
A number of minimal but complete example programs are provided to help the programmer new to mformat. See [list of examples](https://bitbucket.org/tom-bjorkholm/mformat/src/master/example/README.md).
|
|
101
|
+
|
|
102
|
+
## API documentation
|
|
103
|
+
|
|
104
|
+
API documentation automatically extracted from the Python code and docstrings are available [here for the public API](https://bitbucket.org/tom-bjorkholm/mformat/src/master/doc/api.md) for programmers using the API and [here for the protected API](https://bitbucket.org/tom-bjorkholm/mformat/src/master/doc/protected_api.md) for programmers that want to extend the API by adding their own derived class that provide some other output format.
|
|
105
|
+
|
|
106
|
+
Even though some may like reading API documentation, the [example programs](https://bitbucket.org/tom-bjorkholm/mformat/src/master/example/README.md) probably provide a better introduction.
|
|
107
|
+
|
|
108
|
+
## Version history
|
|
109
|
+
|
|
110
|
+
| Version | Date | Python version | Description |
|
|
111
|
+
|---------|-------------|-----------------|-------------------------------------|
|
|
112
|
+
| 0.2 | 30 Jan 2026 | 3.12 or newer | First released version |
|
|
113
|
+
|
|
114
|
+
## Output file formats
|
|
115
|
+
|
|
116
|
+
The following table provides information about in which version support for a format was introduced.
|
|
117
|
+
|
|
118
|
+
| Format | Full name of format | Which package | Starting at version |
|
|
119
|
+
|--------|---------------------|---------------|---------------------|
|
|
120
|
+
| docx | Microsoft Word | mformat-ext | 0.2 |
|
|
121
|
+
| html | Web page | mformat | 0.2 |
|
|
122
|
+
| md | Markdown | mformat | 0.2 |
|
|
123
|
+
| odt | Open Document Text | mformat-ext | 0.2 |
|
|
124
|
+
|
|
125
|
+
## Test summary
|
|
126
|
+
|
|
127
|
+
* Test result: 916 passed in 10s
|
|
128
|
+
* No Flake8 warnings.
|
|
129
|
+
* No mypy errors found.
|
|
130
|
+
* 0.2 built and tested using python version: Python 3.14.2
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# mformat
|
|
2
|
+
|
|
3
|
+
The mformat package contains a number of classes providing a uniform way for a python program to write to a number of different file formats.
|
|
4
|
+
|
|
5
|
+
The primary intended use is for text output from a python program, where the programmer would like the user to be able to select the output file formats. Some users may want the text as a Microsoft Word file, others as a LibreOffice Open Document Text file, while still others might want it as Markdown. By using the uniform way of writing provided by mformat the same python code can produce output in a number of different formats.
|
|
6
|
+
|
|
7
|
+
This is intended to provide an easy and uniform way to produce information in different formats. The emphasis is on getting the same information into the different formats. This will allow you to get a correct (but perhaps rudimentary) document in several formats. If you want to produce the most estetically pleasing document in a particular format, this is not the correct library to use.
|
|
8
|
+
|
|
9
|
+
## Installing mformat (base package, this package)
|
|
10
|
+
|
|
11
|
+
The base package contains support for the output formats that are supported with a minimum of dependencies. Use this if you for some reason want to avoid extra dependencies.
|
|
12
|
+
|
|
13
|
+
If you want to use it, install it using pip from [https://pypi.org/project/mformat](https://pypi.org/project/mformat). There is no need to download anything from Bitbucket to write Python programs that use the library.
|
|
14
|
+
|
|
15
|
+
### Installing base mformat on mac and Linux
|
|
16
|
+
|
|
17
|
+
````sh
|
|
18
|
+
pip3 install --upgrade mformat
|
|
19
|
+
````
|
|
20
|
+
|
|
21
|
+
### Installing base mformat on Microsoft Windows
|
|
22
|
+
|
|
23
|
+
````sh
|
|
24
|
+
pip install --upgrade mformat
|
|
25
|
+
````
|
|
26
|
+
|
|
27
|
+
## Installing mformat-ext (extended package)
|
|
28
|
+
|
|
29
|
+
The extended package contains support also for output formats that require some additional dependencies. Use this if you want the full selection of output formats.
|
|
30
|
+
|
|
31
|
+
If you want to use it, install it using pip from [https://pypi.org/project/mformat-ext](https://pypi.org/project/mformat-ext). There is no need to download anything from Bitbucket to write Python programs that use the library.
|
|
32
|
+
|
|
33
|
+
### Installing extended mformat on mac and Linux
|
|
34
|
+
|
|
35
|
+
````sh
|
|
36
|
+
pip3 install --upgrade mformat-ext
|
|
37
|
+
````
|
|
38
|
+
|
|
39
|
+
### Installing extended mformat on Microsoft Windows
|
|
40
|
+
|
|
41
|
+
````sh
|
|
42
|
+
pip install --upgrade mformat-ext
|
|
43
|
+
````
|
|
44
|
+
|
|
45
|
+
## What it does
|
|
46
|
+
|
|
47
|
+
The main features supported in a uniform way for all supported output file formats are:
|
|
48
|
+
|
|
49
|
+
* Factory function that takes file format and output file name as arguments
|
|
50
|
+
* It opens and closes a file in the selected format, with protection against accidentically overwriting an existing file
|
|
51
|
+
* The recommended way to use it is as a context manager in a with-clause, opening and closing the file
|
|
52
|
+
* Headings (several levels)
|
|
53
|
+
* Paragraphs
|
|
54
|
+
* Nested bullet point lists
|
|
55
|
+
* Nested numbered point lists
|
|
56
|
+
* Mixed nested numbered point and bullet point lists
|
|
57
|
+
* Tables
|
|
58
|
+
* URLs in paragraphs, headings, numbered point list items and in bullet point list items
|
|
59
|
+
|
|
60
|
+
## Design of program that uses mformat
|
|
61
|
+
|
|
62
|
+
It is recommended that the ouput function(s) of the a Python program using mformat should have a with-clause getting the formatting object from the factory (easiest with `with create_mf(file_format=fmt, file_name=output_file_name) as`).
|
|
63
|
+
In the context of the with-clause the programmer just calls a minimum of member functions:
|
|
64
|
+
|
|
65
|
+
* `start_paragraph` to start a new paragraph with some provided text content.
|
|
66
|
+
* `start_heading`to start a new heading with some provided text content.
|
|
67
|
+
* `start_bullet_item` to start a new bullet point list item with some provided text content, and if needed to start the bullet point list with the bullet point item.
|
|
68
|
+
* `start_numbered_point_item` to start a new numbered point list item with some provided text content, and if needed to start the numbered point list with the number point list item.
|
|
69
|
+
* `add_text` to add more text to an already started paragraph, heading, bullet point list item or numbered point list item.
|
|
70
|
+
* `add_url` to add a URL (link) to an already started paragraph, heading, bullet point list item or numbered point list item.
|
|
71
|
+
* `start_table` to start a new table with the provided first row.
|
|
72
|
+
* `add_table_row` to add another row to an already started table.
|
|
73
|
+
* `write_complete_table` to write a table all at once.
|
|
74
|
+
* `write_code_block` to write some preformatted text as a code block
|
|
75
|
+
|
|
76
|
+
There are no member functions to end or close any document item. Each document item is automatically closed as another docuemnt item is started (or when closing the file at the end of the context manager scope). `start_bullet_item`and `start_numbered_point_item` take an optional level argument, that is used to change to another nesting level.
|
|
77
|
+
|
|
78
|
+
## Example programs
|
|
79
|
+
|
|
80
|
+
A number of minimal but complete example programs are provided to help the programmer new to mformat. See [list of examples](https://bitbucket.org/tom-bjorkholm/mformat/src/master/example/README.md).
|
|
81
|
+
|
|
82
|
+
## API documentation
|
|
83
|
+
|
|
84
|
+
API documentation automatically extracted from the Python code and docstrings are available [here for the public API](https://bitbucket.org/tom-bjorkholm/mformat/src/master/doc/api.md) for programmers using the API and [here for the protected API](https://bitbucket.org/tom-bjorkholm/mformat/src/master/doc/protected_api.md) for programmers that want to extend the API by adding their own derived class that provide some other output format.
|
|
85
|
+
|
|
86
|
+
Even though some may like reading API documentation, the [example programs](https://bitbucket.org/tom-bjorkholm/mformat/src/master/example/README.md) probably provide a better introduction.
|
|
87
|
+
|
|
88
|
+
## Version history
|
|
89
|
+
|
|
90
|
+
| Version | Date | Python version | Description |
|
|
91
|
+
|---------|-------------|-----------------|-------------------------------------|
|
|
92
|
+
| 0.2 | 30 Jan 2026 | 3.12 or newer | First released version |
|
|
93
|
+
|
|
94
|
+
## Output file formats
|
|
95
|
+
|
|
96
|
+
The following table provides information about in which version support for a format was introduced.
|
|
97
|
+
|
|
98
|
+
| Format | Full name of format | Which package | Starting at version |
|
|
99
|
+
|--------|---------------------|---------------|---------------------|
|
|
100
|
+
| docx | Microsoft Word | mformat-ext | 0.2 |
|
|
101
|
+
| html | Web page | mformat | 0.2 |
|
|
102
|
+
| md | Markdown | mformat | 0.2 |
|
|
103
|
+
| odt | Open Document Text | mformat-ext | 0.2 |
|
|
104
|
+
|
|
105
|
+
## Test summary
|
|
106
|
+
|
|
107
|
+
* Test result: 916 passed in 10s
|
|
108
|
+
* No Flake8 warnings.
|
|
109
|
+
* No mypy errors found.
|
|
110
|
+
* 0.2 built and tested using python version: Python 3.14.2
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mformat
|
|
3
|
+
Version: 0.2
|
|
4
|
+
Summary: Uniform way to write simple text to different file formats
|
|
5
|
+
Author: Tom Björkholm
|
|
6
|
+
Author-email: Tom Björkholm <klausuler_linnet0q@icloud.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Source code, https://bitbucket.org/tom-bjorkholm/mformat
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: pip
|
|
14
|
+
Requires-Dist: setuptools
|
|
15
|
+
Requires-Dist: build
|
|
16
|
+
Requires-Dist: wheel
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: requires-dist
|
|
19
|
+
Dynamic: requires-python
|
|
20
|
+
|
|
21
|
+
# mformat
|
|
22
|
+
|
|
23
|
+
The mformat package contains a number of classes providing a uniform way for a python program to write to a number of different file formats.
|
|
24
|
+
|
|
25
|
+
The primary intended use is for text output from a python program, where the programmer would like the user to be able to select the output file formats. Some users may want the text as a Microsoft Word file, others as a LibreOffice Open Document Text file, while still others might want it as Markdown. By using the uniform way of writing provided by mformat the same python code can produce output in a number of different formats.
|
|
26
|
+
|
|
27
|
+
This is intended to provide an easy and uniform way to produce information in different formats. The emphasis is on getting the same information into the different formats. This will allow you to get a correct (but perhaps rudimentary) document in several formats. If you want to produce the most estetically pleasing document in a particular format, this is not the correct library to use.
|
|
28
|
+
|
|
29
|
+
## Installing mformat (base package, this package)
|
|
30
|
+
|
|
31
|
+
The base package contains support for the output formats that are supported with a minimum of dependencies. Use this if you for some reason want to avoid extra dependencies.
|
|
32
|
+
|
|
33
|
+
If you want to use it, install it using pip from [https://pypi.org/project/mformat](https://pypi.org/project/mformat). There is no need to download anything from Bitbucket to write Python programs that use the library.
|
|
34
|
+
|
|
35
|
+
### Installing base mformat on mac and Linux
|
|
36
|
+
|
|
37
|
+
````sh
|
|
38
|
+
pip3 install --upgrade mformat
|
|
39
|
+
````
|
|
40
|
+
|
|
41
|
+
### Installing base mformat on Microsoft Windows
|
|
42
|
+
|
|
43
|
+
````sh
|
|
44
|
+
pip install --upgrade mformat
|
|
45
|
+
````
|
|
46
|
+
|
|
47
|
+
## Installing mformat-ext (extended package)
|
|
48
|
+
|
|
49
|
+
The extended package contains support also for output formats that require some additional dependencies. Use this if you want the full selection of output formats.
|
|
50
|
+
|
|
51
|
+
If you want to use it, install it using pip from [https://pypi.org/project/mformat-ext](https://pypi.org/project/mformat-ext). There is no need to download anything from Bitbucket to write Python programs that use the library.
|
|
52
|
+
|
|
53
|
+
### Installing extended mformat on mac and Linux
|
|
54
|
+
|
|
55
|
+
````sh
|
|
56
|
+
pip3 install --upgrade mformat-ext
|
|
57
|
+
````
|
|
58
|
+
|
|
59
|
+
### Installing extended mformat on Microsoft Windows
|
|
60
|
+
|
|
61
|
+
````sh
|
|
62
|
+
pip install --upgrade mformat-ext
|
|
63
|
+
````
|
|
64
|
+
|
|
65
|
+
## What it does
|
|
66
|
+
|
|
67
|
+
The main features supported in a uniform way for all supported output file formats are:
|
|
68
|
+
|
|
69
|
+
* Factory function that takes file format and output file name as arguments
|
|
70
|
+
* It opens and closes a file in the selected format, with protection against accidentically overwriting an existing file
|
|
71
|
+
* The recommended way to use it is as a context manager in a with-clause, opening and closing the file
|
|
72
|
+
* Headings (several levels)
|
|
73
|
+
* Paragraphs
|
|
74
|
+
* Nested bullet point lists
|
|
75
|
+
* Nested numbered point lists
|
|
76
|
+
* Mixed nested numbered point and bullet point lists
|
|
77
|
+
* Tables
|
|
78
|
+
* URLs in paragraphs, headings, numbered point list items and in bullet point list items
|
|
79
|
+
|
|
80
|
+
## Design of program that uses mformat
|
|
81
|
+
|
|
82
|
+
It is recommended that the ouput function(s) of the a Python program using mformat should have a with-clause getting the formatting object from the factory (easiest with `with create_mf(file_format=fmt, file_name=output_file_name) as`).
|
|
83
|
+
In the context of the with-clause the programmer just calls a minimum of member functions:
|
|
84
|
+
|
|
85
|
+
* `start_paragraph` to start a new paragraph with some provided text content.
|
|
86
|
+
* `start_heading`to start a new heading with some provided text content.
|
|
87
|
+
* `start_bullet_item` to start a new bullet point list item with some provided text content, and if needed to start the bullet point list with the bullet point item.
|
|
88
|
+
* `start_numbered_point_item` to start a new numbered point list item with some provided text content, and if needed to start the numbered point list with the number point list item.
|
|
89
|
+
* `add_text` to add more text to an already started paragraph, heading, bullet point list item or numbered point list item.
|
|
90
|
+
* `add_url` to add a URL (link) to an already started paragraph, heading, bullet point list item or numbered point list item.
|
|
91
|
+
* `start_table` to start a new table with the provided first row.
|
|
92
|
+
* `add_table_row` to add another row to an already started table.
|
|
93
|
+
* `write_complete_table` to write a table all at once.
|
|
94
|
+
* `write_code_block` to write some preformatted text as a code block
|
|
95
|
+
|
|
96
|
+
There are no member functions to end or close any document item. Each document item is automatically closed as another docuemnt item is started (or when closing the file at the end of the context manager scope). `start_bullet_item`and `start_numbered_point_item` take an optional level argument, that is used to change to another nesting level.
|
|
97
|
+
|
|
98
|
+
## Example programs
|
|
99
|
+
|
|
100
|
+
A number of minimal but complete example programs are provided to help the programmer new to mformat. See [list of examples](https://bitbucket.org/tom-bjorkholm/mformat/src/master/example/README.md).
|
|
101
|
+
|
|
102
|
+
## API documentation
|
|
103
|
+
|
|
104
|
+
API documentation automatically extracted from the Python code and docstrings are available [here for the public API](https://bitbucket.org/tom-bjorkholm/mformat/src/master/doc/api.md) for programmers using the API and [here for the protected API](https://bitbucket.org/tom-bjorkholm/mformat/src/master/doc/protected_api.md) for programmers that want to extend the API by adding their own derived class that provide some other output format.
|
|
105
|
+
|
|
106
|
+
Even though some may like reading API documentation, the [example programs](https://bitbucket.org/tom-bjorkholm/mformat/src/master/example/README.md) probably provide a better introduction.
|
|
107
|
+
|
|
108
|
+
## Version history
|
|
109
|
+
|
|
110
|
+
| Version | Date | Python version | Description |
|
|
111
|
+
|---------|-------------|-----------------|-------------------------------------|
|
|
112
|
+
| 0.2 | 30 Jan 2026 | 3.12 or newer | First released version |
|
|
113
|
+
|
|
114
|
+
## Output file formats
|
|
115
|
+
|
|
116
|
+
The following table provides information about in which version support for a format was introduced.
|
|
117
|
+
|
|
118
|
+
| Format | Full name of format | Which package | Starting at version |
|
|
119
|
+
|--------|---------------------|---------------|---------------------|
|
|
120
|
+
| docx | Microsoft Word | mformat-ext | 0.2 |
|
|
121
|
+
| html | Web page | mformat | 0.2 |
|
|
122
|
+
| md | Markdown | mformat | 0.2 |
|
|
123
|
+
| odt | Open Document Text | mformat-ext | 0.2 |
|
|
124
|
+
|
|
125
|
+
## Test summary
|
|
126
|
+
|
|
127
|
+
* Test result: 916 passed in 10s
|
|
128
|
+
* No Flake8 warnings.
|
|
129
|
+
* No mypy errors found.
|
|
130
|
+
* 0.2 built and tested using python version: Python 3.14.2
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
README_pypi.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.py
|
|
4
|
+
mformat.egg-info/PKG-INFO
|
|
5
|
+
mformat.egg-info/SOURCES.txt
|
|
6
|
+
mformat.egg-info/dependency_links.txt
|
|
7
|
+
mformat.egg-info/requires.txt
|
|
8
|
+
mformat.egg-info/top_level.txt
|
|
9
|
+
src/mformat/__init__.py
|
|
10
|
+
src/mformat/factory.py
|
|
11
|
+
src/mformat/mformat.py
|
|
12
|
+
src/mformat/mformat_html.py
|
|
13
|
+
src/mformat/mformat_lists_impl.py
|
|
14
|
+
src/mformat/mformat_md.py
|
|
15
|
+
src/mformat/mformat_state.py
|
|
16
|
+
src/mformat/mformat_textbased.py
|
|
17
|
+
src/mformat/py.typed
|
|
18
|
+
src/mformat/reg_pkg_formats.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mformat
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mformat"
|
|
7
|
+
version = "0.2"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Tom Björkholm", email="klausuler_linnet0q@icloud.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "Uniform way to write simple text to different file formats"
|
|
12
|
+
readme = "README_pypi.md"
|
|
13
|
+
requires-python = ">=3.12"
|
|
14
|
+
license = "MIT"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dynamic = ["dependencies"]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
"Source code" = "https://bitbucket.org/tom-bjorkholm/mformat"
|
mformat-0.2/setup.cfg
ADDED
mformat-0.2/setup.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#! /usr/local/bin/python3
|
|
2
|
+
"""Setup file specifying build of .whl."""
|
|
3
|
+
|
|
4
|
+
from setuptools import setup
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name='mformat',
|
|
8
|
+
version='0.2',
|
|
9
|
+
description='Uniform way to write simple text to different file formats',
|
|
10
|
+
author='Tom Björkholm',
|
|
11
|
+
author_email='klausuler_linnet0q@icloud.com',
|
|
12
|
+
python_requires='>=3.12',
|
|
13
|
+
packages=['mformat'],
|
|
14
|
+
package_dir={'mformat': 'src/mformat'},
|
|
15
|
+
package_data={'mformat': ['src/py.typed']},
|
|
16
|
+
install_requires=[ # pylint: disable=duplicate-code
|
|
17
|
+
'pip',
|
|
18
|
+
'setuptools',
|
|
19
|
+
'build',
|
|
20
|
+
'wheel'
|
|
21
|
+
]
|
|
22
|
+
)
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#! /usr/local/bin/python3
|
|
2
|
+
"""Factory class for creating MultiFormat instances."""
|
|
3
|
+
|
|
4
|
+
# Copyright (c) 2025 - 2026 Tom Björkholm
|
|
5
|
+
# MIT License
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
from typing import Optional, TypedDict, Callable
|
|
9
|
+
from mformat.mformat import MultiFormat, FormatterDescriptor
|
|
10
|
+
from mformat.reg_pkg_formats import register_formats_in_pkg
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
_the_factory: Optional['MultiFormatFactory'] = None # pylint: disable=invalid-name # noqa: E501
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class OptArgsDict(TypedDict, total=False):
|
|
17
|
+
"""Optional arguments for the MultiFormat constructor."""
|
|
18
|
+
|
|
19
|
+
file_exists_callback: Optional[Callable[[str], None]]
|
|
20
|
+
lang: Optional[str]
|
|
21
|
+
title: Optional[str]
|
|
22
|
+
css_file: Optional[str]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
type OptArgs = Optional[OptArgsDict]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class MultiFormatFactory:
|
|
29
|
+
"""Factory class for creating instances of MultiFormat subclasses."""
|
|
30
|
+
|
|
31
|
+
def __init__(self) -> None:
|
|
32
|
+
"""Initialize the factory with an empty registry."""
|
|
33
|
+
self._registry: dict[str, type[MultiFormat]] = {}
|
|
34
|
+
self._usage: dict[str, FormatterDescriptor] = {}
|
|
35
|
+
formats: list[type[MultiFormat]] = register_formats_in_pkg()
|
|
36
|
+
for format_class in formats:
|
|
37
|
+
self.i_register(format_class)
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def i_get_factory() -> 'MultiFormatFactory':
|
|
41
|
+
"""Internally get the factory instance."""
|
|
42
|
+
global _the_factory # pylint: disable=global-statement # noqa: E501
|
|
43
|
+
if _the_factory is None:
|
|
44
|
+
_the_factory = MultiFormatFactory()
|
|
45
|
+
return _the_factory
|
|
46
|
+
|
|
47
|
+
@staticmethod
|
|
48
|
+
def register(format_class: type[MultiFormat]) -> None:
|
|
49
|
+
"""Register a MultiFormat subclass with the factory."""
|
|
50
|
+
factory = MultiFormatFactory.i_get_factory()
|
|
51
|
+
factory.i_register(format_class=format_class)
|
|
52
|
+
|
|
53
|
+
def i_register(self, format_class: type[MultiFormat]) -> None:
|
|
54
|
+
"""Internally register a MultiFormat subclass with the factory."""
|
|
55
|
+
if not issubclass(format_class, MultiFormat):
|
|
56
|
+
err = f'{format_class.__name__} must be a subclass of MultiFormat'
|
|
57
|
+
raise ValueError(err)
|
|
58
|
+
desc: FormatterDescriptor = format_class.get_arg_desciption()
|
|
59
|
+
self._registry[desc.name] = format_class
|
|
60
|
+
self._usage[desc.name] = desc
|
|
61
|
+
|
|
62
|
+
@staticmethod
|
|
63
|
+
def create(format_name: str, file_name: str,
|
|
64
|
+
url_as_text: bool = False,
|
|
65
|
+
args: OptArgs = None) -> MultiFormat:
|
|
66
|
+
"""Create an instance of a registered MultiFormat subclass.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
format_name: The name identifier of the format class to create.
|
|
70
|
+
file_name: The file path to pass to the MultiFormat constructor.
|
|
71
|
+
url_as_text: Format URLs as text not clickable URLs.
|
|
72
|
+
args: additional arguments to pass to the MultiFormat constructor.
|
|
73
|
+
Returns:
|
|
74
|
+
An instance of the requested MultiFormat subclass.
|
|
75
|
+
Intended to be used as context manager, using a with statement.
|
|
76
|
+
Raises:
|
|
77
|
+
ValueError: If the format_name is not registered.
|
|
78
|
+
"""
|
|
79
|
+
factory = MultiFormatFactory.i_get_factory()
|
|
80
|
+
return factory.i_create(format_name=format_name,
|
|
81
|
+
file_name=file_name,
|
|
82
|
+
url_as_text=url_as_text,
|
|
83
|
+
args=args)
|
|
84
|
+
|
|
85
|
+
def i_create(self, format_name: str, file_name: str,
|
|
86
|
+
url_as_text: bool = False,
|
|
87
|
+
args: OptArgs = None) -> MultiFormat:
|
|
88
|
+
"""Internally create an instance of a registered subclass."""
|
|
89
|
+
if format_name not in self._registry:
|
|
90
|
+
raise ValueError(
|
|
91
|
+
f'Format "{format_name}" is not registered. ' +
|
|
92
|
+
'Available formats: ' +
|
|
93
|
+
f'{", ".join(sorted(list(self._registry.keys())))}'
|
|
94
|
+
)
|
|
95
|
+
format_class = self._registry[format_name]
|
|
96
|
+
if args is None:
|
|
97
|
+
return format_class(file_name=file_name, url_as_text=url_as_text)
|
|
98
|
+
assert args is not None
|
|
99
|
+
return format_class(file_name=file_name, # type: ignore[misc]
|
|
100
|
+
url_as_text=url_as_text, **args)
|
|
101
|
+
# mypy cannot see which MultiFormat subclass is being created, so it
|
|
102
|
+
# cannot know which arguments are valid.
|
|
103
|
+
|
|
104
|
+
@staticmethod
|
|
105
|
+
def get_registered_formats() -> list[str]:
|
|
106
|
+
"""Get a list of all registered format names.
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
A list of registered format name strings.
|
|
110
|
+
"""
|
|
111
|
+
factory = MultiFormatFactory.i_get_factory()
|
|
112
|
+
return factory.i_get_registered_formats()
|
|
113
|
+
|
|
114
|
+
def i_get_registered_formats(self) -> list[str]:
|
|
115
|
+
"""Internally get a list of registered format names."""
|
|
116
|
+
return sorted(list(self._registry.keys()))
|
|
117
|
+
|
|
118
|
+
@staticmethod
|
|
119
|
+
def get_usage(format_name: str) -> FormatterDescriptor:
|
|
120
|
+
"""Get the usage information for a registered format."""
|
|
121
|
+
factory = MultiFormatFactory.i_get_factory()
|
|
122
|
+
return factory.i_get_usage(format_name=format_name)
|
|
123
|
+
|
|
124
|
+
def i_get_usage(self, format_name: str) -> FormatterDescriptor:
|
|
125
|
+
"""Internally get the usage information for a registered format."""
|
|
126
|
+
if format_name not in self._usage:
|
|
127
|
+
raise ValueError(
|
|
128
|
+
f'Format "{format_name}" is not registered. ' +
|
|
129
|
+
'Available formats: ' +
|
|
130
|
+
f'{", ".join(sorted(list(self._registry.keys())))}'
|
|
131
|
+
)
|
|
132
|
+
return self._usage[format_name]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def create_mf(format_name: str, file_name: str,
|
|
136
|
+
url_as_text: bool = False,
|
|
137
|
+
args: OptArgs = None) -> MultiFormat:
|
|
138
|
+
"""Create an instance of a registered MultiFormat subclass.
|
|
139
|
+
|
|
140
|
+
Intended to be used as context manager, using a with statement.
|
|
141
|
+
This is a shortcut for MultiFormatFactory.create().
|
|
142
|
+
Args:
|
|
143
|
+
format_name: The name identifier of the format class to create.
|
|
144
|
+
file_name: The file path to pass to the MultiFormat constructor.
|
|
145
|
+
url_as_text: Format URLs as text not clickable URLs.
|
|
146
|
+
args: additional arguments to pass to the MultiFormat constructor.
|
|
147
|
+
Returns:
|
|
148
|
+
An instance of the requested MultiFormat subclass.
|
|
149
|
+
Raises:
|
|
150
|
+
ValueError: If the format_name is not registered.
|
|
151
|
+
"""
|
|
152
|
+
return MultiFormatFactory.create(format_name=format_name,
|
|
153
|
+
file_name=file_name,
|
|
154
|
+
url_as_text=url_as_text,
|
|
155
|
+
args=args)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def list_registered_mf() -> list[str]:
|
|
159
|
+
"""Get a list of all registered format names.
|
|
160
|
+
|
|
161
|
+
This is a shortcut for MultiFormatFactory.get_registered_formats().
|
|
162
|
+
Returns:
|
|
163
|
+
A list of registered format name strings.
|
|
164
|
+
"""
|
|
165
|
+
return MultiFormatFactory.get_registered_formats()
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def usage_mf(format_name: str) -> FormatterDescriptor:
|
|
169
|
+
"""Get the usage information for a registered format.
|
|
170
|
+
|
|
171
|
+
This is a shortcut for MultiFormatFactory.get_usage().
|
|
172
|
+
"""
|
|
173
|
+
return MultiFormatFactory.get_usage(format_name=format_name)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def register_mf(format_class: type[MultiFormat]) -> None:
|
|
177
|
+
"""Register a MultiFormat subclass with the factory.
|
|
178
|
+
|
|
179
|
+
This is a shortcut for MultiFormatFactory.register().
|
|
180
|
+
Args:
|
|
181
|
+
format_class: The MultiFormat subclass to register.
|
|
182
|
+
Raises:
|
|
183
|
+
ValueError: If the format_class is not a subclass of MultiFormat.
|
|
184
|
+
"""
|
|
185
|
+
MultiFormatFactory.register(format_class=format_class)
|