1 |
- {"ast":null,"code":"// Process \n\nimport { normalizeReference, isSpace } from '../common/utils.mjs';\nexport default function image(state, silent) {\n let code, content, label, pos, ref, res, title, start;\n let href = '';\n const oldPos = state.pos;\n const max = state.posMax;\n if (state.src.charCodeAt(state.pos) !== 0x21 /* ! */) {\n return false;\n }\n if (state.src.charCodeAt(state.pos + 1) !== 0x5B /* [ */) {\n return false;\n }\n const labelStart = state.pos + 2;\n const labelEnd = state.md.helpers.parseLinkLabel(state, state.pos + 1, false);\n\n // parser failed to find ']', so it's not a valid link\n if (labelEnd < 0) {\n return false;\n }\n pos = labelEnd + 1;\n if (pos < max && state.src.charCodeAt(pos) === 0x28 /* ( */) {\n //\n // Inline link\n //\n\n // [link]( <href> \"title\" )\n // ^^ skipping these spaces\n pos++;\n for (; pos < max; pos++) {\n code = state.src.charCodeAt(pos);\n if (!isSpace(code) && code !== 0x0A) {\n break;\n }\n }\n if (pos >= max) {\n return false;\n }\n\n // [link]( <href> \"title\" )\n // ^^^^^^ parsing link destination\n start = pos;\n res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax);\n if (res.ok) {\n href = state.md.normalizeLink(res.str);\n if (state.md.validateLink(href)) {\n pos = res.pos;\n } else {\n href = '';\n }\n }\n\n // [link]( <href> \"title\" )\n // ^^ skipping these spaces\n start = pos;\n for (; pos < max; pos++) {\n code = state.src.charCodeAt(pos);\n if (!isSpace(code) && code !== 0x0A) {\n break;\n }\n }\n\n // [link]( <href> \"title\" )\n // ^^^^^^^ parsing link title\n res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax);\n if (pos < max && start !== pos && res.ok) {\n title = res.str;\n pos = res.pos;\n\n // [link]( <href> \"title\" )\n // ^^ skipping these spaces\n for (; pos < max; pos++) {\n code = state.src.charCodeAt(pos);\n if (!isSpace(code) && code !== 0x0A) {\n break;\n }\n }\n } else {\n title = '';\n }\n if (pos >= max || state.src.charCodeAt(pos) !== 0x29 /* ) */) {\n state.pos = oldPos;\n return false;\n }\n pos++;\n } else {\n //\n // Link reference\n //\n if (typeof state.env.references === 'undefined') {\n return false;\n }\n if (pos < max && state.src.charCodeAt(pos) === 0x5B /* [ */) {\n start = pos + 1;\n pos = state.md.helpers.parseLinkLabel(state, pos);\n if (pos >= 0) {\n label = state.src.slice(start, pos++);\n } else {\n pos = labelEnd + 1;\n }\n } else {\n pos = labelEnd + 1;\n }\n\n // covers label === '' and label === undefined\n // (collapsed reference link and shortcut reference link respectively)\n if (!label) {\n label = state.src.slice(labelStart, labelEnd);\n }\n ref = state.env.references[normalizeReference(label)];\n if (!ref) {\n state.pos = oldPos;\n return false;\n }\n href = ref.href;\n title = ref.title;\n }\n\n //\n // We found the end of the link, and know for a fact it's a valid link;\n // so all that's left to do is to call tokenizer.\n //\n if (!silent) {\n content = state.src.slice(labelStart, labelEnd);\n const tokens = [];\n state.md.inline.parse(content, state.md, state.env, tokens);\n const token = state.push('image', 'img', 0);\n const attrs = [['src', href], ['alt', '']];\n token.attrs = attrs;\n token.children = tokens;\n token.content = content;\n if (title) {\n attrs.push(['title', title]);\n }\n }\n state.pos = pos;\n state.posMax = max;\n return true;\n}","map":{"version":3,"names":["normalizeReference","isSpace","image","state","silent","code","content","label","pos","ref","res","title","start","href","oldPos","max","posMax","src","charCodeAt","labelStart","labelEnd","md","helpers","parseLinkLabel","parseLinkDestination","ok","normalizeLink","str","validateLink","parseLinkTitle","env","references","slice","tokens","inline","parse","token","push","attrs","children"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/markdown-it/lib/rules_inline/image.mjs"],"sourcesContent":["// Process \n\nimport { normalizeReference, isSpace } from '../common/utils.mjs'\n\nexport default function image (state, silent) {\n let code, content, label, pos, ref, res, title, start\n let href = ''\n const oldPos = state.pos\n const max = state.posMax\n\n if (state.src.charCodeAt(state.pos) !== 0x21/* ! */) { return false }\n if (state.src.charCodeAt(state.pos + 1) !== 0x5B/* [ */) { return false }\n\n const labelStart = state.pos + 2\n const labelEnd = state.md.helpers.parseLinkLabel(state, state.pos + 1, false)\n\n // parser failed to find ']', so it's not a valid link\n if (labelEnd < 0) { return false }\n\n pos = labelEnd + 1\n if (pos < max && state.src.charCodeAt(pos) === 0x28/* ( */) {\n //\n // Inline link\n //\n\n // [link]( <href> \"title\" )\n // ^^ skipping these spaces\n pos++\n for (; pos < max; pos++) {\n code = state.src.charCodeAt(pos)\n if (!isSpace(code) && code !== 0x0A) { break }\n }\n if (pos >= max) { return false }\n\n // [link]( <href> \"title\" )\n // ^^^^^^ parsing link destination\n start = pos\n res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax)\n if (res.ok) {\n href = state.md.normalizeLink(res.str)\n if (state.md.validateLink(href)) {\n pos = res.pos\n } else {\n href = ''\n }\n }\n\n // [link]( <href> \"title\" )\n // ^^ skipping these spaces\n start = pos\n for (; pos < max; pos++) {\n code = state.src.charCodeAt(pos)\n if (!isSpace(code) && code !== 0x0A) { break }\n }\n\n // [link]( <href> \"title\" )\n // ^^^^^^^ parsing link title\n res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax)\n if (pos < max && start !== pos && res.ok) {\n title = res.str\n pos = res.pos\n\n // [link]( <href> \"title\" )\n // ^^ skipping these spaces\n for (; pos < max; pos++) {\n code = state.src.charCodeAt(pos)\n if (!isSpace(code) && code !== 0x0A) { break }\n }\n } else {\n title = ''\n }\n\n if (pos >= max || state.src.charCodeAt(pos) !== 0x29/* ) */) {\n state.pos = oldPos\n return false\n }\n pos++\n } else {\n //\n // Link reference\n //\n if (typeof state.env.references === 'undefined') { return false }\n\n if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) {\n start = pos + 1\n pos = state.md.helpers.parseLinkLabel(state, pos)\n if (pos >= 0) {\n label = state.src.slice(start, pos++)\n } else {\n pos = labelEnd + 1\n }\n } else {\n pos = labelEnd + 1\n }\n\n // covers label === '' and label === undefined\n // (collapsed reference link and shortcut reference link respectively)\n if (!label) { label = state.src.slice(labelStart, labelEnd) }\n\n ref = state.env.references[normalizeReference(label)]\n if (!ref) {\n state.pos = oldPos\n return false\n }\n href = ref.href\n title = ref.title\n }\n\n //\n // We found the end of the link, and know for a fact it's a valid link;\n // so all that's left to do is to call tokenizer.\n //\n if (!silent) {\n content = state.src.slice(labelStart, labelEnd)\n\n const tokens = []\n state.md.inline.parse(\n content,\n state.md,\n state.env,\n tokens\n )\n\n const token = state.push('image', 'img', 0)\n const attrs = [['src', href], ['alt', '']]\n token.attrs = attrs\n token.children = tokens\n token.content = content\n\n if (title) {\n attrs.push(['title', title])\n }\n }\n\n state.pos = pos\n state.posMax = max\n return true\n}\n"],"mappings":"AAAA;;AAEA,SAASA,kBAAkB,EAAEC,OAAO,QAAQ,qBAAqB;AAEjE,eAAe,SAASC,KAAKA,CAAEC,KAAK,EAAEC,MAAM,EAAE;EAC5C,IAAIC,IAAI,EAAEC,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAEC,GAAG,EAAEC,GAAG,EAAEC,KAAK,EAAEC,KAAK;EACrD,IAAIC,IAAI,GAAG,EAAE;EACb,MAAMC,MAAM,GAAGX,KAAK,CAACK,GAAG;EACxB,MAAMO,GAAG,GAAGZ,KAAK,CAACa,MAAM;EAExB,IAAIb,KAAK,CAACc,GAAG,CAACC,UAAU,CAACf,KAAK,CAACK,GAAG,CAAC,KAAK,IAAI,UAAS;IAAE,OAAO,KAAK;EAAC;EACpE,IAAIL,KAAK,CAACc,GAAG,CAACC,UAAU,CAACf,KAAK,CAACK,GAAG,GAAG,CAAC,CAAC,KAAK,IAAI,UAAS;IAAE,OAAO,KAAK;EAAC;EAExE,MAAMW,UAAU,GAAGhB,KAAK,CAACK,GAAG,GAAG,CAAC;EAChC,MAAMY,QAAQ,GAAGjB,KAAK,CAACkB,EAAE,CAACC,OAAO,CAACC,cAAc,CAACpB,KAAK,EAAEA,KAAK,CAACK,GAAG,GAAG,CAAC,EAAE,KAAK,CAAC;;EAE7E;EACA,IAAIY,QAAQ,GAAG,CAAC,EAAE;IAAE,OAAO,KAAK;EAAC;EAEjC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