semvec/pypi-packages huggingface dataset:
mdpo2html 0.0.9
0.0.9
License: BSD License
Requires Python: >=3

# mdpo2html

[![PyPI](https://img.shields.io/pypi/v/mdpo2html)](https://pypi.org/project/mdpo2html/) [![PyPI versions](https://img.shields.io/pypi/pyversions/mdpo2html)](https://pypi.org/project/mdpo2html/) [![Tests](https://img.shields.io/travis/mondeja/mdpo2html?label=tests)](https://travis-ci.com/github/mondeja/mdpo2html) [![Coverage Status](https://coveralls.io/repos/github/mondeja/mdpo2html/badge.svg)](https://coveralls.io/github/mondeja/mdpo2html)

Given next HTML string:

```html
<html>
  <body>
    <h1>Header</h1>
    <p>I'm a string with <strong>bold text</strong>, <i>italic text<i>, <code>inline code with ` backtick</code>, <a href="https://github.com/mondeja/mdpo2html">a link</a> and an asterisk like *.</p>
  <body>
</html>
```

...and next dictionary:

```python
replacements = {
  "Header": "Encabezado",
  "I'm a string with **bold text**, *italic text*, `inline code with \\` backtick` `[a link]` and an asterisk like \\*.": "Soy una cadena con **texto en negrita**, *texto en cursiva*, `código en línea con \\` tilde invertida`, `[un enlace]` y un asterisco como \\*."
}
```

This package allows you to do this:

```python
>>> from mdpo2html import mdpo_html_replace
>>>
>>> mdpo_html_replace(html, replacements)
<html>
  <body>
    <h1>Encabezado</h1>
    <p>Soy una cadena con <strong>texto en negrita</strong>, <i>texto en cursiva<i>, <code>código en línea con ` tilde invertida</code>, <a href="https://github.com/mondeja/mdpo2html">un enlace</a> y un asterisco como *.</p>
  <body>
</html>
```

Also, the parser can infere where the strings need to be placed inside special markups characters. For example, you can do this:

```python
>>> html = '<p><code>Flexible</code> replacement</p>'
>>> replacements = {"`Flexible` replacement": "Reemplazamiento `flexible`"}
>>> mdpo_html_replace(html, replacements)
<p>Reemplazamiento <code>flexible</code></p>
>>>
>>> # Even some magic
>>> html = '<p><strong>Flexible</strong> replacement <strong>again</strong></p>'
>>> replacements = {"**Flexible** replacement **again**": "Reemplazamiento **flexible de nuevo**"}
>>> mdpo_html_replace(html, replacements)
<p>Reemplazamiento <strong>flexible de nuevo</strong></p>
```

So this package allows you to convert extracted Markdown strings from one `.po` file inside HTML distribution files generated by some processors like [markdown_py](https://python-markdown.github.io/) (recommended).

If you want to extract Markdown strings to `.po` files, check my [md2po](https://github.com/mondeja/md2po) package. Along with this package provides you a convenient way of translate Markdown files inside HTML directly, so you doesn't need to create one HTML file for every distribution language (server side caching) nor use painful template rendering to internationalize your project (static pages).

> This package exists to fit my needs, if you want to see more functionalities added to this package, [send a pull request](https://github.com/mondeja/mdpo2html/pulls) or [open an issue](https://github.com/mondeja/mdpo2html/issues/new) with a minimal example.


## Install

```bash

pip install mdpo2html
```