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

Collapsed reference links converted in POT to shortcut reference links #221

Closed
ivilata opened this issue Feb 24, 2022 · 2 comments
Closed
Labels
rendering-format Some related with a problem with rendering format

Comments

@ivilata
Copy link

ivilata commented Feb 24, 2022

(After the last comments from #164.)

According to CommonMark link specs, a collapsed reference link like [foo][] and a shortcut reference link like [foo] should both be valid and equivalent to [foo][foo].

However, md2po 0.3.84 converts collapsed links to shortcut ones in POT entries. For instance, with a test.md with the following content:

A link to [example.com][].

Another link to [example.com].

[example.com]: http://example.com/

the command md2po test.md > test.po creates these entries (I added the missing translation):

#: test.md:block 1 (paragraph)
msgid "A link to [example.com]."
msgstr "A translated link to [example.com]."

#: test.md:block 2 (paragraph)
msgid "Another link to [example.com]."
msgstr "Another translated link to [example.com]."

#: test.md:block 2 (paragraph)
#, fuzzy
msgid "[example.com]: http://example.com/"
msgstr "[example.com]: http://example.com/"

Then po2md -p test.po -s /dev/stdout test.md produces:

A translated link to [example.com].

Another translated link to [example.com].

[example.com]: http://example.com/

The final output is correct, the issue is that PO strings slightly differ from the original ones. I would expect that both [foo][] and [foo] keep their shape in the PO file.

Please note that the original Markdown contemplated [foo][] but not [foo] as valid links, so thay may affect some editors or syntax highlighters (like GitHub's).

This started happening with mdpo 0.3.80 (while 0.3.79 would convert them to [example.com][example.com] instead, which confuses some translators).

Thank you!

@mondeja
Copy link
Owner

mondeja commented Feb 24, 2022

Thanks. The problem is essentially that MD4C parser does not provide information about the formatting of the links, so I can't differentiate between [foo][] and [foo]. You can see the information provided by MD4C in link spans appending the --debug option:

md2po --debug test.md
md2po[DEBUG]::2022-02-24 20:29:42.607483::enter_block:: DOC
md2po[DEBUG]::2022-02-24 20:29:42.607544::enter_block:: P
md2po[DEBUG]::2022-02-24 20:29:42.607569::text:: A link to 
md2po[DEBUG]::2022-02-24 20:29:42.607603::enter_span:: A - {'href': [(<TextType.NORMAL: 0>, 'http://example.com/')], 'title': None}
md2po[DEBUG]::2022-02-24 20:29:42.607887::text:: example.com
md2po[DEBUG]::2022-02-24 20:29:42.607921::leave_span:: A - {'href': [(<TextType.NORMAL: 0>, 'http://example.com/')], 'title': None}
md2po[DEBUG]::2022-02-24 20:29:42.607941::text:: .
md2po[DEBUG]::2022-02-24 20:29:42.607956::leave_block:: P
md2po[DEBUG]::2022-02-24 20:29:42.607968::msgid:: msgid='A link to [example.com].'
md2po[DEBUG]::2022-02-24 20:29:42.608007::enter_block:: P
md2po[DEBUG]::2022-02-24 20:29:42.608026::text:: Another link to 
md2po[DEBUG]::2022-02-24 20:29:42.608054::enter_span:: A - {'href': [(<TextType.NORMAL: 0>, 'http://example.com/')], 'title': None}
md2po[DEBUG]::2022-02-24 20:29:42.608069::text:: example.com
md2po[DEBUG]::2022-02-24 20:29:42.608087::leave_span:: A - {'href': [(<TextType.NORMAL: 0>, 'http://example.com/')], 'title': None}
md2po[DEBUG]::2022-02-24 20:29:42.608103::text:: .
md2po[DEBUG]::2022-02-24 20:29:42.608118::leave_block:: P
md2po[DEBUG]::2022-02-24 20:29:42.608128::msgid:: msgid='Another link to [example.com].'
md2po[DEBUG]::2022-02-24 20:29:42.608154::leave_block:: DOC
md2po[DEBUG]::2022-02-24 20:29:42.608167::msgid:: msgid=''
md2po[DEBUG]::2022-02-24 20:29:42.608181::link_reference:: target='example.com' - href='http://example.com/'
md2po[DEBUG]::2022-02-24 20:29:42.608199::msgid:: msgid='[example.com]: http://example.com/' - msgstr='[example.com]: http://example.com/' - flags='['fuzzy']'
#
msgid ""
msgstr ""

#: test.md:block 1 (paragraph)
msgid "A link to [example.com]."
msgstr ""

#: test.md:block 2 (paragraph)
msgid "Another link to [example.com]."
msgstr ""

#: test.md:block 2 (paragraph)
#, fuzzy
msgid "[example.com]: http://example.com/"
msgstr "[example.com]: http://example.com/"

This was implemented in #204 (here) and could be implemented in either format, always being the same for all, but used this because is simpler. As I can see, Github accept all possible formats as valid links:

[example1]

[example1]: https://example1.com

[example2][example2]

[example2]: https://example2.com

[example3][]

[example3]: https://example3.com

example1

example2

example3

Really this issue is a duplicate of #152, but as said, is not possible to implement it, at least for now. Of course, PRs are welcome!

Do you know other parsers that would not be able to parse links like [foo]?

@mondeja mondeja added awaiting-response Someone must say something rendering-format Some related with a problem with rendering format labels Feb 27, 2022
@ivilata
Copy link
Author

ivilata commented Feb 28, 2022

Thanks @mondeja for the clarification! Since I have usually followed John Gruber's original specs, I've never used [foo] myself, so I can't list other parsers beyond GitHub's md syntax highlighter and Emacs' markdown-mode.

So, since the parsing issue is out of your control, and the choice between [foo][] and [foo] seems mostly aesthetic, feel free to close this issue. Thanks!

@mondeja mondeja removed the awaiting-response Someone must say something label Feb 28, 2022
@mondeja mondeja closed this as completed Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rendering-format Some related with a problem with rendering format
Projects
None yet
Development

No branches or pull requests

2 participants