API Reference
High-level API
Convert Markdown text to LinkedIn-compatible Unicode plain text.
Bold (**text** / __text__), italic (*text* / _text_), and
bold-italic (***text*** / ___text___) markers are replaced with
their Unicode Mathematical Sans-Serif equivalents so that the styling is
preserved when pasting into LinkedIn or other plain-text rich editors.
The following Markdown constructs are also handled:
- Headers — ATX (
#) and setext styles; H1 gets a━border. - Code spans — backticks stripped; content converted to Unicode Monospace by default (see monospace_code).
- Fenced code blocks — fences stripped and content converted to Unicode Monospace by default (see monospace_code).
- Links — stripped to display text by default (see preserve_links).
- Images — replaced by alt text.
- Bullet lists —
-/*/+→•/‣(nested). - Blockquotes — leading
>stripped. - HTML spans — unwrapped, inner text kept.
- HTML entities — decoded to literal characters.
- Backslash escapes — resolved (
\*→*). - Windows line endings — normalised to
\n.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The Markdown source string. |
required |
preserve_links
|
bool
|
When |
False
|
monospace_code
|
bool
|
When |
True
|
Returns:
| Type | Description |
|---|---|
str
|
A plain-text string suitable for pasting into LinkedIn. |
Examples:
Source code in src/md2linkedin/_converter.py
Convert a Markdown file and write the result to a .txt file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
str | Path
|
Path to the Markdown source file ( |
required |
output_path
|
str | Path | None
|
Destination path for the converted output. Defaults to
the input path with the extension replaced by
|
None
|
preserve_links
|
bool
|
Passed through to :func: |
False
|
monospace_code
|
bool
|
Passed through to :func: |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
The resolved path of the written output file. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If input_path does not exist. |
Examples:
>>> from pathlib import Path
>>> import tempfile, os
>>> with tempfile.NamedTemporaryFile(mode="w", suffix=".md", delete=False) as f:
... _ = f.write("**bold** and *italic*")
... tmp = f.name
>>> out = convert_file(tmp)
>>> out.read_text(encoding="utf-8")
'𝗯𝗼𝗹𝗱 and 𝘪𝘵𝘢𝘭𝘪𝘤\n'
>>> os.unlink(tmp)
... os.unlink(str(out))
Source code in src/md2linkedin/_converter.py
Unicode Mapping
Apply a Unicode sans-serif style to text.
A convenience dispatcher that routes to the appropriate mapping function based on the requested style. Useful when the style is determined dynamically at runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string to convert. |
required |
style
|
Literal['bold', 'italic', 'bold_italic']
|
One of |
required |
Returns:
| Type | Description |
|---|---|
str
|
A new string with the requested Unicode style applied. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If style is not one of the three accepted values. |
Examples:
Source code in src/md2linkedin/_unicode.py
Convert text to Unicode Mathematical Monospace.
ASCII uppercase letters, lowercase letters, and digits are mapped to their monospace counterparts. All other characters (spaces, punctuation, non-ASCII) pass through unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A new string with ASCII alphanumerics replaced by monospace |
str
|
Unicode equivalents. |
Examples:
Source code in src/md2linkedin/_unicode.py
Convert text to Unicode Mathematical Sans-Serif Bold.
ASCII uppercase letters, lowercase letters, and digits are mapped to their bold sans-serif counterparts. All other characters (spaces, punctuation, non-ASCII) pass through unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A new string with ASCII alphanumerics replaced by bold sans-serif |
str
|
Unicode equivalents. |
Examples:
Source code in src/md2linkedin/_unicode.py
Convert text to Unicode Mathematical Sans-Serif Italic.
ASCII uppercase and lowercase letters are mapped to their italic sans-serif counterparts. Digits and all other characters pass through unchanged (there are no italic digit codepoints in this Unicode block).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A new string with ASCII letters replaced by italic sans-serif |
str
|
Unicode equivalents. |
Examples:
Source code in src/md2linkedin/_unicode.py
Convert text to Unicode Mathematical Sans-Serif Bold Italic.
ASCII uppercase and lowercase letters are mapped to their bold-italic sans-serif counterparts. Digits and all other characters pass through unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A new string with ASCII letters replaced by bold-italic sans-serif |
str
|
Unicode equivalents. |
Examples: