Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/server/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub enum StepItem {
Cookware(String),
Timer(String),
Quantity(String),
LineBreak,
}

#[derive(Debug, Clone, Serialize)]
Expand Down
10 changes: 9 additions & 1 deletion src/server/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,15 @@ async fn recipe_page(

match item {
Item::Text { value } => {
step_items.push(StepItem::Text(value.to_string()));
let parts: Vec<&str> = value.split('\n').collect();
for (i, part) in parts.iter().enumerate() {
if i > 0 {
step_items.push(StepItem::LineBreak);
}
if !part.is_empty() {
step_items.push(StepItem::Text(part.to_string()));
}
}
}
Item::Ingredient { index } => {
section_ingredient_indices.insert(*index);
Expand Down
31 changes: 25 additions & 6 deletions src/util/cooklang_to_human.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,17 @@ fn steps(w: &mut impl io::Write, recipe: &Recipe) -> Result {
match content {
cooklang::Content::Step(step) => {
let (step_text, step_ingredients) = step_text(recipe, section, step);
let step_text = format!("{:>2}. {}", step.number, step_text.trim());
print_wrapped_with_options(w, &step_text, |o| o.subsequent_indent(" "))?;
let paragraphs: Vec<&str> = step_text.trim().split('\n').collect();
for (i, paragraph) in paragraphs.iter().enumerate() {
if i == 0 {
let first = format!("{:>2}. {}", step.number, paragraph.trim_start());
print_wrapped_with_options(w, &first, |o| o.subsequent_indent(" "))?;
} else {
print_wrapped_with_options(w, paragraph.trim_start(), |o| {
o.initial_indent(" ").subsequent_indent(" ")
})?;
}
}
print_wrapped_with_options(w, &step_ingredients, |o| {
let indent = " "; // 5
o.initial_indent(indent)
Expand All @@ -440,10 +449,20 @@ fn steps(w: &mut impl io::Write, recipe: &Recipe) -> Result {
// Format as a note with a visual indicator
let note_style = yansi::Style::new().italic().fg(yansi::Color::Blue);
let note_prefix = "📝 Note: ".paint(note_style);
write!(w, " {note_prefix}")?;
print_wrapped_with_options(w, t.trim(), |o| {
o.initial_indent("").subsequent_indent(" ")
})?;
let note_indent = " ";
let paragraphs: Vec<&str> = t.trim().split('\n').collect();
for (i, paragraph) in paragraphs.iter().enumerate() {
if i == 0 {
write!(w, " {note_prefix}")?;
print_wrapped_with_options(w, paragraph.trim(), |o| {
o.initial_indent("").subsequent_indent(note_indent)
})?;
} else {
print_wrapped_with_options(w, paragraph.trim(), |o| {
o.initial_indent(note_indent).subsequent_indent(note_indent)
})?;
}
}
writeln!(w)?;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/util/cooklang_to_latex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ fn write_ingredients(w: &mut impl io::Write, recipe: &Recipe, converter: &Conver
)?;
}

if ingredient.reference.is_some() {
if let Some(reference) = &ingredient.reference {
let sep = std::path::MAIN_SEPARATOR.to_string();
let path = ingredient.reference.as_ref().unwrap().components.join(&sep);
let path = reference.components.join(&sep);
write!(
w,
r"\ingredient{{{}}}",
Expand Down
4 changes: 2 additions & 2 deletions src/util/cooklang_to_md.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ fn ingredients(
}
}

if ingredient.reference.is_some() {
if let Some(reference) = &ingredient.reference {
let sep = std::path::MAIN_SEPARATOR.to_string();
let path = ingredient.reference.as_ref().unwrap().components.join(&sep);
let path = reference.components.join(&sep);
write!(
w,
"[{}]({}{}{})",
Expand Down
4 changes: 2 additions & 2 deletions src/util/cooklang_to_typst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ fn write_ingredients(w: &mut impl io::Write, recipe: &Recipe, converter: &Conver
write!(w, r"*{}* ", escape_typst(&entry.quantity.to_string()))?;
}

if ingredient.reference.is_some() {
if let Some(reference) = &ingredient.reference {
let sep = std::path::MAIN_SEPARATOR.to_string();
let path = ingredient.reference.as_ref().unwrap().components.join(&sep);
let path = reference.components.join(&sep);
write!(
w,
r#"#ingredient("{}")"#,
Expand Down
4 changes: 2 additions & 2 deletions templates/recipe.html
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ <h3 class="text-xl font-semibold mt-6 mb-4 text-orange-700 border-b-2 border-ora
<div class="text-gray-700 mb-2 leading-8">
{% for step_item in step.items %}
{% match step_item %}
{% when crate::server::templates::StepItem::Text with (text) %}{{ text }}{% when crate::server::templates::StepItem::Ingredient with { name, reference_path } %}{% match reference_path %}{% when Some with (path) %}<a href="/recipe/{{ path }}" class="ingredient-badge hover:underline" title="View recipe: {{ name }}">{{ name }}</a>{% when None %}<span class="ingredient-badge">{{ name }}</span>{% endmatch %}{% when crate::server::templates::StepItem::Cookware with (name) %}<span class="cookware-badge">{{ name }}</span>{% when crate::server::templates::StepItem::Timer with (name) %}<span class="timer-badge">⏱️ {{ name }}</span>{% when crate::server::templates::StepItem::Quantity with (qty) %}<span class="font-bold text-orange-600">{{ qty }}</span>{% endmatch %}{% endfor %}
{% when crate::server::templates::StepItem::Text with (text) %}{{ text }}{% when crate::server::templates::StepItem::Ingredient with { name, reference_path } %}{% match reference_path %}{% when Some with (path) %}<a href="/recipe/{{ path }}" class="ingredient-badge hover:underline" title="View recipe: {{ name }}">{{ name }}</a>{% when None %}<span class="ingredient-badge">{{ name }}</span>{% endmatch %}{% when crate::server::templates::StepItem::Cookware with (name) %}<span class="cookware-badge">{{ name }}</span>{% when crate::server::templates::StepItem::Timer with (name) %}<span class="timer-badge">⏱️ {{ name }}</span>{% when crate::server::templates::StepItem::Quantity with (qty) %}<span class="font-bold text-orange-600">{{ qty }}</span>{% when crate::server::templates::StepItem::LineBreak %}<br>{% endmatch %}{% endfor %}
</div>
{% if step.ingredients.len() > 0 %}
<div class="text-sm text-gray-600 mt-2 pl-4 border-l-2 border-orange-300">
Expand All @@ -318,7 +318,7 @@ <h3 class="text-xl font-semibold mt-6 mb-4 text-orange-700 border-b-2 border-ora
<li class="bg-gradient-to-r from-blue-50 to-purple-50 rounded-xl p-4 mb-3 border-l-4 border-blue-400">
<div class="flex items-start gap-2">
<span class="text-blue-600">📝</span>
<p class="text-gray-700 italic">{{ note }}</p>
<p class="text-gray-700 italic" style="white-space: pre-line">{{ note }}</p>
</div>
</li>
{% endmatch %}
Expand Down