From 2cf0ffbffc8442efaba12364a07fc0f5e58b7432 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 20 Mar 2024 11:25:44 +0100 Subject: Support underscore in the exporters on titles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Underscores on titles are meant to be replaced by something else on each exporter (e.g. removed on CSV, or surrounded by \emph on UOC). Signed-off-by: Miquel Sabaté Solà --- lib/uoc_exporter.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib/uoc_exporter.rb') diff --git a/lib/uoc_exporter.rb b/lib/uoc_exporter.rb index 9a83d7c..e8dcc62 100644 --- a/lib/uoc_exporter.rb +++ b/lib/uoc_exporter.rb @@ -16,7 +16,7 @@ class UocExporter < BaseExporter # Returns the head of a line, containing authors, year, title and, if # available, the "inside of" information. def head(thing:) - str = "#{parse_authors(thing:)} (#{thing.year}). \\emph{#{thing.title}}." + str = "#{parse_authors(thing:)} (#{thing.year}). #{parse_title(title: thing.title)}." if thing.insideof.present? str += " #{inside_of(thing.insideof)}" @@ -26,6 +26,25 @@ class UocExporter < BaseExporter str end + # Returns the title without underscores and with the expected formatting. + def parse_title(title:) + str = '' + seen = false + + # I'm sure there is a clever (and comboluted) regexp that can also achieve + # this, but after some tries I decided to cut the crap. + title.each_char do |c| + if c == '_' + str += seen ? '\emph{' : '}' + seen = !seen + else + str += c + end + end + + "\\emph{#{str}}" + end + # Parse the authors as delivered by `thing.authors` and render them in the # proper format. def parse_authors(thing:) -- cgit v1.2.3