A package where users can convert markdown syntax into their very own google docs file
Project description
MarkGDoc: Converting Markdown to Google Docs
pip install markgdoc
Don't you just love to use Markdown to take your notes or store information? But what if you want to convert those notes into a Google Docs File?
As a programmer and dealing with Google Docs API requests, it can seem frustrating to figure out how to structure your request for inputting content in a Google Docs file properly without errors.
In this Python Package, you can now convert your markdown files into your very own Google Docs file with ease! We have streamlined every Markdown Syntax to match a properly formatted Google Docs API Request, saving you the nitty gritty time of worrying on how to structure a request, ensuring everything is now automated!
Key Functions
convert_to_google_docs():
This is the main function to convert your markdown content into your very own google docs file. This will output your very own Google Docs URL to your google docs file:
google_docs_url = convert_to_google_docs(content_markdown, document_title, docs_service, credentials_file, scopes, debug=False)
You need to ensure to pass:
-
content_markdown
: A string of your markdown content -
document_title
: A string of the title of your google docs -
docs_service
: Your google docs build service -
credentials_file
: The path to your credentials.json file -
scopes
: Scopes to define the access for the application.- You can declare this constant as a default but feel free to add more:
SCOPES = [ "https://www.googleapis.com/auth/documents", "https://www.googleapis.com/auth/drive", ]
To learn how to create your own google docs build service and how to setup your own credentials file from Google Cloud Platform, please checkout our tutorial here:
Guide on How to Setup Your Google Cloud Console Project
create_empty_google_doc():
You can even use the create_empty_google_doc
function if required to help you quickly create an empty google doc:
doc_id, doc_url = create_empty_google_doc(document_title, credentials_file, scopes)
You need to ensure to pass:
-
document_title
: A string of the title of your google docs -
credentials_file
: The path to your credentials.json file -
scopes
: Scopes to define the access for the application.
This will output the google docs id as well as the overall complete google docs URL.
Specific Google Doc Request Functions:
In our package we have dissolved your long and complex google docs requests into single line functions catered for every common markdown syntax used:
get_header_request(text, level, index, debug=False)
This function will return a google docs request for any header. All you need to do is specify the text you want, the header level (which heading size), and the index at which you would like to place the header in the google docs.
Example:
header_request = markgdoc.get_header_request("This is a large heading", 1, 1)
get_paragraph_request(text, index, debug=False)
This function will return a google docs request for paragraphs, basically any regular body of text. All you need to do is specify the text you want, and the index at which you would like to place the paragraph in the google docs.
Example:
paragraph_request = markgdoc.get_paragraph_request("This is a paragraph", 20)
get_horizontal_line_request(index, debug=False)
This function will return a google docs request for horizontal line. All you need to do is insert the index at which you would like to place it.
Example:
horizontal_line_request = markgdoc.get_horizontal_line_request(10)
get_style_request(text, style, index, debug=False)
This function will return a google docs request for styling a section of your already inserted text. This includes styling marks such as: bolding, italics, strikethrough. You need to specify the text you want to style (text should already be inserted through another request), styling method, index at where the text was inserted in the doc.
Example:
style_request = markgdoc.get_style_request("This is a styled text", bold, 23)
get_hyperlink_request(text, url, index, debug=False)
This function will return a google docs request for hyperlinks. You need to specify the text (name of the link you want to click), url of the link, index you want to place the link.
Example:
Link structure: [Google](https://www.google.com/)
link_request = markgdoc.get_hyperlink_request("Google", "https://www.google.com/", 145)
get_unordered_list_request(text, index, debug=False)
This function will return a google docs request for a single bullet point line. You need to spcify the text of the bullet point line and the index you want to place it.
- Note 1: This is only one line of the bullet point. To add several bullet points from an overall list, you would probably need to do a for loop with this function.
Example:
ul_request = markgdoc.get_unordered_list("This is a bullet point", 33)
get_ordered_list_request(text, index, debug=False)
This function will return a google docs request for a single numbered line. You need to spcify the text of the bullet point line and the index you want to place it.
- Note 1: This is only one line of the numbered line. To add several numberlines from into an overall numbered line list, you would probably need to do a for loop with this function.
- Note 2: The numbered line list should be together with no gaps (empty lines) between the numbered lines to avoid them from being identified as new numbered lists.
Example:
ol_request = markgdoc.get_ordered_list("This is a numbered line", 40)
get_empty_table_request(rows, cols, index, debug=False)
This function will return a google docs request to create an empty table on the google docs. You need to specify the number of rows and columns and the index to place it on.
Example:
table_request = markgdoc.get_empty_table_request(2, 3, 39)
get_table_content_request(table_data, index, debug=False):
This function will return a google docs request to insert your table content into an empty table in the google docs. You need to specify a 2D list vector of your table data in the form of table_data = [rows][column]
as well as the index to place it on.
Example:
table_content_request = markgdoc.get_table_content_request(table_data, 255)
Running the main.py file
Important Note:
Before you go ahead and run your this program, please make sure that:
-
You have setup a Google Cloud Project with Google Docs API enabled.
-
You have a valid and active
credentials.json
key for your Google Cloud Console Project.
The above steps are required for you to run this main as these are the steps needed to connect to the API and create a Google Docs through Python.
If you don't have any of these setup, checkout our documentation on how to setup a a Google Cloud Console Project: Guide on How to Setup Your Google Cloud Console Project
Once properly setup, you can run the command:
python -m markgdoc
Additionally you can also run the program as the following for Debugging Print Statements of all the requests to show in your terminal
python -m markgdoc --debug
Contributing
Contributions are definitely accepted and we are open to growing this package. By participating in this project, you agree to abide by the code of conduct.
Setting Up the Development Environment
-
Clone the repository:
Use the following command to clone the repository:
git clone https://github.com/awesomeadi00/MarkGDoc.git
-
Navigate to the project directory:
Change into the cloned directory:
cd markgdoc
-
Install pipenv:
First make sure you have pipenv installed
pip install pipenv
-
Locking Pipfile if Pipfile.lock not present:
If the Pipfile.lock file is not present or updated, use the following command to lock the pipfile
pipenv lock
-
Install Dependencies:
In order to install the dependencies, first create an empty folder and rename it as
.venv
. After this step is done, then you can install your dependencies through the following command:pipenv install
Note that
pipenv install --dev
install dev-packages as well. -
Activate the virtual environment:
Enter the virtual environment using:
pipenv shell
-
Make your changes:
Make the changes you want to contribute to the project.
-
Run tests:
Ensure your changes pass all tests using pytest:
pipenv run python -m pytest
-
Submit a Pull Request:
After making your changes and verifying the functionality, commit your changes and push your branch to GitHub. Then, submit a pull request to the main branch for review.
Reporting Bugs
Report bugs at Issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Submitting Enhancements
If you're proposing enhancements or new features:
- Open a new issue here, describing the enhancement.
- Include the 'enhancement' label on the issue.
Thank you for your interest!
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
Built Distribution
File details
Details for the file markgdoc-1.0.1.tar.gz
.
File metadata
- Download URL: markgdoc-1.0.1.tar.gz
- Upload date:
- Size: 57.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f628e6bf94c4a5b60a8c68cdc021950fd802ad883e75fc9d07fd37cbf839aaa |
|
MD5 | 54c605015333462993e78934512e634e |
|
BLAKE2b-256 | 9ce35c3957f8cb7163e5ed68e8bf5189c4e180f8a74f24e95c05d0b5fd0d51c1 |
File details
Details for the file markgdoc-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: markgdoc-1.0.1-py3-none-any.whl
- Upload date:
- Size: 40.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a56170b14c646c18701642a9c5c10a187c117afe64dafe31f8ff1721d65ffdd |
|
MD5 | 72c2cab6c8aaa52134e075698b727b41 |
|
BLAKE2b-256 | e4393a966898e4ac1535bfb71163f2fe5af912f462e831439cb86c20191480e1 |