From 136d422a3334911920e98d00bb3426c569b39621 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 10 Mar 2020 17:19:00 +0100 Subject: [PATCH] Remove *all* text after a newline in title --- API.md | 2 +- init.lua | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/API.md b/API.md index f8d3b87..ca79595 100644 --- a/API.md +++ b/API.md @@ -42,7 +42,7 @@ easy and quick manipulation of the item help entries. All fields are optional. * `_doc_items_hidden`: Whether entry is hidden (default: `false` for air and hand, `true` for everything else) * `_doc_items_create_entry`: Whether to create an entry for this item (default: `true`) * `_doc_items_entry_name`: The title of the entry. By default, this is the same as the `description` field - of the item. This field is required if the `description` is empty + of the item (discarding text after the first newline). This field is required if the `description` is empty * `_doc_items_durability`: This field is for describing how long a tool can be used before it breaks. Choose one data type: * It it is a `number`: Fixed number of uses before it breaks * If it is a `string`: Free-form text which explains how the durability works. Try to keep it short and only use it if the other types won't work diff --git a/init.lua b/init.lua index b2c68c8..b0be3e1 100644 --- a/init.lua +++ b/init.lua @@ -65,10 +65,14 @@ local groups_to_string = function(grouptable, filter) end end --- Replaces all newlines with spaces +-- Removes all text after the first newline (including the newline) local scrub_newlines = function(text) - local new, x = string.gsub(text, "\n", " ") - return new + local spl = string.split(text, "\n") + if spl and #spl > 0 then + return spl[1] + else + return text + end end --[[ Append a newline to text, unless it already ends with a newline. ]]