Differences From
Artifact [bf3719fe9a]:
1148 1148 {fn = insert_paragraph};
1149 1149 }
1150 1150
1151 1151 function ct.parse_line(l, ctx, dest)
1152 1152 local newspan
1153 1153 local job = ctx.doc.stage.job
1154 1154 job:hook('line_read',ctx,l)
1155 + if l then
1156 + l = l:gsub("^ +","") -- trim leading spaces
1157 + end
1155 1158 if ctx.mode then
1156 1159 if ctx.mode.kind == 'code' then
1157 1160 if l and l:match '^~~~%s*$' then
1158 1161 job:hook('block_listing_end',ctx,ctx.mode.listing)
1159 1162 job:hook('mode_switch', c, nil)
1160 1163 ctx.mode = nil
1161 1164 else
................................................................................
1264 1267 local lines = ss.str.breaklines(ctx.doc.enc, r.props.src)
1265 1268 local srcs = {}
1266 1269 for i,l in ipairs(lines) do
1267 1270 local args = ss.str.breakwords(ctx.doc.enc, l, 2, {escape=true})
1268 1271 if #args < 3 then
1269 1272 r.origin:fail('invalid syntax for resource %s', t.ref)
1270 1273 end
1271 - local mimebreak = function(s)
1272 - local wds = ss.str.split(ctx.doc.enc, s, '/', 1, {escape=true})
1273 - return wds
1274 - end
1275 - local mime = mimebreak(args[2]);
1276 - local mimeclasses = {
1277 - ['application/svg+xml'] = 'image';
1278 - }
1274 + local mime = ss.mime(args[2]);
1279 1275 local class = mimeclasses[mime]
1280 1276 table.insert(srcs, {
1281 1277 mode = args[1];
1282 1278 mime = mime;
1283 1279 uri = args[3];
1284 1280 class = class or mime[1];
1285 1281 })
1286 1282 end
1287 1283 --ideally move this into its own mimetype lib
1288 - local kind = r.props.as or srcs[1].class
1289 - r.class = kind
1290 1284 r.srcs = srcs
1285 + -- note that resources do not themselves have kinds. when a
1286 + -- document requests to insert a resource, the renderer must
1287 + -- iterate through the sources and find the first source it
1288 + -- is capable of emitting. this allows constructions like
1289 + -- emitting a video for HTML outputs, a photo for printers,
1290 + -- and a screenplay for tty/plaintext outputs.
1291 1291 end
1292 1292 end
1293 1293 end
1294 1294 ctx.doc.stage = nil
1295 1295 ctx.doc.docjob:hook('meddle_ast')
1296 1296 return ctx.doc
1297 1297 end