Skip to content

Commit

Permalink
feat: 图片语法增加花括号扩展能力
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Mar 13, 2023
1 parent a7e1f96 commit 44d8063
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/core/hooks/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class Image extends SyntaxBase {
this.RULE = this.rule(this.extendMedia);
}

toHtml(match, leadingChar, alt, link, title, ref) {
toHtml(match, leadingChar, alt, link, title, ref, extendAttrs) {
// console.log(match, alt, link, ref, title);
const refType = typeof link === 'undefined' ? 'ref' : 'url';
let attrs = '';
Expand All @@ -99,9 +99,12 @@ export default class Image extends SyntaxBase {
srcProp = imgAttrs.srcProp || srcProp;
srcValue = imgAttrs.src || link;
}
const extendAttrStr = extendAttrs
? extendAttrs.replace(/[{}]/g, '').replace(/([^=\s]+)=([^\s]+)/g, '$1="$2"')
: '';
return `${leadingChar}<img ${srcProp}="${UrlCache.set(
encodeURIOnce(this.urlProcessor(srcValue, 'image')),
)}" ${extent} ${style} ${classes} alt="${$e(alt || '')}"${attrs}/>`;
)}" ${extent} ${style} ${classes} alt="${$e(alt || '')}"${attrs} ${extendAttrStr}/>`;
}
// should never happen
return match;
Expand Down Expand Up @@ -159,7 +162,7 @@ export default class Image extends SyntaxBase {
}${NOT_ALL_WHITE_SPACES_INLINE})\\]` + // ?<ref> global ref
')',
].join(''),
end: '', // TODO: extend attrs e.g. {width=50 height=60}
end: '({[^{}]+?})?', // extend attrs e.g. {width=50 height=60}
};
if (extendMedia) {
const extend = { ...ret };
Expand Down

0 comments on commit 44d8063

Please sign in to comment.