Various sample.lua editorial fixes. (#7493)

These address most of the items mentioned in #7487.
There's also a table caption fix (the caption wasn't escaped).
This commit is contained in:
William Lupton 2021-08-12 18:16:34 +01:00 committed by GitHub
parent ebef4fb41d
commit fc20672bb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 16 deletions

View file

@ -143,7 +143,7 @@ end
function Link(s, tgt, tit, attr) function Link(s, tgt, tit, attr)
return "<a href='" .. escape(tgt,true) .. "' title='" .. return "<a href='" .. escape(tgt,true) .. "' title='" ..
escape(tit,true) .. "'>" .. s .. "</a>" escape(tit,true) .. "'" .. attributes(attr) .. ">" .. s .. "</a>"
end end
function Image(s, src, tit, attr) function Image(s, src, tit, attr)
@ -284,9 +284,15 @@ local function html_align(align)
end end
function CaptionedImage(src, tit, caption, attr) function CaptionedImage(src, tit, caption, attr)
return '<div class="figure">\n<img src="' .. escape(src,true) .. if #caption == 0 then
'" title="' .. escape(tit,true) .. '"/>\n' .. return '<p><img src="' .. escape(src,true) .. '" id="' .. attr.id ..
'<p class="caption">' .. escape(caption) .. '</p>\n</div>' '"/></p>'
else
local ecaption = escape(caption)
return '<figure>\n<img src="' .. escape(src,true) ..
'" id="' .. attr.id .. '" alt="' .. ecaption .. '"/>' ..
'<figcaption>' .. ecaption .. '</figcaption>\n</figure>'
end
end end
-- Caption is a string, aligns is an array of strings, -- Caption is a string, aligns is an array of strings,
@ -299,7 +305,7 @@ function Table(caption, aligns, widths, headers, rows)
end end
add("<table>") add("<table>")
if caption ~= "" then if caption ~= "" then
add("<caption>" .. caption .. "</caption>") add("<caption>" .. escape(caption) .. "</caption>")
end end
if widths and widths[1] ~= 0 then if widths and widths[1] ~= 0 then
for _, w in pairs(widths) do for _, w in pairs(widths) do
@ -313,9 +319,7 @@ function Table(caption, aligns, widths, headers, rows)
table.insert(header_row,'<th align="' .. align .. '">' .. h .. '</th>') table.insert(header_row,'<th align="' .. align .. '">' .. h .. '</th>')
empty_header = empty_header and h == "" empty_header = empty_header and h == ""
end end
if empty_header then if not empty_header then
head = ""
else
add('<tr class="header">') add('<tr class="header">')
for _,h in pairs(header_row) do for _,h in pairs(header_row) do
add(h) add(h)

View file

@ -712,18 +712,18 @@ So is &lsquo;pine.&rsquo;</p>
<h2 id="autolinks">Autolinks</h2> <h2 id="autolinks">Autolinks</h2>
<p>With an ampersand: <a href='http://example.com/?foo=1&amp;bar=2' title=''>http://example.com/?foo=1&amp;bar=2</a></p> <p>With an ampersand: <a href='http://example.com/?foo=1&amp;bar=2' title='' class="uri">http://example.com/?foo=1&amp;bar=2</a></p>
<ul> <ul>
<li>In a list?</li> <li>In a list?</li>
<li><a href='http://example.com/' title=''>http://example.com/</a></li> <li><a href='http://example.com/' title='' class="uri">http://example.com/</a></li>
<li>It should.</li> <li>It should.</li>
</ul> </ul>
<p>An e-mail address: <a href='mailto:nobody@nowhere.net' title=''>nobody@nowhere.net</a></p> <p>An e-mail address: <a href='mailto:nobody@nowhere.net' title='' class="email">nobody@nowhere.net</a></p>
<blockquote> <blockquote>
<p>Blockquoted: <a href='http://example.com/' title=''>http://example.com/</a></p> <p>Blockquoted: <a href='http://example.com/' title='' class="uri">http://example.com/</a></p>
</blockquote> </blockquote>
<p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code></p> <p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code></p>
@ -736,10 +736,9 @@ So is &lsquo;pine.&rsquo;</p>
<p>From &ldquo;Voyage dans la Lune&rdquo; by Georges Melies (1902):</p> <p>From &ldquo;Voyage dans la Lune&rdquo; by Georges Melies (1902):</p>
<div class="figure"> <figure>
<img src="lalune.jpg" title="fig:Voyage dans la Lune"/> <img src="lalune.jpg" id="" alt="lalune"/><figcaption>lalune</figcaption>
<p class="caption">lalune</p> </figure>
</div>
<p>Here is a movie <img src='movie.jpg' title=''/> icon.</p> <p>Here is a movie <img src='movie.jpg' title=''/> icon.</p>