iansinnott / iansinnott/react-string-replace
Trouble formatting bold/italic/underline text with capture group regex
- 主要語言
- JavaScript
- 星號
- 666
- 分支
- 54
- PR 合併指標
- 30 天內沒有已合併 PR
描述
I'm having trouble using `reactStringReplace` to format text with bold/italic tags. I have it set up as follows:
```javascript
var text1 = "[b]Testing bold [i]and italic[/i] tags[/b]"
var text2 = "[b]Testing bold [i]and italic tags[/b][/i]"
let replaced = reactStringReplace(text1, /\[b\]([\s\S]+)\[\/b\]/g, (match, i) => {
return {match}
})
replaced = reactStringReplace(replaced, /\[i\]([\s\S]+)\[\/i\]/g, (match, i) => {
return {match}
})
// result (html)
Testing [i]bold and italic[/i] tags
Testing [i]bold and italic tags[/i]
```
I'm not sure if this is a problem with `reactStringReplace`, with the regex I'm using, or something else. If I apply the italic replace first, I get italic tags where I'd expect them to be, but the [b] tags remain unchanged. Is this use case possible using `reactStringReplace` or do I need to use `dangerouslySetInnerHtml`?
Bonus: is `reactStringReplace` capable of handling unbalanced tags, or improperly formatted tags as in `text2` or should I be doing some pre-processing to ensure the strings are properly balanced and formatted?
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
先從提供的兩個字串和替換呼叫開始,然後閱讀 reactStringReplace API 和實作,以確定連續替換如何處理巢狀的 React 輸出。重現這兩種情況,並記錄或測試平衡標籤和不平衡標籤的預期行為;當支援的行為和限制都涵蓋到時,該 issue 就完成了。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript, react
- 領域
- frontend
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100