md2po-html-replacer 0.0.2
0.0.2
License: BSD License
Requires Python: >=3

# md2po-html-replacer

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

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/md2po-html-replacer">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 md2po_html_replacer import markup_html_replace
>>>
>>> markup_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/md2po-html-replacer">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`"}
>>> markup_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**"}
>>> markup_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/md2po-html-replacer/pulls) or [open an issue](https://github.com/mondeja/md2po-html-replacer/issues/new) with a minimal example.


## Install

```bash

pip install md2po-html-replacer
```