mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-06-23 15:31:37 -04:00
fix: removed HTML tags when copying recipe ingredients (#2533)
This commit is contained in:
parent
408ca88cb2
commit
0a00a6ea0d
@ -54,7 +54,7 @@ export default defineComponent({
|
|||||||
const ingredientCopyText = computed(() => {
|
const ingredientCopyText = computed(() => {
|
||||||
return props.value
|
return props.value
|
||||||
.map((ingredient) => {
|
.map((ingredient) => {
|
||||||
return `${parseIngredientText(ingredient, props.disableAmount, props.scale)}`;
|
return `${parseIngredientText(ingredient, props.disableAmount, props.scale, false)}`;
|
||||||
})
|
})
|
||||||
.join("\n");
|
.join("\n");
|
||||||
});
|
});
|
||||||
|
@ -31,7 +31,16 @@ describe(parseIngredientText.name, () => {
|
|||||||
test("ingredient text with fraction", () => {
|
test("ingredient text with fraction", () => {
|
||||||
const ingredient = createRecipeIngredient({ quantity: 1.5, unit: { fraction: true, id: "1", name: "cup" } });
|
const ingredient = createRecipeIngredient({ quantity: 1.5, unit: { fraction: true, id: "1", name: "cup" } });
|
||||||
|
|
||||||
expect(parseIngredientText(ingredient, false)).contain("1 <sup>1</sup>").and.to.contain("<sub>2</sub>");
|
expect(parseIngredientText(ingredient, false, 1, true)).contain("1 <sup>1</sup>").and.to.contain("<sub>2</sub>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("ingredient text with fraction no formatting", () => {
|
||||||
|
const ingredient = createRecipeIngredient({ quantity: 1.5, unit: { fraction: true, id: "1", name: "cup" } });
|
||||||
|
const result = parseIngredientText(ingredient, false, 1, false);
|
||||||
|
|
||||||
|
expect(result).not.contain("<");
|
||||||
|
expect(result).not.contain(">");
|
||||||
|
expect(result).contain("1 1/2");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("sanitizes html", () => {
|
test("sanitizes html", () => {
|
||||||
|
@ -10,7 +10,7 @@ function sanitizeIngredientHTML(rawHtml: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useParsedIngredientText(ingredient: RecipeIngredient, disableAmount: boolean, scale = 1) {
|
export function useParsedIngredientText(ingredient: RecipeIngredient, disableAmount: boolean, scale = 1, includeFormating = true) {
|
||||||
if (disableAmount) {
|
if (disableAmount) {
|
||||||
return {
|
return {
|
||||||
name: ingredient.note ? sanitizeIngredientHTML(ingredient.note) : undefined,
|
name: ingredient.note ? sanitizeIngredientHTML(ingredient.note) : undefined,
|
||||||
@ -35,7 +35,9 @@ export function useParsedIngredientText(ingredient: RecipeIngredient, disableAmo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fraction[1] > 0) {
|
if (fraction[1] > 0) {
|
||||||
returnQty += ` <sup>${fraction[1]}</sup>⁄<sub>${fraction[2]}</sub>`;
|
returnQty += includeFormating ?
|
||||||
|
` <sup>${fraction[1]}</sup>⁄<sub>${fraction[2]}</sub>` :
|
||||||
|
` ${fraction[1]}/${fraction[2]}`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
returnQty = (quantity * scale).toString();
|
returnQty = (quantity * scale).toString();
|
||||||
@ -54,8 +56,8 @@ export function useParsedIngredientText(ingredient: RecipeIngredient, disableAmo
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseIngredientText(ingredient: RecipeIngredient, disableAmount: boolean, scale = 1): string {
|
export function parseIngredientText(ingredient: RecipeIngredient, disableAmount: boolean, scale = 1, includeFormating = true): string {
|
||||||
const { quantity, unit, name, note } = useParsedIngredientText(ingredient, disableAmount, scale);
|
const { quantity, unit, name, note } = useParsedIngredientText(ingredient, disableAmount, scale, includeFormating);
|
||||||
|
|
||||||
const text = `${quantity || ""} ${unit || ""} ${name || ""} ${note || ""}`.replace(/ {2,}/g, " ").trim();
|
const text = `${quantity || ""} ${unit || ""} ${name || ""} ${note || ""}`.replace(/ {2,}/g, " ").trim();
|
||||||
return sanitizeIngredientHTML(text);
|
return sanitizeIngredientHTML(text);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user