### Install md2linkedin via Package Manager Source: https://www.indrapatil.com/md2linkedin Commands to install the package using pip or uv. ```bash pip install md2linkedin ``` ```bash uv add md2linkedin ``` -------------------------------- ### Convert Markdown using CLI Source: https://www.indrapatil.com/md2linkedin Command-line interface examples for converting files, piping input, and configuring output options. ```bash # Convert a Markdown file (output: post.linkedin.txt) md2linkedin post.md # Specify output path md2linkedin post.md -o linkedin_post.txt # Pipe from stdin echo "**Hello**, *world*!" | md2linkedin # Keep link URLs in the output md2linkedin post.md --preserve-links # Disable monospace code rendering md2linkedin post.md --no-monospace-code ``` -------------------------------- ### Run md2linkedin without installing using uvx Source: https://www.indrapatil.com/md2linkedin/advanced Use uvx to run md2linkedin directly for occasional use. It downloads and caches the package for fast subsequent runs. ```bash # Convert a Markdown file (output: post.linkedin.txt) uvx md2linkedin post.md ``` ```bash # Pipe from stdin echo "**bold** and *italic*" | uvx md2linkedin ``` ```bash # Preserve link syntax uvx md2linkedin --preserve-links post.md ``` ```bash # Explicit output path uvx md2linkedin post.md -o linkedin_post.txt ``` ```bash # Disable monospace code rendering uvx md2linkedin --no-monospace-code post.md ``` -------------------------------- ### Integrate md2linkedin with Pandoc using Python Source: https://www.indrapatil.com/md2linkedin/advanced Use Python's subprocess module to pipe LaTeX content through Pandoc for conversion to Markdown, then process with md2linkedin's convert function. Ensure the 'resume.tex' file exists and is readable. ```python import subprocess from md2linkedin import convert result = subprocess.run( ["pandoc", "--from=latex", "--to=markdown_strict", "--wrap=none"], input=Path("resume.tex").read_text(), capture_output=True, text=True, check=True, ) linkedin_text = convert(result.stdout) ``` -------------------------------- ### Convert Markdown Files Source: https://www.indrapatil.com/md2linkedin/advanced Use convert_file to process Markdown files directly, with optional output path overrides. ```python from md2linkedin import convert_file out = convert_file("post.md") print(f"Written to: {out}") # post.linkedin.txt # Override the output path out = convert_file("post.md", "my_post.txt") ``` -------------------------------- ### md2linkedin CLI Reference Source: https://www.indrapatil.com/md2linkedin/advanced Reference for md2linkedin command-line interface options. Use this to understand available flags for input files, output paths, link preservation, and code rendering. ```bash Usage: md2linkedin [OPTIONS] [INPUT_FILE] Convert Markdown to LinkedIn-friendly Unicode text. Options: -o, --output PATH Output file path. --preserve-links Keep link syntax in output. --no-monospace-code Disable monospace Unicode rendering for code. -V, --version Show the version and exit. -h, --help Show this message and exit. ``` -------------------------------- ### Apply Unicode Styles Directly Source: https://www.indrapatil.com/md2linkedin/advanced Use public mapping functions or dynamic dispatch to apply specific Unicode styles to strings. ```python from md2linkedin import ( to_sans_bold, to_sans_italic, to_sans_bold_italic, to_monospace, apply_style, ) to_sans_bold("Open to Work") # 𝗢𝗽𝗲𝗻 𝘁𝗼 𝗪𝗼𝗿𝗸 to_sans_italic("3 years of exp") # 3 𝘺𝘦𝘢𝘳𝘴 𝘰𝘧 𝘦𝘹𝘱 to_sans_bold_italic("Key insight") # 𝙆𝙚𝙮 𝙞𝙣𝙨𝙞𝙜𝙝𝙩 to_monospace("print('hi')") # 𝚙𝚛𝚒𝚗𝚝('𝚑𝚒') # Dynamic dispatch apply_style("Hiring!", "bold") ``` -------------------------------- ### Configure Monospace Rendering Source: https://www.indrapatil.com/md2linkedin/advanced Control whether code blocks are converted to Unicode monospace or kept as plain text. ```python convert("Use `**bold**` in Markdown") # → Use **𝚋𝚘𝚕𝚍** in Markdown (backticks stripped, letters monospaced, ** kept) convert("```\nprint('hi')\n```") # → 𝚙𝚛𝚒𝚗𝚝('𝚑𝚒') (fences stripped, content monospaced) ``` ```python convert("Use `**bold**` in Markdown", monospace_code=False) # → Use **bold** in Markdown (backticks stripped, content as plain text) convert("```\n**not bold**\n```", monospace_code=False) # → ```\n**not bold**\n``` (fenced block fully preserved) ``` -------------------------------- ### Convert Markdown Strings Source: https://www.indrapatil.com/md2linkedin/advanced Use the convert function to transform Markdown strings into LinkedIn-ready plain text. ```python from md2linkedin import convert result = convert("**Hello**, *world*!") print(result) # 𝗛𝗲𝗹𝗹𝗼, 𝘸𝘰𝘳𝘭𝘥! ``` -------------------------------- ### convert_file Function Source: https://www.indrapatil.com/md2linkedin/reference/converter Converts a Markdown file to a LinkedIn-compatible text file. ```APIDOC ## convert_file ### Description Converts a Markdown file and writes the result to a .txt file. ### Parameters #### Path Parameters - **input_path** (str | Path) - Required - Path to the Markdown source file (.md or any text file). - **output_path** (str | Path | None) - Optional - Destination path for the converted output. Defaults to the input path with the extension replaced by .linkedin.txt. - **preserve_links** (bool) - Optional - Passed through to :func:`convert`. Default: False. - **monospace_code** (bool) - Optional - Passed through to :func:`convert`. Default: True. ### Response #### Success Response - **Path** (Path) - The resolved path of the written output file. ### Errors - **FileNotFoundError** - If input_path does not exist. ``` -------------------------------- ### Apply Unicode Style to Text Source: https://www.indrapatil.com/md2linkedin/reference/converter Routes to the appropriate mapping function based on the requested style. Useful when the style is determined dynamically at runtime. Raises ValueError if the style is not one of the three accepted values. ```python def apply_style(text: str, style: Literal["bold", "italic", "bold_italic"]) -> str: """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. Args: text: The input string to convert. style: One of ``"bold"``, ``"italic"``, or ``"bold_italic"``. Returns: A new string with the requested Unicode style applied. Raises: ValueError: If *style* is not one of the three accepted values. Examples: >>> apply_style("hello", "bold") '𝗵𝗲𝗹𝗹𝗼' >>> apply_style("hello", "italic") '𝘩𝘦𝘭𝘭𝘰' >>> apply_style("hello", "bold_italic") '𝙝𝙚𝙡𝙡𝙤' """ if style == "bold": return to_sans_bold(text) if style == "italic": return to_sans_italic(text) if style == "bold_italic": return to_sans_bold_italic(text) msg = f"Unknown style {style!r}. Expected 'bold', 'italic', or 'bold_italic'." raise ValueError(msg) ``` -------------------------------- ### to_sans_bold Source: https://www.indrapatil.com/md2linkedin/reference/converter Converts ASCII alphanumeric characters to Unicode Mathematical Sans-Serif Bold. ```APIDOC ## FUNCTION to_sans_bold ### Description Converts ASCII uppercase letters, lowercase letters, and digits to their bold sans-serif counterparts. All other characters pass through unchanged. ### Parameters - **text** (str) - Required - The input string to convert. ### Response - **returns** (str) - A new string with ASCII alphanumerics replaced by bold sans-serif Unicode equivalents. ``` -------------------------------- ### Manage Orphaned Markers Source: https://www.indrapatil.com/md2linkedin/advanced The library ignores unmatched Markdown markers to prevent crashes. ```python convert("price: $10 * 3") # → price: $10 * 3 (no crash) convert("under_score alone") # → unchanged ``` -------------------------------- ### Preserve Markdown Links Source: https://www.indrapatil.com/md2linkedin/advanced Enable link preservation to retain Markdown syntax for links instead of stripping them. ```python result = convert("[GitHub](https://github.com)", preserve_links=True) # [GitHub](https://github.com) result = convert_file("post.md", preserve_links=True) ``` -------------------------------- ### Function: convert Source: https://www.indrapatil.com/md2linkedin/reference/converter Converts a Markdown source string into LinkedIn-compatible Unicode plain text, handling bold, italic, headers, lists, and code blocks. ```APIDOC ## convert(text, preserve_links=False, monospace_code=True) ### Description Converts Markdown text to LinkedIn-compatible Unicode plain text. Bold, italic, and bold-italic markers are replaced with Unicode Mathematical Sans-Serif equivalents. ### Parameters #### Request Body - **text** (str) - Required - The Markdown source string. - **preserve_links** (bool) - Optional - When True, link syntax is left unchanged. Default: False. - **monospace_code** (bool) - Optional - When True, code spans and blocks are rendered in Unicode Mathematical Monospace. Default: True. ### Response #### Success Response (200) - **result** (str) - A plain-text string suitable for pasting into LinkedIn. ### Request Example ```python convert("**Hello**, *world*!", preserve_links=False, monospace_code=True) ``` ### Response Example ```text '𝗛𝗲𝗹𝗹𝗼, 𝘸𝘰𝘳𝘭𝘥!\n' ``` ``` -------------------------------- ### Convert text to Sans-Serif Bold Source: https://www.indrapatil.com/md2linkedin/reference/converter Maps ASCII alphanumeric characters to their bold sans-serif Unicode counterparts. Non-ASCII characters and punctuation remain unchanged. ```python def to_sans_bold(text: str) -> str: """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. Args: text: The input string to convert. Returns: A new string with ASCII alphanumerics replaced by bold sans-serif Unicode equivalents. Examples: >>> to_sans_bold("Hello, World! 123") '𝗛𝗲𝗹𝗹𝗼, 𝗪𝗼𝗿𝗹𝗱! 𝟭𝟮𝟯' >>> to_sans_bold("café") '𝗰𝗮𝗳é' >>> to_sans_bold("") '' """ out: list[str] = [] for c in text: if "A" <= c <= "Z": out.append(chr(_SANS_BOLD_UPPER + ord(c) - ord("A"))) elif "a" <= c <= "z": out.append(chr(_SANS_BOLD_LOWER + ord(c) - ord("a"))) elif "0" <= c <= "9": out.append(chr(_SANS_BOLD_DIGIT + ord(c) - ord("0"))) else: out.append(c) return "".join(out) ``` -------------------------------- ### Integrate md2linkedin with Pandoc for LaTeX to Markdown conversion Source: https://www.indrapatil.com/md2linkedin/advanced Pipe LaTeX files through Pandoc to convert them to Markdown before processing with md2linkedin. This is useful for documents originally written in LaTeX. ```bash pandoc --from=latex --to=markdown_strict --wrap=none resume.tex | md2linkedin ``` -------------------------------- ### Handle Nested Formatting Source: https://www.indrapatil.com/md2linkedin/advanced The library processes nested formatting by prioritizing bold-italic markers. ```python convert("***very important***") # → bold-italic Unicode convert("**bold and *italic* inside**") # → bold wrapping italic ``` -------------------------------- ### Convert Markdown File for LinkedIn Source: https://www.indrapatil.com/md2linkedin/reference/converter Use this function to convert a Markdown file to a text file optimized for LinkedIn. It handles file paths, preserves or modifies formatting like links and monospace code, and writes the output to a specified location. ```python 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)) ``` ```python def convert_file( input_path: str | Path, output_path: str | Path | None = None, *, preserve_links: bool = False, monospace_code: bool = True, ) -> Path: """Convert a Markdown file and write the result to a ``.txt`` file. Args: input_path: Path to the Markdown source file (``.md`` or any text file). output_path: Destination path for the converted output. Defaults to the input path with the extension replaced by ``.linkedin.txt``. preserve_links: Passed through to :func:`convert`. monospace_code: Passed through to :func:`convert`. Returns: The resolved path of the written output file. Raises: 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)) """ input_path = Path(input_path) if not input_path.exists(): msg = f"Input file not found: {input_path}" raise FileNotFoundError(msg) if output_path is None: output_path = input_path.with_suffix("").with_suffix(".linkedin.txt") output_path = Path(output_path) md_text = input_path.read_text(encoding="utf-8") result = convert( md_text, preserve_links=preserve_links, monospace_code=monospace_code, ) output_path.write_text(result, encoding="utf-8") return output_path ``` -------------------------------- ### Convert Markdown using Python API Source: https://www.indrapatil.com/md2linkedin Use the convert function to transform a Markdown string into LinkedIn-formatted text. ```python # @pyodide from md2linkedin import convert md = """ # Exciting News I'm thrilled to share that **we just launched** a new product! Key highlights: - **Performance**: *3x faster* than the previous version - **Reliability**: ***zero downtime*** deployments - **Developer UX**: clean, intuitive API Check it out and let me know what you think. """ print(convert(md)) ``` -------------------------------- ### Apply Unicode Style Source: https://www.indrapatil.com/md2linkedin/reference/converter Applies a specified Unicode sans-serif style (bold, italic, or bold-italic) to the input text. This function is useful when the desired style needs to be determined dynamically at runtime. ```APIDOC ## POST /apply_style ### Description Applies a specified Unicode sans-serif style (bold, italic, or bold-italic) to the input text. This function is useful when the desired style needs to be determined dynamically at runtime. ### Method POST ### Endpoint /apply_style ### Parameters #### Request Body - **text** (str) - Required - The input string to convert. - **style** (Literal['bold', 'italic', 'bold_italic']) - Required - One of "bold", "italic", or "bold_italic". ### Request Example ```json { "text": "hello", "style": "bold" } ``` ### Response #### Success Response (200) - **result** (str) - A new string with the requested Unicode style applied. #### Response Example ```json { "result": "𝗵𝗲𝗹𝗹𝗼" } ``` ### Error Handling - **ValueError**: If _style_ is not one of the three accepted values. ``` -------------------------------- ### to_sans_bold_italic Source: https://www.indrapatil.com/md2linkedin/reference/converter Converts ASCII letters to Unicode Mathematical Sans-Serif Bold Italic. ```APIDOC ## FUNCTION to_sans_bold_italic ### Description Maps ASCII uppercase and lowercase letters to their bold-italic sans-serif counterparts. Digits and other characters remain unchanged. ### Parameters - **text** (str) - Required - The input string to convert. ### Response - **returns** (str) - A new string with ASCII letters replaced by bold-italic sans-serif Unicode equivalents. ``` -------------------------------- ### Convert to Sans-Serif Bold Source: https://www.indrapatil.com/md2linkedin/reference/converter Converts 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 pass through unchanged. ```APIDOC ## POST /to_sans_bold ### Description Converts 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. ### Method POST ### Endpoint /to_sans_bold ### Parameters #### Request Body - **text** (str) - Required - The input string to convert. ### Request Example ```json { "text": "Hello, World! 123" } ``` ### Response #### Success Response (200) - **result** (str) - A new string with ASCII alphanumerics replaced by bold sans-serif Unicode equivalents. #### Response Example ```json { "result": "𝗛𝗲𝗹𝗹𝗼, 𝗪𝗼𝗿𝗹𝗱! 𝟭𝟮𝟯" } ``` ``` -------------------------------- ### Handle Emojis and Non-ASCII Source: https://www.indrapatil.com/md2linkedin/advanced Emojis and accented characters are preserved during conversion. ```python from md2linkedin import convert result = convert("**Excited to share** 🎉 *check this out*!") print(result) # 𝗘𝘅𝗰𝗶𝘁𝗲𝗱 𝘁𝗼 𝘀𝗵𝗮𝗿𝗲 🎉 𝘤𝘩𝘦𝘤𝘬 𝘵𝘩𝘪𝘴 𝘰𝘶𝘵! ``` -------------------------------- ### Convert to Monospace Source: https://www.indrapatil.com/md2linkedin/reference/converter Converts text to Unicode Mathematical Monospace. ASCII uppercase letters, lowercase letters, and digits are mapped to their monospace counterparts. All other characters pass through unchanged. ```APIDOC ## POST /to_monospace ### Description Converts 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. ### Method POST ### Endpoint /to_monospace ### Parameters #### Request Body - **text** (str) - Required - The input string to convert. ### Request Example ```json { "text": "Hello, World! 123" } ``` ### Response #### Success Response (200) - **result** (str) - A new string with ASCII alphanumerics replaced by monospace Unicode equivalents. #### Response Example ```json { "result": "𝙷𝚎𝚕𝚕𝚘, 𝚆𝚘𝚛𝚕𝚍! 𝟷𝟸𝟹" } ``` ``` -------------------------------- ### Convert Text to Unicode Sans-Serif Bold Source: https://www.indrapatil.com/md2linkedin/reference/converter Maps ASCII uppercase letters, lowercase letters, and digits to their bold sans-serif counterparts. Other characters pass through unchanged. This function is used by `apply_style` for bold text. ```python def to_sans_bold(text: str) -> str: """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. Args: text: The input string to convert. Returns: A new string with ASCII alphanumerics replaced by bold sans-serif Unicode equivalents. Examples: >>> to_sans_bold("Hello, World! 123") '𝗛𝗲𝗹𝗹𝗼, 𝗪𝗼𝗿𝗹𝗱! 𝟭𝟮𝟯' >>> to_sans_bold("café") '𝗰𝗮𝗳é' >>> to_sans_bold("") '' """ out: list[str] = [] for c in text: if "A" <= c <= "Z": out.append(chr(_SANS_BOLD_UPPER + ord(c) - ord("A"))) elif "a" <= c <= "z": out.append(chr(_SANS_BOLD_LOWER + ord(c) - ord("a"))) elif "0" <= c <= "9": out.append(chr(_SANS_BOLD_DIGIT + ord(c) - ord("0"))) else: out.append(c) return "".join(out) ``` -------------------------------- ### to_sans_italic Source: https://www.indrapatil.com/md2linkedin/reference/converter Converts ASCII letters to Unicode Mathematical Sans-Serif Italic. ```APIDOC ## FUNCTION to_sans_italic ### Description Maps ASCII uppercase and lowercase letters to their italic sans-serif counterparts. Digits and other characters remain unchanged. ### Parameters - **text** (str) - Required - The input string to convert. ### Response - **returns** (str) - A new string with ASCII letters replaced by italic sans-serif Unicode equivalents. ``` -------------------------------- ### Convert Markdown to LinkedIn Plain Text Source: https://www.indrapatil.com/md2linkedin/reference/converter Use this function to convert Markdown text to a plain-text string compatible with LinkedIn. It handles various Markdown elements and preserves styling using Unicode characters. Configure link preservation and monospace code rendering. ```python def convert( text: str, *, preserve_links: bool = False, monospace_code: bool = True, ) -> str: """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``. Args: text: The Markdown source string. preserve_links: When ``True``, link syntax (``[text](url)``) is left unchanged in the output instead of being reduced to display text. monospace_code: When ``True`` (the default), inline code spans and fenced code blocks are rendered in Unicode Mathematical Monospace. When ``False``, inline code is kept as plain text and fenced blocks are preserved verbatim. Returns: A plain-text string suitable for pasting into LinkedIn. Examples: >>> convert("**Hello**, *world*!") '𝗛𝗲𝗹𝗹𝗼, 𝘸𝘰𝘳𝘭𝘥!\n' >>> convert("") '' """ if not text or not text.strip(): return "" text = _normalize_line_endings(text) text, placeholders = _protect_code(text) text = _strip_html_spans(text) text = _strip_images(text) text = _convert_bold_italic(text) text = _convert_bold(text) text = _convert_italic(text) text = _convert_headers(text) text = _strip_links(text, preserve=preserve_links) text = _convert_bullets(text) text = _strip_blockquotes(text) text = _restore_code(text, placeholders, monospace=monospace_code) text = _clean_entities(text) text = _clean_escaped_chars(text) return _normalize_whitespace(text) ``` ```python >>> convert("**Hello**, *world*!") '𝗛𝗲𝗹𝗹𝗼, 𝘸𝘰𝘳𝘭𝘥!\n' ``` ```python >>> convert("") '' ``` -------------------------------- ### Process Large Documents Source: https://www.indrapatil.com/md2linkedin/advanced The conversion function is optimized for performance and can handle large input strings. ```python big_md = Path("quarterly_report.md").read_text() result = convert(big_md) ``` -------------------------------- ### Convert text to Sans-Serif Bold Italic Source: https://www.indrapatil.com/md2linkedin/reference/converter Maps ASCII letters to bold-italic sans-serif Unicode characters. Digits and other characters remain unchanged. ```python >>> to_sans_bold_italic("Hello, World!") '𝙃𝙚𝙡𝙡𝙤, 𝙒𝙤𝙧𝙡𝙙!' ``` ```python >>> to_sans_bold_italic("") '' ``` ```python def to_sans_bold_italic(text: str) -> str: """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. Args: text: The input string to convert. Returns: A new string with ASCII letters replaced by bold-italic sans-serif Unicode equivalents. Examples: >>> to_sans_bold_italic("Hello, World!") '𝙃𝙚𝙡𝙡𝙤, 𝙒𝙤𝙧𝙡𝙙!' >>> to_sans_bold_italic("") '' """ out: list[str] = [] for c in text: if "A" <= c <= "Z": out.append(chr(_SANS_BOLD_ITALIC_UPPER + ord(c) - ord("A"))) elif "a" <= c <= "z": out.append(chr(_SANS_BOLD_ITALIC_LOWER + ord(c) - ord("a"))) else: out.append(c) return "".join(out) ``` -------------------------------- ### Convert Text to Unicode Monospace Source: https://www.indrapatil.com/md2linkedin/reference/converter Maps ASCII uppercase letters, lowercase letters, and digits to their monospace counterparts. Other characters pass through unchanged. Useful for consistent text formatting. ```python def to_monospace(text: str) -> str: """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. Args: text: The input string to convert. Returns: A new string with ASCII alphanumerics replaced by monospace Unicode equivalents. Examples: >>> to_monospace("Hello, World! 123") '𝙷𝚎𝚕𝚕𝚘, 𝚆𝚘𝚛𝚕𝚍! 𝟷𝟸𝟹' >>> to_monospace("café") '𝚌𝚊𝚏é' >>> to_monospace("") '' """ out: list[str] = [] for c in text: if "A" <= c <= "Z": out.append(chr(_MONOSPACE_UPPER + ord(c) - ord("A"))) elif "a" <= c <= "z": out.append(chr(_MONOSPACE_LOWER + ord(c) - ord("a"))) elif "0" <= c <= "9": out.append(chr(_MONOSPACE_DIGIT + ord(c) - ord("0"))) else: out.append(c) return "".join(out) ``` -------------------------------- ### Handle Underscore Italicization Source: https://www.indrapatil.com/md2linkedin/advanced Single underscores are only treated as italics when they appear at word boundaries. ```python convert("_italic_") # → italic Unicode convert("snake_case_variable") # → unchanged ``` -------------------------------- ### Convert text to Sans-Serif Italic Source: https://www.indrapatil.com/md2linkedin/reference/converter Maps ASCII letters to italic sans-serif Unicode characters. Digits and other characters are not affected as no italic digit codepoints exist in this block. ```python >>> to_sans_italic("Hello, World!") '𝘏𝘦𝘭𝘭𝘰, 𝘞𝘰𝘳𝘭𝘥!' ``` ```python >>> to_sans_italic("price: $42") '𝘱𝘳𝘪𝘤𝘦: $42' ``` ```python >>> to_sans_italic("") '' ``` ```python def to_sans_italic(text: str) -> str: """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). Args: text: The input string to convert. Returns: A new string with ASCII letters replaced by italic sans-serif Unicode equivalents. Examples: >>> to_sans_italic("Hello, World!") '𝘏𝘦𝘭𝘭𝘰, 𝘞𝘰𝘳𝘭𝘥!' >>> to_sans_italic("price: $42") '𝘱𝘳𝘪𝘤𝘦: $42' >>> to_sans_italic("") '' """ out: list[str] = [] for c in text: if "A" <= c <= "Z": out.append(chr(_SANS_ITALIC_UPPER + ord(c) - ord("A"))) elif "a" <= c <= "z": out.append(chr(_SANS_ITALIC_LOWER + ord(c) - ord("a"))) else: out.append(c) return "".join(out) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.