Skip to content

Commit d571fa7

Browse files
committed
fix line splitting
1 parent fe69856 commit d571fa7

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/format/html/format-html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export async function htmlFormatExtras(
260260
options.figResponsive = format.metadata[kFigResponsive] || false;
261261
}
262262
if (featureDefaults.codeAnnotations) {
263-
options.codeAnnotations = format.metadata[kCodeAnnotations] || "below";
263+
options.codeAnnotations = format.metadata[kCodeAnnotations] || true;
264264
} else {
265265
options.codeAnnotations = format.metadata[kCodeAnnotations] || false;
266266
}

src/resources/filters/quarto-pre/code-annotation.lua

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ local function latexListPlaceholder(number)
142142
return '5CB6E08D-list-annote-' .. number
143143
end
144144

145+
local function toLines(s)
146+
if s:sub(-1)~="\n" then s=s.."\n" end
147+
return s:gmatch("(.-)\n")
148+
end
149+
145150
-- Finds annotations in a code cell and returns
146151
-- the annotations as well as a code cell that
147152
-- removes the annotations
@@ -153,12 +158,14 @@ local function resolveCellAnnotes(codeBlockEl, processAnnotation)
153158
if annotationProvider ~= nil then
154159
local annotations = {}
155160
local code = codeBlockEl.text
156-
local lines = split(code, "\n")
161+
157162
local outputs = pandoc.List({})
158-
for i, line in ipairs(lines) do
163+
local i = 1
164+
for line in toLines(code) do
159165

160166
-- Look and annotation
161167
local annoteNumber = annotationProvider.annotationNumber(line)
168+
162169
if annoteNumber then
163170
-- Capture the annotation number and strip it
164171
local annoteId = toAnnoteId(annoteNumber)
@@ -172,11 +179,15 @@ local function resolveCellAnnotes(codeBlockEl, processAnnotation)
172179
else
173180
outputs:insert(line)
174181
end
182+
i = i + 1
175183
end
176184

185+
quarto.log.output(outputs)
186+
quarto.log.output(annotations)
187+
177188
-- if we capture annotations, then replace the code source
178189
-- code, stripping annotation comments
179-
if #annotations > 0 then
190+
if annotations and next(annotations) ~= nil then
180191
local outputText = ""
181192
for i, output in ipairs(outputs) do
182193
outputText = outputText .. output .. '\n'
@@ -281,7 +292,7 @@ end
281292
function processAnnotation(line, annoteNumber, annotationProvider)
282293
-- For all other formats, just strip the annotation- the definition list is converted
283294
-- to be based upon line numbers.
284-
local stripped = annotationProvider.stripAnnotation(line, annoteNumber)
295+
local stripped = annotationProvider.stripAnnotation(line, annoteNumber)
285296
return stripped
286297
end
287298

src/resources/formats/html/templates/quarto-html.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ window.document.addEventListener("DOMContentLoaded", function (event) {
412412
};
413413
<% } %>
414414
415-
<% if (codeAnnotations === "below") { %>
415+
<% if (codeAnnotations === true || codeAnnotations === "below") { %>
416416
417417
// Attach click handler to the DT
418418
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');

0 commit comments

Comments
 (0)