From c4c25266435ce7f1d03d4c0cdf4a572afd88c5d9 Mon Sep 17 00:00:00 2001 From: Bastien Dumont Date: Tue, 27 Sep 2022 22:09:36 +0200 Subject: [PATCH] =?UTF-8?q?Implementation=20of=20=E2=80=9Cposition?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- margin-notes/README.md | 2 ++ margin-notes/margin-notes.lua | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/margin-notes/README.md b/margin-notes/README.md index 3961912..6fe9b21 100644 --- a/margin-notes/README.md +++ b/margin-notes/README.md @@ -130,3 +130,5 @@ mrgnn-define-renderings: In that case, you will have to define `\mrgnnTerm` in your LaTeX or ConTeXt template. This macro takes one argument, which is the result of the processing of `note-text`. +The position of the instructions about the marginal note in the output file can be set _via_ the variable `position`. They can be placed `after` (default) or `before` the in-text content. + diff --git a/margin-notes/margin-notes.lua b/margin-notes/margin-notes.lua index a880218..8d47bc2 100644 --- a/margin-notes/margin-notes.lua +++ b/margin-notes/margin-notes.lua @@ -21,6 +21,8 @@ local PLACEHOLDER_REGEX = PLACEHOLDER_BEGIN .. PLACEHOLDER_LABEL .. PLACEHOLDER_END -- String indicating an indefined value in the output local UNDEFINED = '??' +-- Default value for "position" ("before" or "after"). +local POS_DEFAULT = 'after' local DOCX_TOOLTIP_ANCHOR = '*' local DOCX_TOOLTIP_ANCHOR_SYTLE = 'Tooltip anchor' @@ -89,7 +91,7 @@ function add_rendering(config, class, body_text, note_text, docx_body_text, docx_note_text, odt_body_text, odt_note_text, - csname) + csname, position) -- The values are plain strings (not the empty string!) or nil. config[class] = { body_text = body_text, @@ -98,7 +100,8 @@ function add_rendering(config, class, docx_note_text = docx_note_text, odt_body_text = odt_body_text, odt_note_text = odt_note_text, - csname = csname + csname = csname, + position = position } end @@ -125,7 +128,8 @@ local function get_renderings_config(meta) or this_value['body-text']), meta_to_str(this_value['odt-note-text'] or this_value['note-text']), - meta_to_str(this_value['csname']) + meta_to_str(this_value['csname']), + meta_to_str(this_value['position']) or POS_DEFAULT ) end end @@ -526,6 +530,7 @@ local function render_margin_notes(span) if span.classes:includes(class_name) then local render_note = config[class_name].render.note local render_body = config[class_name].render.body + local note_position = config[class_name].position local margin_note = {} local body = {} if render_note then @@ -536,7 +541,19 @@ local function render_margin_notes(span) body = render_body(span.content, span.attributes) end span.content = body - return { span, unpack_table(margin_note) } + local span_with_note = {} + if note_position == 'before' then + span_with_note = margin_note + insert_in_table(span_with_note, span) + elseif note_position == 'after' then + span_with_note = { span, unpack_table(margin_note) } + else + error('Invalid value "' .. note_position .. '" ' .. + 'for "position" in the definition of ' .. + 'the margin-note class "' .. class_name '". ' .. + 'Expected "before" or "after".') + end + return span_with_note end end end