didix21 / mdutils Goto Github PK
View Code? Open in Web Editor NEWPython package contains a set of basic tools that can help to create a markdown file.
Home Page: https://pypi.org/project/mdutils
License: MIT License
Python package contains a set of basic tools that can help to create a markdown file.
Home Page: https://pypi.org/project/mdutils
License: MIT License
Tables created without using text_align, should use ---
as a default, instead of :---:
. This gives more support for version of markdown that do not use text align
pip reports the following warning on install
DEPRECATION: mdutils is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Hi,
after seeing your project a while back, I was inspired to expand on it a bit using mkdocs. It is still beta and some functionality missing/not stable, but would love any feedback you have.
https://github.com/hhoeflin/mkreports
Just opened an issue as I don't have another way to contact!
Add a class image which has to insert them in a markdown file.
Implement reference-style method. References has to be added at the end of a file.
The new_line method has to start with ' \n' and with the text added by the user.
The TextUtils.text_color method adds an extra space at the start of line, which disables bullets in lines needed.
Create a new class call Link that can implement inline-style link ![title](link)
Adding a long link in the markdown file will not work as the link will be splitted at a certain length of characters to break the line into the next one.
Steps to reproduce the behavior: I added a very long link line in the document like this one to experience this error:
md_file.new_line(md_file.new_inline_link(link="https://www.rezeptwelt.de/saucendipsbrotaufstriche-rezepte/bbq-sauce-aus-finessen-32015/yqmvpwuf-77b3e-450897-cfcd2-84c8tcgw", text="rezeptwelt.de/saucendipsbrotaufstriche-rezepte/bbq-sauce-aus-finessen-32015/yqmvpwuf-77b3e-450897-cfcd2-84c8tcgw", bold_italics_code='i'))
Expected behavior
I would expect to have a proper link displayed however the link is not working as the output in the markdown file looks like this with the unwanted line break:
[*rezeptwelt.de/saucendipsbrotaufstriche-rezepte/bbq-sauce-aus-
finessen-32015/yqmvpwuf-77b3e-450897-cfcd2-84c8tcgw*](https://www.rezeptwelt.de/saucendipsbrotaufstriche-rezepte/bbq-
sauce-aus-finessen-32015/yqmvpwuf-77b3e-450897-cfcd2-84c8tcgw)
Further information
Would be great if this could be fixed as this is I guess some sort of formatting issue which breaks fully working links.
Describe the bug
A clear and concise description of what the bug is.
When using MarkDown with name set to 'foobar-cmd', then the .md extension is not added.
It looks like a regression introduced in 121cfcb, see
if name:
self.file_name = name if 'md' in name else name + '.md'
To Reproduce
Any file name with the string 'md' can be used, and the output file will be missing the .md extension.
Expected behavior
The .md extension should be added.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
I have installed the mdutils on Python 3.5 with pip install.
On importing the module I get the following error:
Traceback (most recent call last):
File "C:\Users\CClaus\projecten\Studytube\navisworks_manage.py", line 1, in <module>
from mdutils import *
File "C:\Python35\lib\site-packages\mdutils\__init__.py", line 2, in <module>
from mdutils.mdutils import MdUtils
File "C:\Python35\lib\site-packages\mdutils\mdutils.py", line 21, in <module>
import mdutils.tools.Table
File "C:\Python35\lib\site-packages\mdutils\tools\__init__.py", line 4, in <module>
from .MDList import MDList
File "C:\Python35\lib\site-packages\mdutils\tools\MDList.py", line 28
md_list += self._add_new_item(item, f "{n_marker}")
^
SyntaxError: invalid syntax
Currently, new_table_of_contents
limits the header depth to 2. It may be useful to allow creation of a table of contents with more than 2 levels. For example, being able to create a ToC with labels:
Contents
========
- 1
- 1.1
- 1.1.1
- 1.1.2
- 2
- 2.1
- 2.1.1
- 2.1.2
- 2.1.2a
etc.
I have worked on a personal fork and believe it would work. I would be willing to make a pull request if this sounds like a useful feature.
Currently as of May 26th, 2020, on version 1.2.1, if I read an existing markdown file in and then generate a table of contents the table of contents is either blank or just contains new headers.
This makes it impossible to source an existing markdown file as a template, build off of it, and create an encompassing table of contents.
The underlying data store for the read markdown appears to be the generated text store with no attempt made to parse the underlying existing structures. One thought I had was perhaps as a compromise to avoid having to fully parse existing markdown, a regular expression could fire after reading existing markdown to at least ensure the TOC is correct?
I'm trying to include matplotlib figures I'm creating in the same script that I'm calling MdUtils with. It appears currently that I have to save those figures to a directory, either in PNG or HTML format, and then call those images back with a path in a MdUtils method:
matplotlib_figure = matplotlib_figure_maker(df)
plt.savefig('/path/to/image.png')
mdFile.new_paragraph(
mdFile.new_inline_image(text='', path='/path/to/image.png')
)
Is there a way to remove this intermediary step?
This package is wonderful, can you add a new feature to adjust the text font size?
Describe the bug
This regular expression generates a DeprecationWarning
on Python 3.11.
To Reproduce
pytest
Expected behavior
No warnings.
Desktop (please complete the following information):
Additional context
I believe the fix should be as simple as removing the backslash. Making this change and running pytest
gives me 107 passing tests and no warnings.
- + re.sub("[^a-z0-9_\-]", "", item.lower().replace(" ", "-"))
+ + re.sub("[^a-z0-9_-]", "", item.lower().replace(" ", "-"))
Hi I am trash at any kind of coding, so this might not even be an error on your part. I have tried all kinds of ways to import mdutils, but I cannot use the create_md_file function properly. I am trying to download text from a website using BeautifulSoup and then saving it as an .md file becuase I have a note taking application that uses .md files exclusively.
I have tried this on both macOS Big Sur 11.2.1 and Microsoft Windows 10, python version 3.7.9
Methods of importing mdutils that have been attempted, but have not worked
from mdutils.mdutils import Mdutils
from mdutils.mdutils import Mdutils, create_md_file
from mdutils import Mdutils, create_md_file
from mdutils.mdutils import *
import Mdutils
import mdutils
Here is the whole code:
import requests
from bs4 import BeautifulSoup
import mdutils
save_path = r'/Users/myname/Documents/foldername/Python/Etymonline'
URL = 'https://www.etymonline.com/search?q=love'
name = URL.split("=")[1]
filename = "".join([save_path,name])
name_markup = '<h1> ' + name + ' </h1>' + '\n'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
content = soup.find(class_='word--C9UPa word_4pc--2SZw8')
full_text = content
file = create_md_file(file_name=filename, title=name)
file.newparagraph(full_text)
file.create_md_file()
Describe the bug
There may be one or more blank lines at the beginning of the file. There is not any functional reason for this and the behavior may cause other unintended side-effects.
To Reproduce
Steps to reproduce the behavior:
[nav] In [18]: md = MdUtils(file_name='Example')
...: md.new_header(level=1, title='Example Header')
Out[18]: '\n# Example Header\n'
Expected behavior
No blank lines at the beginning of the file.
Desktop (please complete the following information):
Additional context
It looks like most every operation that adds new markdown content intentionally has a newline at the beginning of the string. For example:
return "\n" + "#" * level.value + " " + title + header_id + "\n"
Additionally with the create_md_file
function it looks like there may be more that one blank line added if you don't specify anything for title
or have a table of contents:
md_file.rewrite_all_file(
data=self.title
+ self.table_of_contents
+ self.file_data_text
+ self.reference.get_references_as_markdown()
I note this repo hasn’t been updated in over a year.. so not sure if still maintained? Is it possible to write md out to a specific file/path?
I might have a dig through file utils later but I have read the docs and it’s not immediately obvious :)
write
method has to allow to give format to text: bold, italics, color... place text using markers if it is wanted.
Consider migrating to Github actions.
There are various issues with using title levels in a non-standard order which seems to trigger an IndexError.
To Reproduce
Steps to reproduce the behavior:
from mdutils.mdutils import MdUtils
md.new_header(level=3, title=infile)
md = MdUtils(file_name='test.md',title='test')
md.new_header(level=3, title='Level 3 header')
python3.7 mdutilstest.py
Traceback (most recent call last):
File "faraday_markdown_parser.py", line 19, in <module>
md.new_header(level=3, title=host_title)
File "/usr/local/lib/python3.7/dist-packages/mdutils/mdutils.py", line 113, in new_header
self.__add_new_item_table_of_content(level, title)
File "/usr/local/lib/python3.7/dist-packages/mdutils/mdutils.py", line 130, in __add_new_item_table_of_content
curr = curr[-1]
IndexError: list index out of range
Expected behavior
It should be possible to have title levels in arbitrary order/
Desktop (please complete the following information):
Hi, while working on #33 I came across a couple of things that can be improved in my opinion, first of which would be to make sure the code base adheres to the PEP8 convention. The code is clear and well-written but there are some long lines that are hard to read, so limiting line length and adhering to other standarts of PEP8 can make it even better and easier to work with.
I am happy to do it and submit a pull request
Headers in markdown have an anchor which is used for links, format is '#' then the header text converted to lower-case, spaces replaced with hyphens, and special characters removed.
The Table of Contents in MdUtils has a link to the header by converting to lower-case and replacing spaces with hyphens, but does not remove special characters. This means that some of the links in the ToC will not work.
For example I have a header level 2, with text "Unnamed: 41", when I create a ToC the link to this is #unnamed:-41, but should be #unnamed-41, i.e. without the colon. Clicking on the link does not take me to the header section of the document as it should do..
new_paragraph
new_line
write
Describe the bug
I want a sub-header without a header. I get an IndexError instead.
To Reproduce
doc = MdUtils('test.md','test') doc.new_header(level=2, 'test')
Expected behavior
Successfully add the header to the document.
Desktop (please complete the following information):
Problem
I'm including markdown files into LaTeX, which I generate with mdutils.
Before I can do this I have to slice some sections, which I don't want to include. This can only be done by named Id's.
Id's are described in Extended Markdown Sythax
Describe the solution you'd like
Please add an option to add an id to a new header like:
MdUtils.new_header(level=3, title="My Great Heading", id="greatheader")
so it returns:
### My Great Heading {#greatheader}
or so
Hi!
Is it possible to create a break and to shift the following content to a new page?
Would give more control about layout.
Is your feature request related to a problem? Please describe.
Methods of MdUtils
have ambiguous and inconsistant return values, here are some examples:
new_table
, new_reference_image
, write
return lines in md format;new_paragraph
, new_line
return whole file;new_list
and new_checkbox_list
returns nothing;new_inline_*
do not write anything into the file, but just return strings.Describe the solution you'd like
Apply no. 1 for all except new_inline_*
.
Describe alternatives you've considered
I think no. 2 is by mistake, it contradicts the method's docstring. For no. 4, I don't have a good solution on it, maybe just write it explicitly in the documentation. It is a pain to users, I have to read the source code to debug my code...
Additional context
More suggestions:
MdUtils.new_header
's docstring, :return:
is not stated;new_inline_link
could be a static method, just like new_inline_image
(one is MdUtils.new_inline_image(...)
and another is mdfile.new_inline_link
, it's bizzare);]
, )
, simple string concat won't work every time, mentioned in #63;place_text_using_marker
, do you mean replace_text_using_marker
? I don't know about the marker, my editor does not support that, but would it be overkilling to just use str.replace
?wrap_width
, I suggest making its default value to 0
. It is not commonly used, I have to set it whenever I want to call new_line
etc. I was ??? when I saw those \n appeared out of thin air, again, debugging it spent me some time;rows
parameter of new_table
is not that necessary, append blanks at the end of text
list will do.Enhancements:
new_table
, would it be better if we supports dict type text
? Maybe we should discuss this.text_align
of new_table
: Customize each column;marked_with
of new_list
: The nested list(s) must not follow the marker of the root list, what I mean is, an ordered list can have an unordered list in it, just like what I am using right now.checked
of new_checked_list
: In most of the time, we don't check/uncheck the whole list at a time, a list of bools would be way better, or else I have to write the list manually in md (although I am using a lib that is doing markdown lol).Thanks.
Is your feature request related to a problem? Please describe.
Cool library, thanks. I'm putting together a web page from a class hierarchy. Here is a small snippet:
@dataclass
class Md_insert_code():
code: str
language: str = ""
MdUnion = Union[Md_insert_code]
@dataclass
class Expectation():
expected: str
actual: str
details: list[MdUnion]
First objects will be created, Second the md files will be generated. In the example above a class Md_insert_code is going to be used to capture an eventual call to MdUtils.insert_code(code, language).
Describe the solution you'd like
Components of the md document would be represented by object types supplied by the mdutils package.
Create a list class that has to allow to create a list of differents types: numeric, checkbox list, etc.
Github actions should verify that flake8 lint pass
Describe the bug
With "Modify tests to fix flakiness" MarkDownFile.init() has been modified to use os.getcwd() as base directory.
This makes it impossible to specify an absolute path via MdUtils.create_md_file().
To Reproduce
md_file = mdutils.MdUtils(file_name="<absolute file path>", title="My title")
md_file.create_md_file()
leads to
FileNotFoundError: [Errno 2] No such file or directory: '<current directory>/<absolute file path>'
Expected behavior
MD file is created with given absolute file_name.
Desktop (please complete the following information):
Describe the bug
cnverting from a wordpress based html content to markdown the tables are broken
To Reproduce
Based on this page: https://www.urbancode.com/plugindoc/accurev-scm#tab-settings
original HTML part which is converted:
Creates a new component version and imports artifacts from AccuRev.
This step has no input properties.
The plug-in adds these roles automatically to resources. You cannot add these roles
manually.
Name | Type | Description |
---|---|---|
AccuRev Executable Path | String | Full path to the AccuRev executable on the agents file system. |
AccuRev URL | String | Full URL for the AccuRev server. Hostname and port can be identified by running the `accurev info` command locally. |
Depot | String | Specify a Depot to retrieve artifacts from. |
Excludes | String | Specify a list of files to exclude during artifact import. |
Import Issues | Boolean | Select to import latest Issue change set artifacts on automatic import. Artifacts will still be retrieved if the Issue number is specified on manual import. Only valid for a non-Workspace Stream. |
Import Promote Transactions | Boolean | Select to import latest Promote Transaction artifacts on automatic import. Artifacts will still be retrieved if the Transaction number is specified on manual import. Only valid for a non-Workspace Stream. |
Import Snapshots | Boolean | Select to import latest Snapshot artifacts on automatic import. Artifacts will still be retrieved if the Snapshot name is specified on manual import. Only valid for a non-Workspace Stream. |
Includes | String | Specify a list of files to include during artifact import. |
Password | Password | Specify the password of the user with permissions to access the AccuRev Depot and Stream. |
Preserve Execute Permissions | Boolean | Select to save file execute permissions with files. |
Stream | String | Specify a Stream or Workspace to retrieve artifacts from. If empty, the Depot name will be used. If a Workspace is specified, the checkboxes and manual import values for Promote Transactions, Issues, and Snapshot will be ignored. A version will be created based on the runtime timestamp and file contents of the Workspace. |
Username | String | Specify a user with permissions to access the AccuRev Depot and Stream. |
Name | Type | Description |
---|---|---|
Issue Numbers | String | Specify a Issue Number to import. Only valid for a non-Workspace Stream. Separate multiple Issue Numbers with commas. Example: 5, 16, 27 |
Stream Snapshots | String | Specify a Stream Snapshot to import. Only valid for a non-Workspace Stream. Separate multiple Snapshots with a comma. Example: snap-stream1, snap-stream2 |
Transaction Numbers | String | Specify a Promote Transaction Number to import. Only valid for a non-Workspace Stream. Separate multiple Transaction Numbers with commas. Example: 80, 120, 184 |
Version Name Tag | String | Specify a tag to append to the versions name. |
I pre-process the html and remove the following:
Properties for the AccuRevComponentProperties roleCreates a new component version and imports artifacts from AccuRev.
This step has no input properties.
The plug-in adds
these roles automatically to resources. You cannot add these roles manually.
AccuRevComponentProperties
*
AccuRevImportProperties
| Name | Type |
Description |
| --- | --- | --- |
| AccuRev Executable Path | String | Full path to the AccuRev executable on the agents
file system. |
| AccuRev URL | String | Full URL for the AccuRev server. Hostname and port can be identified by running
the accurev info
command locally. |
| Depot | String | Specify a Depot to retrieve artifacts from. |
| Excludes |
String | Specify a list of files to exclude during artifact import. |
| Import Issues | Boolean | Select to import
latest Issue change set artifacts on automatic import. Artifacts will still be retrieved if the Issue number is
specified on manual import. Only valid for a non-Workspace Stream. |
| Import Promote Transactions | Boolean | Select to
import latest Promote Transaction artifacts on automatic import. Artifacts will still be retrieved if the Transaction
number is specified on manual import. Only valid for a non-Workspace Stream. |
| Import Snapshots | Boolean | Select to
import latest Snapshot artifacts on automatic import. Artifacts will still be retrieved if the Snapshot name is
specified on manual import. Only valid for a non-Workspace Stream. |
| Includes | String | Specify a list of files to
include during artifact import. |
| Password | Password | Specify the password of the user with permissions to access
the AccuRev Depot and Stream. |
| Preserve Execute Permissions | Boolean | Select to save file execute permissions with
files. |
| Stream | String | Specify a Stream or Workspace to retrieve artifacts from. If empty, the Depot name will be
used. If a Workspace is specified, the checkboxes and manual import values for Promote Transactions, Issues, and
Snapshot will be ignored. A version will be created based on the runtime timestamp and file contents of the Workspace. |
| Username | String | Specify a user with permissions to access the AccuRev Depot and Stream. |
AccuRevImportProperties
Name | Type | Description |
---|---|---|
Issue Numbers | String | Specify a Issue |
Number to import. Only valid for a non-Workspace Stream. Separate multiple Issue Numbers with commas. Example: 5, 16, | ||
27 | ||
Stream Snapshots | String | Specify a Stream Snapshot to import. Only valid for a non-Workspace Stream. Separate |
multiple Snapshots with a comma. Example: snap-stream1, snap-stream2 | ||
Transaction Numbers | String | Specify a |
Promote Transaction Number to import. Only valid for a non-Workspace Stream. Separate multiple Transaction Numbers with | ||
commas. Example: 80, 120, 184 | ||
Version Name Tag | String | Specify a tag to append to the versions name. |
Is your feature request related to a problem? Please describe.
I'm creating a markdown file and moving it to a specific directory. Looking at the README, the filename
param seems to just be a name for the generated file, and would need to be manually moved after creation. Looking deeper at the MarkdownFile
class, the filename is actually the path where the file will be created. This should be stated clearly in the README.
Describe the solution you'd like
A clear and concise description of what you want to happen.
Update documentation to clarify the usage of the filename
param.
Is your feature request related to a problem? Please describe.
I want to increase font size for my paragraph, I don't see any option available. I saw an option available to change the font color, I think font-size is the similar option to increase font.
Describe the solution you'd like
https://github.com/didix21/mdutils/blob/master/mdutils/mdutils.py#L241
from mdutils.mdutils import MdUtils
md_file = MdUtils(file_name='Example_Markdown',title='Markdown File Example')
md_file.new_paragraph(f"Duration:", font_size=16)
Describe the bug
Cannot create a file with a single header at level 2 (without having a level 1)
To Reproduce
from mdutils.mdutils import MdUtils
mdFile = MdUtils(file_name='example.md',title='Markdown File Example')
mdFile.new_header(level=2, title='Atx Header 2')
mdFile.create_md_file()
Expected behavior
Markdown file with a level 2 header
Desktop (please complete the following information):
Additional context
Traceback:
Traceback (most recent call last):
File "test-mdutils.py", line 4, in <module>
mdFile.new_header(level=2, title='Atx Header 2')
File "/opt/anaconda3/lib/python3.8/site-packages/mdutils/mdutils.py", line 113, in new_header
self.__add_new_item_table_of_content(level, title)
File "/opt/anaconda3/lib/python3.8/site-packages/mdutils/mdutils.py", line 130, in __add_new_item_table_of_content
curr = curr[-1]
IndexError: list index out of range
Currently there are some IDE files that are included in the tree.
Is your feature request related to a problem? Please describe.
Feature Request/Query.
Describe the solution you'd like
I am writing an automation to generate report using mdutils. To make the report suit the theme, I was looking for an option to have an option to set colour for the titile
MdUtils(file_name='Report', title='XYZ Report', color='purple')
Also want to know if there is an option to give hexcode RGB values as color in
mdFile.write('Text color', color=rgbhexcode)
Currently, create_md_file()
only allows us to write to the current folder where the python script is in.
Is there anyway to add additional functionality by allowing the user to pass in a path in maybe another folder? And have the output directed to that path instead.
Thx.
Implement a new action for performing a new release
Describe the bug
Can't create list of numeric items. Discovered when trying to list versions of software
To Reproduce
>>> from mdutils.mdutils import MdUtils
>>> mdf = MdUtils('foo.md', title='Foo')
>>> mdf.new_list(['foo', 'bar'])
>>> mdf.new_list(['1.2', '1.3'])
>>> mdf.create_md_file()
results:
Foo
===
- foo
- bar
1.2
1.3
Expected behavior
Foo
===
- foo
- bar
- 1.2
- 1.3
Desktop (please complete the following information):
it seems there is no api to add pic to md files?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.