Skip to main content

Convert markdown inside Docx to docx styles

Project description

MarkDownToDocxStyle

Convert Markdown inside Office Word documents

Installation

pip install markdowntodocx

Usage

to convert an existing Docx file:

see examples/example.py

from markdowntodocx.markdownconverter import convertMarkdownInFile

convertMarkdownInFile("/mypath/to/document.docx", "output_path.docx", {"Code Car":"CodeStyle"})

Styles and considerations

You have to define styles in you word document in order to use Markdown **Headers/titles**, **Hyperlinks**, **Code formatting**, **Arrays**, **Unordered List**.

This styles are either standard markdown or come from extended markdown : https://www.markdownguide.org/extended-syntax/

  • Emphasis (italic) *Text* or _Text_: converts to word italic

  • Strong Emphasis (Bold) **Text** or __Text__: converts to word bold

  • Strike through (Strike) ~~Strike~~ : converts to word strike through style

  • Highlight (==highlight==) `==Highlight==' : converts to word Yellow highlight.

  • Header # MarkdownHeader1 to ###### MarkdownHeader6:

    • Must be in alone in a paragraph. IF NOT, the rest will be erased.
    • It will use the document style named "Header" by default.
    • You can specify another style by giving the style dictionnary as last arg for both functions.
    • E.g : res, msg = convertMarkdownInFile("examples/in_document.docx", "examples/out_document.docx", {"Header":"style_name"})
  • (EXTENDED SYNTAX FOR WORD) Change font color <color:FF0000> this text will be very red because the color is in RGB format</color> or <span style="color: rgb(230, 0, 0);> REd colored text </span>

  • Inline Code `Text` (my code):

    • It will use the document style named "Code" (Caracter format) by default.
    • You can specify another style by giving the style dictionnary as last arg for both functions.
    • E.g : markdownToWordInFile("/mypath/to/document.docx", "output_path.docx", {"Code Car":"my_inline_code_style"})
  • Code Block ` ` `T e x t` ` `

my code
* It will use the document style named "Code" by default. 
* You can specify another style by giving the style dictionnary as last arg for both functions. 
* E.g : `markdownToWordInFile("/mypath/to/document.docx", "output_path.docx", {"Code":"my_block_code_style"})`
  • Insert Remote Image ![Image name](http://link.do.web/myimage.png):

    • It will download the image from the hyperlink and insert the picture with a width of 18cm
  • Insert Local Image ![image name](file:///home/myuser/images/test.png)

    • It will read images extensioned file and insert them as remote images
  • Hyperlink [google](https://www.google.fr) : Makes it a Word hyperlink google

    • Will also attempt to convert any valid http hyperlink to word : http://www.google.fr -> http://www.google.fr
    • If the link does not start with http, it will be treated as an internal link to a bookmark
  • (EXTENDED SYNTAX FOR WORD) Bookmark ``this will be bookmared with name bookmark1{#bookmark1}

    • You may hyperlink to it : [url text to display]{bookmark1}
  • Footnotes (BETA) :

    • Inline foot notes : this is a conundrum^[https://fr.wiktionary.org/wiki/conundrum]
    • External foot notes : ``` This paragraph will have a footnote[^1] And this paragraph will have another[^2] [^1]: This is a footnote with markdown as well bold And it can have many lines if they are indented. [^2]: This is the second footnote
    
    
  • Array to wordlist: (must be alone in a paragraph otherwise the rest of the paragraph is deleted)

|Column1|column2|Column3|
|-------|-------|-------|
|line|line|line|

-->

Column1 column2 Column3
line line line
* Cells created will use the document style named "Cell" by default. 
* You can specify another style by giving the style dictionnary as last arg for both functions. 
* E.g : `markdownToWordInFile("/mypath/to/document.docx", "output_path.docx", {"Cell":"my_cell_style"})`
  • Unordered List : (- my list or * my list or + my list) :
    • Must be in alone in a paragraph. IF NOT, the rest of the paragraph will be erased.
    • It will use the document style named "Header" by default.
    • You can specify another style by giving the style dictionnary as last arg for both functions.
    • E.g : markdownToWordInFile("/mypath/to/document.docx", "output_path.docx", {"BulletList":"my_bullet_style"})

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

markdowntodocx-0.1.6.4.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

markdowntodocx-0.1.6.4-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file markdowntodocx-0.1.6.4.tar.gz.

File metadata

  • Download URL: markdowntodocx-0.1.6.4.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for markdowntodocx-0.1.6.4.tar.gz
Algorithm Hash digest
SHA256 e82ea7632fd4764839acab06166baf12e514d5bdfe40b0a8eb973872c72d4399
MD5 b2858a077c5ce04a245bc7ce80d0b931
BLAKE2b-256 86687405b1b22e3da3b857d85002bd5b42a95d5a35810b1ee15abc3d038c7cf0

See more details on using hashes here.

File details

Details for the file markdowntodocx-0.1.6.4-py3-none-any.whl.

File metadata

File hashes

Hashes for markdowntodocx-0.1.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 da2f962012465c6bc96252747ca384aad90e1a89df218a26660d9536bbb79b68
MD5 6f3d4f32359c83570b80ef47a009e261
BLAKE2b-256 468061ac6e05d7182547fed021c6ef2800283d9a3a795fa4846ff63206524727

See more details on using hashes here.

Supported by

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