Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdpo-disable-next-line and mdpo-enable-next-line don't just disable the next line #211

Closed
keunes opened this issue Dec 16, 2021 · 2 comments · Fixed by #212
Closed

mdpo-disable-next-line and mdpo-enable-next-line don't just disable the next line #211

keunes opened this issue Dec 16, 2021 · 2 comments · Fixed by #212
Labels
enhancement New feature or request

Comments

@keunes
Copy link

keunes commented Dec 16, 2021

Hello,

To ensure proper rendering of images when translated versions are available, we had to put some liquid tricks in place. This, in turn, made it necessary to use <!-- mdpo-disable-next-line --> and <!-- mdpo-enable-next-line --> in our document. However, it seems that instead of just enabling or disabling the next line in the md file, the whole block that mdpo considers a 'message' is enabled or disabled.

Given the file gpodder.md (from our Jekyll website):

  • I would expect line 8 with the word devices to be included without whatever follows because it is part of a disabled block (and the same for line 17 with the word synchronize)
    • Instead, the following lines (9-12 and 18-21) are included in the PO(T) file as well:
      "devices \" loc=\"/assets/images/documentation\" file=\"gpodder-devices.png\""
      " %}{% endcapture %}"
  • I would expect line 25 with the phrase After you created the account to be included, as it is not excluded by any preceding tags (and the same for line 27 with the phrase After you created the devices)
    • Instead, these lines are not available in the PO(T) file, probably because the message includes an exclusion tag.

I'm using the following code to create a POT file from the attached MD file: md2po gpodder.md --po-filepath site-documentation_en.POT --save --quiet --remove-not-found

I'm not sure if this open interpretation is intentional or not. Either way, it would be great if the tags to enable and disable next lines could be interpreted more strictly, so that only any content on the next line in the file is affected - not more not less.

This would save us from having to introduce white lines (which we now need in order to avoid liquid code ending up in our translation files).

Thanks again for making mdpo!

@mondeja mondeja added the enhancement New feature or request label Dec 16, 2021
@mondeja
Copy link
Owner

mondeja commented Dec 16, 2021

Sorry, but this is not how md2po works. It's intended to extract text from Markdown content. For this reason the MD4C parser used in the implementation doesn't recognize lines. If you includes another content, it just will not work as you expected. You are using template engine placeholders with HTML and Markdown here, and trying to extract an attribute of HTML.

I have to admit that the name of the commands mdpo-disable-next-line and mdpo-enable-next-line are confusing. Were defined like so, using the same syntax of ESLint, just because I remember them more easily. They disable/enable the next block instead of the next line.

So the solution here would be to add the next aliases for these commands, maintaining the current names for backwards compatibility and convenience:

  • mdpo-disable-next-line -> mdpo-disable-next-block
  • mdpo-enable-next-line -> mdpo-enable-next-block

@mondeja
Copy link
Owner

mondeja commented Dec 17, 2021

Added mdpo-disable-next-block and mdpo-enable-next-block command aliases for mdpo-disable-next-line and mdpo-enable-next-line and properly documented disable/enable-next-line commands. There will be available in the next release. This does not solve your problem but would prevent the confussion in the future.

I'm open to accept pull requests that implement more flexible ways of parsing than MD4C so we could introduce a real disable/enable-next-line command and other improvements like #152 without decreasing performance, but it is not easy. I suppose that it would be easy to implement if MD4C includes more information about the parsed source (see issue 91 in md4c). Without it, I'm not going to implement this.

For now I can only suggest to include the whole Jekyll template engine block in POT files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants