Skip to content

Commit

Permalink
Fix error stripping mdpo commands from original Markdown pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Feb 27, 2022
1 parent 6936124 commit ebd6809
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.22
current_version = 0.0.23

[bumpversion:file:mkdocs_mdpo_plugin/__init__.py]

Expand Down
32 changes: 28 additions & 4 deletions docs/locale/es/useful-recipes.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,38 @@ msgid ""
"use them directly [as a command line interface][mdpo-cli] or through is "
"[pre-commit hooks][mdpo-pre-commit]."
msgstr ""
"[mdpo] es el núcleo de **mkdocs-mdpo-plugin**. El paquete contiene un conjunto"
" de programas para traducir archivos Markdown usando [archivos PO][po-files],"
" así que puedes usarlos directamente como una [interfaz de línea de comandos][mdpo-cli]"
" o mediante sus [hooks pre-commit][mdpo-pre-commit]."
"[mdpo] es el núcleo de **mkdocs-mdpo-plugin**. El paquete contiene un "
"conjunto de programas para traducir archivos Markdown usando [archivos "
"PO][po-files], así que puedes usarlos directamente como una [interfaz de "
"línea de comandos][mdpo-cli] o mediante sus [hooks pre-commit][mdpo-pre-"
"commit]."

msgid ""
"[po-files]: https://www.gnu.org/software/gettext/manual/gettext.html#PO-"
"Files"
msgstr ""
"[po-files]: https://www.gnu.org/software/gettext/manual/gettext.html#PO-"
"Files"

msgid ""
"```\n"
"locale\n"
"├── es\n"
"│   ├── README.md\n"
"│   └── README.md.po\n"
"└── fr\n"
" ├── README.md\n"
" └── README.md.po\n"
"README.md <-- only existing file before execution\n"
"```\n"
msgstr ""
"```\n"
"locale\n"
"├── es\n"
"│   ├── README.md\n"
"│   └── README.md.po\n"
"└── fr\n"
" ├── README.md\n"
" └── README.md.po\n"
"README.md <-- único archivo existente antes de la ejecución\n"
"```\n"
11 changes: 9 additions & 2 deletions docs/src/assets/javascripts/extensions-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
var removePyMdownxSnippetsMarkdownDemoEscapeChar = function() {
var pyMdownSnippetsSection = document.getElementById('pymdownxsnippets');
if (pyMdownSnippetsSection) {
var markdownCodeBlock = pyMdownSnippetsSection.nextElementSibling.children[5].children[0].children[0].children[1];
markdownCodeBlock.innerHTML = markdownCodeBlock.innerHTML.replace('\\', '');
console.log(pyMdownSnippetsSection)
var markdownCode = pyMdownSnippetsSection.nextElementSibling.children[5].children[0].children[0];
for (let i=0; i<markdownCode.children.length; i++) {
let child = markdownCode.children[i];
if (child.tagName === 'CODE') {
child.innerHTML = child.innerHTML.replace('\\', '');
break;
}
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions docs/src/useful-recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use them directly [as a command line interface][mdpo-cli] or through is
files: ^README\.md
args: ['-l', 'es', '-l', 'fr', '-o', 'locale/{lang}']
```

<!-- mdpo-include-codeblocks -->
=== "Directories tree"

```
Expand All @@ -72,9 +72,11 @@ use them directly [as a command line interface][mdpo-cli] or through is
└── fr
├── README.md
└── README.md.po
README.md <-- only existing file before execute it
README.md <-- only existing file before execution
```

<!-- mdpo-disable-codeblocks -->

## Relative mkdocs-material's language selector

If you are using the [mkdocs-material theme][mkdocs-material], you can install
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_mdpo_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""mkdocs-mdpo-plugin package"""

__version__ = '0.0.22'
__version__ = '0.0.23'
33 changes: 14 additions & 19 deletions mkdocs_mdpo_plugin/mdpo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
from mdpo.command import COMMAND_SEARCH_REGEX


COMMAND_SEARCH_REGEX_AT_LINE_START = re.compile(
r'^(\s{2,})?[^\\]' + COMMAND_SEARCH_REGEX + r'\n?',
re.M,
)
COMMAND_SEARCH_REGEX_ESCAPER = re.compile(
(
r'\\(' + COMMAND_SEARCH_REGEX[:20] + ')('
Expand All @@ -20,19 +16,18 @@


def remove_mdpo_commands_preserving_escaped(text):
return re.sub(
# restore escaped commands
'<!-- mdpo-0',
'<!-- mdpo',
re.sub(
# remove commands
COMMAND_SEARCH_REGEX_AT_LINE_START,
'',
# preserve escaped commands
re.sub(
COMMAND_SEARCH_REGEX_ESCAPER,
r'\g<1>0-\g<2>',
text,
),
),
# preserve escaped commands
text = re.sub(
COMMAND_SEARCH_REGEX_ESCAPER,
r'\g<1>0-\g<2>',
text,
)

text = re.sub(
COMMAND_SEARCH_REGEX,
'',
text,
)

# restore escaped commands
return text.replace('<!-- mdpo-0', '<!-- mdpo')
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = mkdocs_mdpo_plugin
version = 0.0.22
version = 0.0.23
description = Mkdocs plugin for translations using PO files.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit ebd6809

Please sign in to comment.