作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想让我的部分文字加粗。
我从特定文件中获取文本。"INFORMATION": "Here's an example of text",
我想要 Here's an
要大胆。"INFORMATION": "<b>Here's an</b> example of text",
"INFORMATION": "<strong>Here's an</strong> example of text"
然后我打印出来
<span translate>INFORMATION</span>
<b>Here's an</b> example of text
<strong>Here's an</strong> example of text
<span [innerHTML]="information | translate"></span>
最佳答案
我要做的是一个管道来清理你给它的字符串,并使用正则表达式使其更通用。像这样的堆栈 Blitz :
https://stackblitz.com/edit/angular-tyz8b1?file=src%2Fapp%2Fapp.component.html
import { Pipe, PipeTransform, Sanitizer, SecurityContext } from '@angular/core';
@Pipe({
name: 'boldSpan'
})
export class BoldSpanPipe implements PipeTransform {
constructor(
private sanitizer: Sanitizer
) {}
transform(value: string, regex): any {
return this.sanitize(this.replace(value, regex));
}
replace(str, regex) {
return str.replace(new RegExp(`(${regex})`, 'gi'), '<b>$1</b>');
}
sanitize(str) {
return this.sanitizer.sanitize(SecurityContext.HTML, str);
}
}
关于javascript - 在字符串 Angular 的一部分上应用粗体文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55241693/
下面是我用来制作 1px 文本描边轮廓的代码。但是如何使轮廓变粗呢?如果我只是用“5px”替换所有“1px”,结果看起来很疯狂。 HTML Hello! CSS .element { color:
我是一名优秀的程序员,十分优秀!