MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / parseImageSize

Function parseImageSize

packages/ui-default/backendlib/markdown-it-imsize.ts:20–50  ·  view source on GitHub ↗
(str, pos, max)

Source from the content-addressed store, hash-verified

18}
19
20function parseImageSize(str, pos, max) {
21 const result = {
22 ok: false,
23 pos: 0,
24 width: '',
25 height: '',
26 };
27 if (pos >= max) return result;
28 let code = str.charCodeAt(pos);
29 if (code !== 0x3D /* = */) return result;
30 pos++;
31 code = str.charCodeAt(pos);
32 if (code !== 0x78 /* x */ && (code < 0x30 || code > 0x39) /* [0-9] */) {
33 return result;
34 }
35 // parse width
36 const resultW = parseNextNumber(str, pos, max);
37 pos = resultW.pos;
38 // next charactor must be 'x'
39 code = str.charCodeAt(pos);
40 if (code !== 0x78 /* x */) { return result; }
41 pos++;
42 // parse height
43 const resultH = parseNextNumber(str, pos, max);
44 pos = resultH.pos;
45 result.width = resultW.value;
46 result.height = resultH.value;
47 result.pos = pos;
48 result.ok = true;
49 return result;
50}
51
52export default function plugin(md) {
53 md.inline.ruler.before('emphasis', 'image', (state, silent) => {

Callers 1

pluginFunction · 0.85

Calls 1

parseNextNumberFunction · 0.85

Tested by

no test coverage detected