我试图写regularExpression(SVG, width="(\d+)px", $1)
及其变体。
例如
我已经把它放在剪贴板中
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(-932.000000, -4274.000000)">
<g transform="translate(0.000000, 4184.000000)">
<g transform="translate(932.000000, 90.000000)">
<rect fill="#3C5494" x="0" y="0" width="32" height="32" rx="16"></rect>
<path d="M17.1973392,16.7117794 L19.5654279,16.7117794 L19.9199468,13.8590668 L17.1973392,13.8590668 L17.1973392,12.0421097 C17.1973392,11.2181543 17.4178625,10.6566668 18.5566829,10.6566668 L20,10.6559859 L20,8.11206559 C19.7488603,8.07744655 18.887255,8 17.8848071,8 C15.7919823,8 14.3592018,9.32549911 14.3592018,11.759728 L14.3592018,13.8590668 L12,13.8590668 L12,16.7117794 L14.3592018,16.7117794 L14.3592018,24 L17.1973392,24 L17.1973392,16.7117794 Z" fill="#FFFFFE"></path>
</g>
</g>
</g>
</g>
</svg>
我使用此模板
/* eslint-disable max-len */
import React from 'react'
import Icon from './Icon'
const $NAME$ = ({ width, height }) => (
<Icon
width={width}
height={height}
viewBox='0 0 $width$ $height$'
>
$SVG$$END$
</Icon>
)
export default $NAME$
我正在尝试从svg属性中插入$ width $和$ height $
除了viewBox是'0 0 32 32'
之外,我得到了'0 0 '
答案 0 :(得分:1)
regularExpression(String, Pattern, Replacement)
实时模板功能以以下方式运行:String
中与Pattern
匹配的所有匹配项均被第三个参数替换,并返回结果字符串(请参见函数实现)在https://github.com/JetBrains/intellij-community/blob/master/platform/lang-impl/src/com/intellij/codeInsight/template/macro/RegExMacro.java中)。因此,regularExpression(SVG, width="(\d+)px", $1)
的结果是剪贴板内容由width="32px"
替换为32