Skip to content

Commit

Permalink
Do not quote lists in YAML Front Matter of markdown
Browse files Browse the repository at this point in the history
Fix #304
  • Loading branch information
mquinson committed Jul 9, 2022
1 parent d70589e commit 50a2744
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 17 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Markdown:
Useful when your file starts with an horizontal ruler that is not a YFM.
(GitHub's #365) [mquinson]
This introduces a NEW DEPENDENCY: Syntax::Keyword::Try
* Do not quote the YFM lists to not break them (GitHub's #304) [mquinson].
Thanks @dbaio for the analysis and @ynojima for an initial patch in doc-l10n-kit.

xHTML:
* Add a test for tables and stop claiming that they may be broken
Expand Down
16 changes: 9 additions & 7 deletions lib/Locale/Po4a/TransTractor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1304,19 +1304,21 @@ sub handle_yaml {
if ( !$type ) {
my %keys = %{$yfm_keys};
if ( ( not %keys ) || $keys{$name} ) { # either no key is provided, or the key we need is also provided
$self->pushline(
$header . ' '
. format_scalar(
$self->translate( $el, $blockref, "YAML Front Matter:$ctx $name", "wrap" => 0 )
)
. "\n"
);
my $translation = $self->translate( $el, $blockref, "YAML Front Matter:$ctx $name", "wrap" => 0 );
if ( $el =~ /^\[.*\]$/ ) { # Do not quote the lists
$self->pushline( $header . " $translation\n" );
} else {
# add extra quotes to the parameter, as a protection to the extra chars that the translator could add
$self->pushline( $header . ' ' . format_scalar($translation) . "\n" );
}
} else {

# Work around a bug in YAML::Tiny that quotes numbers
# See https://github.com/Perl-Toolchain-Gang/YAML-Tiny#additional-perl-specific-notes
if ( Scalar::Util::looks_like_number($el) ) {
$self->pushline("$header $el\n");
} elsif ( $el =~ /^\[.*\]$/ ) { # Do not quote the lists either
$self->pushline("$header $el\n");
} else {
$self->pushline( $header . ' ' . YAML::Tiny::_dump_scalar( "dummy", $el ) . "\n" );
}
Expand Down
1 change: 1 addition & 0 deletions t/fmt/txt-markdown/YamlFrontMatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include_newlines: |
exactly as you see
will appear these three
lines of poetry
list: ["freebsd", "netbsd", "general"]
people:
-
name: John D'vloper
Expand Down
1 change: 1 addition & 0 deletions t/fmt/txt-markdown/YamlFrontMatter.norm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
author: test
include_newlines: "exactly as you see\nwill appear these three\nlines of poetry\n"
list: ["freebsd", "netbsd", "general"]
people:
-
hobbies:
Expand Down
16 changes: 11 additions & 5 deletions t/fmt/txt-markdown/YamlFrontMatter.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2020-04-28 19:06+0200\n"
"POT-Creation-Date: 2022-07-09 23:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@LI.ORG>\n"
Expand All @@ -34,6 +34,12 @@ msgstr ""
"WILL APPEAR THESE THREE\n"
"LINES OF POETRY\n"

#. type: YAML Front Matter: list
#: YamlFrontMatter.md:1
#, no-wrap
msgid "[\"freebsd\", \"netbsd\", \"general\"]"
msgstr "[\"FREEBSD\", \"NETBSD\", \"GENERAL\"]"

#. type: YAML Front Matter: people hobbies
#: YamlFrontMatter.md:1
#, no-wrap
Expand Down Expand Up @@ -101,7 +107,7 @@ msgid "markdown"
msgstr "MARKDOWN"

#. type: Title #
#: YamlFrontMatter.md:1 YamlFrontMatter.md:32
#: YamlFrontMatter.md:1 YamlFrontMatter.md:33
#, no-wrap
msgid "YAML: does it fit in Markdown?"
msgstr "YAML: DOES IT FIT IN MARKDOWN?"
Expand All @@ -113,7 +119,7 @@ msgid "this is really a single line of text despite appearances\n"
msgstr "THIS IS REALLY A SINGLE LINE OF TEXT DESPITE APPEARANCES\n"

#. type: Plain text
#: YamlFrontMatter.md:36
#: YamlFrontMatter.md:37
msgid ""
"Lots of Static Site Generators like Jekyll, Hugo, Lektor and more use a "
"standard format: Markdown with YAML Front Matter."
Expand All @@ -122,11 +128,11 @@ msgstr ""
"STANDARD FORMAT: MARKDOWN WITH YAML FRONT MATTER."

#. type: Plain text
#: YamlFrontMatter.md:38
#: YamlFrontMatter.md:39
msgid "Why"
msgstr "WHY"

#. type: Plain text
#: YamlFrontMatter.md:41
#: YamlFrontMatter.md:42
msgid "Because blog posts need metadata!"
msgstr "BECAUSE BLOG POSTS NEED METADATA!"
16 changes: 11 additions & 5 deletions t/fmt/txt-markdown/YamlFrontMatter.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2020-04-28 19:06+0200\n"
"POT-Creation-Date: 2022-07-09 23:33+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -31,6 +31,12 @@ msgid ""
"lines of poetry\n"
msgstr ""

#. type: YAML Front Matter: list
#: YamlFrontMatter.md:1
#, no-wrap
msgid "[\"freebsd\", \"netbsd\", \"general\"]"
msgstr ""

#. type: YAML Front Matter: people hobbies
#: YamlFrontMatter.md:1
#, no-wrap
Expand Down Expand Up @@ -98,7 +104,7 @@ msgid "markdown"
msgstr ""

#. type: Title #
#: YamlFrontMatter.md:1 YamlFrontMatter.md:32
#: YamlFrontMatter.md:1 YamlFrontMatter.md:33
#, markdown-text, no-wrap
msgid "YAML: does it fit in Markdown?"
msgstr ""
Expand All @@ -110,21 +116,21 @@ msgid "this is really a single line of text despite appearances\n"
msgstr ""

#. type: Plain text
#: YamlFrontMatter.md:36
#: YamlFrontMatter.md:37
#, markdown-text
msgid ""
"Lots of Static Site Generators like Jekyll, Hugo, Lektor and more use a "
"standard format: Markdown with YAML Front Matter."
msgstr ""

#. type: Plain text
#: YamlFrontMatter.md:38
#: YamlFrontMatter.md:39
#, markdown-text
msgid "Why"
msgstr ""

#. type: Plain text
#: YamlFrontMatter.md:41
#: YamlFrontMatter.md:42
#, markdown-text
msgid "Because blog posts need metadata!"
msgstr ""
1 change: 1 addition & 0 deletions t/fmt/txt-markdown/YamlFrontMatter.trans
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
author: TEST
include_newlines: "EXACTLY AS YOU SEE\nWILL APPEAR THESE THREE\nLINES OF POETRY\n"
list: ["FREEBSD", "NETBSD", "GENERAL"]
people:
-
hobbies:
Expand Down

0 comments on commit 50a2744

Please sign in to comment.