-
Notifications
You must be signed in to change notification settings - Fork 27
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
Allow formatting in the SUMMARY.md
file
#100
Conversation
TODO: I would like to add an end-to-end test of this: something which verifies that what we extract in |
72fa00b
to
2e2f4a7
Compare
I suppose the unit tests here are good enough — and we'll be testing this soon enough in Comprehensive Rust. |
2e2f4a7
to
704a7cc
Compare
These extra `)` were ignored by the `mdbook` parser, but they began showing up in my testing of google/mdbook-i18n-helpers#100.
704a7cc
to
97450ce
Compare
These extra `)` were ignored by the `mdbook` parser, but they began showing up in my testing of google/mdbook-i18n-helpers#100.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only took a brief look; hopefully @dyoo can look in more depth?
97450ce
to
73b90a5
Compare
@dyoo, does this look reasonable to you? |
fn add_stripped_summary_translations(catalog: &mut Catalog) { | ||
let mut stripped_messages = Vec::new(); | ||
for msg in catalog.messages() { | ||
if !msg.source().contains("SUMMARY.md") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps ends_with
instead of contains
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that would be nice, but we're actually matching against the full list of filenames here: something like src/foo/bar.md:123 src/SUMMARY.md:234
.
I could parse this and it would look something like this:
if !msg
.source()
.split_whitespace()
.filter_map(|source| source.split_once(':'))
.map(|(path, _)| Path::new(path))
.any(|path| path.file_name() == Some(OsStr::new("SUMMARY.md")))
{
continue;
}
However, now that I just tried this out, I realize that we cannot make any strong assumptions on where the SUMMARY.md
file is: mdbook
allows you to configure the source directory.
So the code above is essentially the same as just checking if SUMMARY.md
is found anywhere in the string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This first changes `mdbook-xgettext` so that formatting is preserved from the `SUMMARY.md` file. Next, `mdbook-gettext` is changed to translate text from the `SUMMARY.md` file without formatting: this is necessary since `mdbook` strips formatting before sending the TOC to the preprocessor. Fixes #66.
73b90a5
to
7ea5252
Compare
This first changes
mdbook-xgettext
so that formatting is preserved from theSUMMARY.md
file.Next,
mdbook-gettext
is changed to translate text from theSUMMARY.md
file without formatting: this is necessary sincemdbook
strips formatting before sending the TOC to the preprocessor.Fixes #66.